## OTEL SDK & API Port on AIX

This README provides details of the OTEL SDK & API port on AIX and how to use it 
along with C wrapper for legacy application to compile with xlc compiler while still use
latest SDK and API.

The tar bundle contains a collection of the main OTEL-CPP implementation along with its dependencies.

## Version Details

**opentelemetry-cpp:** 1.26.0

  Dependencies
  - abseil-cpp: 20260107.1
  - protobuf: 34.1
  - grpc: 1.80

  Other Dependencies from AIX Toolbox
  - curl: 8.18.0
  - zlib: 1.3.1

Please see the section "Setting up dnf on AIX" to install additional dependencies required.

## What the Tar Bundle Contains

The tar bundle contains the shared libraries and header files for the packages mentioned below, 
which are built on AIX 7.2 TL5 SP10. This tar bundle can be used on AIX 7.2 TL5 and any higher versions.

- opentelemetry-cpp: 1.26.0
- abseil-cpp: 20260107.1
- protobuf: 34.1
- grpc: 1.80

**Plus:** Example programs which are dependent on the instrumented foo_library built along with OTEL-CPP.

To extract the tar, run the below command which will extract the files under /opt/freeware

/usr/bin/tar -xf otel-cpp-aix-1.26.0.tar -C /

## Installation Path

All required OTEL-CPP libraries and header files are installed under the path /opt/freeware/otelaix
C Wrapper library and it's dependent library rapidyaml is under /opt/freeware/otel-c-wrapper &
/opt/freeware/rapidyaml.

## What Features Are Enabled

Enables the ABI version 1.

Below are the components of OTEL-CPP:

- http
- file
- grpc
- http_client_curl
- prometheus (Untested)
- elastic (Untested)
- nlohmann_json

For C Wrapper

- rapidyaml
- otel-c-wrapper

## How to Build Instrumented Applications

To build instrumented applications with the provided OTEL libraries and header files, please use the below common CFLAGS & CXXFLAGS:

export OBJECT_MODE=64
export OBJECT_MODE=64
export CC="/opt/IBM/openxlC/17.1.2/bin/ibm-clang_r "
export CXX="/opt/IBM/openxlC/17.1.2/bin/ibm-clang++_r "
export LDFLAGS="-L/opt/freeware/lib/pthread/ppc64 -L/opt/freeware/lib64 -L/opt/freeware/otelaix/lib"
export CFLAGS="-maix64 -D_ALL_SOURCE -D_LARGE_FILES -pthread -I/opt/freeware/otelaix/include"
export CXXFLAGS="-maix64 -D_ALL_SOURCE -D_LARGE_FILES -pthread -I/opt/freeware/otelaix/include -std=c++17 -pthread -Wl,-brtl"


Please note the include and library paths provided.

To make CMake aware of the OTEL installation path, please use:


-Dopentelemetry-cpp_DIR=/opt/freeware/otelaix


and


-DCMAKE_EXE_LINKER_FLAGS:STRING="-L/opt/freeware/lib -L/opt/freeware/lib64 -L/opt/freeware/otelaix -Wl,-brtl"

You may need to install the development packages such as curl-devel, zlib-devel etc.


for proper linking.


## Setting up dnf on AIX

To set up DNF and install the other required dependencies plus build tools such as gcc, CMake, etc., please follow the instructions below:

- To install DNF, run the dnf_aixtoolbox.sh script with either the `-d` or `-y` option. 
  Please check [this blog](https://www.ibm.com/support/pages/dnf-open-source-package-management-utility-aix) for more information on DNF setup.

- Once DNF is successfully installed, run `dnf update` to update packages to the latest version. This should update curl to the latest version along with its dependencies.

- Install build-related packages such as cmake, etc., using:

  dnf install cmake
   
 

## How to Run Example Programs Provided

If you would like to run the example programs built along with OTEL-CPP, then run them with LIBPATH as shown below:


LIBPATH=/opt/freeware/otelaix/share/examples/common:/opt/freeware/otelaix/lib:/opt/freeware/lib/pthread:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib /opt/freeware/otelaix/share/examples/simple/example_simple



LIBPATH=/opt/freeware/otelaix/share/examples/common:/opt/freeware/otelaix/lib:/opt/freeware/lib/pthread:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib /opt/freeware/otelaix/share/examples/otlp/example_otlp_http http://x.x.x.x:4318/v1/traces yes bin



LIBPATH=/opt/freeware/otelaix/share/examples/common:/opt/freeware/otelaix/lib:/opt/freeware/lib/pthread:/opt/freeware/lib64:/opt/freeware/lib:/usr/lib:/lib /opt/freeware/otelaix/share/examples/otlp/example_otlp_grpc http://x.x.x.x:4318/v1/traces


## Important Notes

1. The build instructions for instrumented applications may change in the future as this is the very first build made available for instrumentation.
2. The libraries are built as .so shared objects.
3. The OpenTelemetry SDK and C Wrapper library is built with openXL compiler.
4. For any DNF and AIX Toolbox package-related issues, please open a forum thread at [IBM Community](https://community.ibm.com/community/user/groups/community-home?communitykey=329e8662-cb5a-4e9e-80ee-47b1c3b5848c).


## Compiling Application by Using C wrapper

/opt/IBM/xlC/16.1.0/bin/xlc++_r -q64 main_c_grpc.cpp -o gateway_app_grpc   \
  -L/opt/freeware/otelaix   \
  -I/opt/freeware/otel-c-wrapper/include  \
  /opt/freeware/otel-c-wrapper/lib/libopentelemetry-c-wrapper.so \
 -Wl,-blibpath:"/opt/freeware/otel-c-wrapper/lib:/opt/freeware/otelaix:/opt/freeware/lib:/usr/lib"
 
 
 The example sample application code and yaml file can be found at.
 https://github.com/sswamy48/otel-cpp
