### Build OpenTelemetry C++ Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Execute the build process: ```bash cmake --build . ``` -------------------------------- ### Build Commands Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Commands to build the application using CMake. ```bash mkdir build cd build cmake .. -DCMAKE_PREFIX_PATH=$(pwd)/../../install cmake --build . ``` -------------------------------- ### Build Project Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Commands to build the C++ project using CMake. ```bash cd build cmake .. -DCMAKE_PREFIX_PATH=$(pwd)/../../install cmake --build . ``` -------------------------------- ### Run Command Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Command to run the compiled executable. ```bash ./dice-server ``` -------------------------------- ### Run Executable Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Command to run the compiled C++ application. ```bash ./dice-server ``` -------------------------------- ### Install Oat++ Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Install oatpp into a local prefix. This command installs the built oatpp library, headers, and CMake package configuration into the install directory, making it accessible for development. ```bash cmake --install . --prefix ../../install ``` -------------------------------- ### Build Oat++ Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Build oatpp using the cmake and make commands. ```bash mkdir build cd build cmake .. make ``` -------------------------------- ### Checkout Oat++ version Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Navigate to the oatpp directory and switch to 1.3.0 version. ```bash cd oatpp git checkout 1.3.0-latest ``` -------------------------------- ### Clone Oat++ repository Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Obtain the Oat++ source code by cloning from the oatpp/oatpp GitHub repository. ```bash git clone https://github.com/oatpp/oatpp.git ``` -------------------------------- ### Alternative OpenTelemetry C++ configuration Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Or, if the cmake --build fails, you can also try: ```bash cmake -DBUILD_TESTING=OFF -DWITH_ABSEIL=ON .. ``` -------------------------------- ### Download Installation Scripts Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/es/docs/zero-code/dotnet/getting-started.md Download the installation scripts from the releases page of the opentelemetry-dotnet-instrumentation repository. ```shell curl -L -O https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh ``` ```powershell $module_url = "https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/OpenTelemetry.DotNet.Auto.psm1" $download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1" Invoke-WebRequest -Uri $module_url -OutFile $download_path -UseBasicParsing ``` -------------------------------- ### Install core files and setup instrumentation (Linux/macOS) Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/zero-code/dotnet/_index.md Download the installation script, make it executable, set up instrumentation for the current shell session, and then run your application with environment variables for service name and attributes. ```shell # Download the bash script curl -sSfL https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/latest/download/otel-dotnet-auto-install.sh -O # Install core files sh ./otel-dotnet-auto-install.sh # Enable execution for the instrumentation script chmod +x $HOME/.otel-dotnet-auto/instrument.sh # Setup the instrumentation for the current shell session . $HOME/.otel-dotnet-auto/instrument.sh # Run your application with instrumentation OTEL_SERVICE_NAME=myapp OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=staging,service.version=1.0.0 ./MyNetApp ``` -------------------------------- ### Updated CMakeLists.txt for OpenTelemetry Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md This snippet shows how to add OpenTelemetry dependencies to the CMakeLists.txt file. ```cmake cmake_minimum_required(VERSION 3.25) project(RollDiceServer) # Set C++ standard (e.g., C++17) set(CMAKE_CXX_STANDARD 17) set(project_name roll-dice-server) # Define your project's source files set(SOURCES main.cpp # Add your source files here ) ``` -------------------------------- ### Configure OpenTelemetry C++ build Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md In the build directory run CMake, to configure and generate the build system without enabling tests. ```bash cd opentelemetry-cpp mkdir build cd build cmake -DBUILD_TESTING=OFF .. ``` -------------------------------- ### Run otel-collector Example Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2024/getting-started-with-otelsql/index.md Navigate to the otel-collector example directory and start all services using Docker Compose. ```sh cd example/otel-collector docker compose up -d ``` -------------------------------- ### CMakeLists.txt for Dice Server Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md This CMakeLists.txt file sets up the build for the dice server application, linking against the oatpp library. ```cmake add_executable(dice-server ${SOURCES}) find_package(oatpp REQUIRED) target_link_libraries(dice-server PRIVATE oatpp::oatpp) ``` -------------------------------- ### Clone OpenTelemetry C++ repository Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md In your terminal, navigate back to the otel-cpp-starter directory. Then, clone the OpenTelemetry C++ GitHub repository to your local machine. ```bash git clone https://github.com/open-telemetry/opentelemetry-cpp.git ``` -------------------------------- ### Install Rails Gem Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/ruby/getting-started.md Install the Rails framework to create the example application. ```sh gem install rails ``` -------------------------------- ### main.cpp for Dice Server Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md The main C++ source file for the dice server, implementing an HTTP handler to generate random numbers and setting up the server. ```cpp #include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/network/Server.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include #include #include using namespace std; class Handler : public oatpp::web::server::HttpRequestHandler { public: shared_ptr handle(const shared_ptr& request) override { int low = 1; int high = 7; int random = rand() % (high - low) + low; // Convert a std::string to oatpp::String const string response = to_string(random); return ResponseFactory::createResponse(Status::CODE_200, response.c_str()); } }; void run() { auto router = oatpp::web::server::HttpRouter::createShared(); router->route("GET", "/rolldice", std::make_shared()); auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router); auto connectionProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8080, oatpp::network::Address::IP_4}); oatpp::network::Server server(connectionProvider, connectionHandler); OATPP_LOGI("Dice Server", "Server running on port %s", static_cast(connectionProvider->getProperty("port").getData())); server.run(); } int main() { oatpp::base::Environment::init(); srand((int)time(0)); run(); oatpp::base::Environment::destroy(); return 0; } ``` -------------------------------- ### CMakeLists.txt for C++ Project Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md This snippet shows how to configure CMake to build an executable target and link against OpenTelemetry C++ libraries. ```cmake add_executable(dice-server ${SOURCES}) find_package(oatpp REQUIRED) find_package(opentelemetry-cpp CONFIG REQUIRED) target_link_libraries(dice-server PRIVATE oatpp::oatpp ${OPENTELEMETRY_CPP_LIBRARIES}) ``` -------------------------------- ### Run Your Application Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/es/docs/zero-code/dotnet/getting-started.md Run your application again after setting up the instrumentation. ```shell dotnet run ``` -------------------------------- ### Initialize Composer Project Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/php/instrumentation.md Initializes a minimal composer.json file and installs dependencies for the example application. ```shell composer init \ --no-interaction \ --require slim/slim:"^4" \ --require slim/psr7:"^1" \ --require monolog/monolog:"^3" composer update ``` -------------------------------- ### Install Go Instrumentation Libraries Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/go/libraries.md Use `go get` to install instrumentation libraries from the Contrib repository. Replace `{import-path}` and `{package-name}` with the specific library details. ```sh go get go.opentelemetry.io/contrib/instrumentation/{import-path}/otel{package-name} ``` -------------------------------- ### Install Specific Instrumentation Libraries Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/ruby/libraries.md Install only the specific instrumentation libraries you intend to use. This example installs Sinatra and Faraday. ```sh gem install opentelemetry-instrumentation-sinatra gem install opentelemetry-instrumentation-faraday ``` -------------------------------- ### Install All Instrumentations Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/ruby/instrumentation.md Install the 'opentelemetry-instrumentation-all' gem to automatically enable many common library instrumentations. This simplifies setup by avoiding individual instrumentation configurations. ```sh gem install opentelemetry-instrumentation-all ``` -------------------------------- ### Example Span Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md An example of the JSON output for a span emitted to the terminal when a request is made to /rolldice. ```json { "name" : "RollDiceServer", "trace_id": "f47bea385dc55e4d17470d51f9d3130b", "span_id": "deed994b51f970fa", "tracestate" : , "parent_span_id": "0000000000000000", "start": 1698991818716461000, "duration": 64697, "span kind": "Internal", "status": "Unset", "service.name": "unknown_service", "telemetry.sdk.language": "cpp", "telemetry.sdk.name": "opentelemetry", "telemetry.sdk.version": "1.11.0", "instr-lib": "my-app-tracer" } ``` -------------------------------- ### Start Demo with Make Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/zh/docs/demo/docker-deployment.md Use the Make command to start the demo application. This is a convenient way to manage the startup process. ```shell make start ``` -------------------------------- ### Example Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/go/getting-started.md Example JSON output of spans emitted to the console when a request is made to the /rolldice/{player} route. ```json { "Name": "roll", "SpanContext": { "TraceID": "f00f8045a6c78b3aa5ecaca9f3b971b4", "SpanID": "f641bd25400a1b70", "TraceFlags": "01", "TraceState": "", "Remote": false }, "Parent": { "TraceID": "f00f8045a6c78b3aa5ecaca9f3b971b4", "SpanID": "a10f1d2ca2f685c9", "TraceFlags": "01", "TraceState": "", "Remote": false }, "SpanKind": 1, "StartTime": "2026-01-28T09:58:44.298985982+01:00", "EndTime": "2026-01-28T09:58:44.299067482+01:00", "Attributes": [ { "Key": "roll.value", "Value": { "Type": "INT64", "Value": 1 } } ], "Events": null, "Links": null, "Status": { "Code": "Unset", "Description": "" }, "DroppedAttributes": 0, "DroppedEvents": 0, "DroppedLinks": 0, "ChildSpanCount": 0, "Resource": [ { "Key": "service.name", "Value": { "Type": "STRING", "Value": "dice" } }, { "Key": "service.version", "Value": { "Type": "STRING", "Value": "0.1.0" } }, { "Key": "telemetry.sdk.language", "Value": { "Type": "STRING", "Value": "go" } }, { "Key": "telemetry.sdk.name", "Value": { "Type": "STRING", "Value": "opentelemetry" } }, { "Key": "telemetry.sdk.version", "Value": { "Type": "STRING", "Value": "1.39.0" } } ], "InstrumentationScope": { "Name": "go.opentelemetry.io/contrib/examples/dice", "Version": "", "SchemaURL": "", "Attributes": null }, "InstrumentationLibrary": { "Name": "go.opentelemetry.io/contrib/examples/dice", "Version": "", "SchemaURL": "", "Attributes": null } } { "Name": "/", "SpanContext": { "TraceID": "f00f8045a6c78b3aa5ecaca9f3b971b4", "SpanID": "a10f1d2ca2f685c9", "TraceFlags": "01", "TraceState": "", "Remote": false }, "Parent": { "TraceID": "00000000000000000000000000000000", "SpanID": "0000000000000000", "TraceFlags": "00", "TraceState": "", "Remote": false }, "SpanKind": 2, "StartTime": "2026-01-28T09:58:44.298951202+01:00", "EndTime": "2026-01-28T09:58:44.299109293+01:00", "Attributes": [ { "Key": "server.address", "Value": { "Type": "STRING", "Value": "localhost" } }, { "Key": "http.request.method", "Value": { "Type": "STRING", "Value": "GET" } }, { "Key": "url.scheme", "Value": { "Type": "STRING", "Value": "http" } }, { "Key": "server.port", "Value": { "Type": "INT64", "Value": 8080 } }, { "Key": "network.peer.address", "Value": { "Type": "STRING", "Value": "127.0.0.1" } }, { "Key": "network.peer.port", "Value": { "Type": "INT64", "Value": 43804 } }, { "Key": "user_agent.original", "Value": { "Type": "STRING", "Value": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:147.0) Gecko/20100101 Firefox/147.0" } }, { "Key": "client.address", "Value": { "Type": "STRING", "Value": "127.0.0.1" } }, { "Key": "url.path", "Value": { "Type": "STRING", "Value": "/rolldice/Alice" } }, { "Key": "network.protocol.version", "Value": { "Type": "STRING", "Value": "1.1" } }, { "Key": "http.response.body.size", "Value": { "Type": "INT64", "Value": 2 } }, { "Key": "http.response.status_code", "Value": { "Type": "INT64", "Value": 200 } } ], "Events": null, "Links": null, "Status": { "Code": "Unset", "Description": "" }, "DroppedAttributes": 0, "DroppedEvents": 0, "DroppedLinks": 0, "ChildSpanCount": 1, "Resource": [ { "Key": "service.name", "Value": { "Type": "STRING", "Value": "dice" } }, { "Key": "service.version", "Value": { "Type": "STRING", "Value": "0.1.0" } }, { "Key": "telemetry.sdk.language", "Value": { "Type": "STRING", "Value": "go" } }, { "Key": "telemetry.sdk.name", "Value": { "Type": "STRING", "Value": "opentelemetry" } }, { "Key": "telemetry.sdk.version", "Value": { "Type": "STRING", "Value": "1.39.0" } } ], "InstrumentationScope": { "Name": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp", "Version": "0.64.0", "SchemaURL": "", "Attributes": null }, "InstrumentationLibrary": { "Name": "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp", "Version": "0.64.0", "SchemaURL": "", "Attributes": null } } ``` -------------------------------- ### Run OpAMP Server Example Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/collector/management.md Launch the example OpAMP server from the cloned opamp-go repository. This server acts as the control plane for managing telemetry agents. ```console go run . 2025/04/20 15:10:35.307207 [MAIN] OpAMP Server starting... 2025/04/20 15:10:35.308201 [MAIN] OpAMP Server running... ``` -------------------------------- ### Install Collector as DaemonSet and Gateway Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/collector/install/kubernetes.md Use this command to install the OpenTelemetry Collector as a DaemonSet and a single gateway instance. This example serves as a starting point for production-ready customization. ```sh kubectl apply -f https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector/v{{% param vers %}}/examples/k8s/otel-config.yaml ``` -------------------------------- ### Example Kubernetes Event Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/platforms/kubernetes/operator/troubleshooting/automatic.md This is an example of the expected output from 'kubectl get events'. The presence of 'Created' and 'Started' events for the auto-instrumentation container indicates successful initialization. ```text 53s Normal Created pod/py-otel-server-7f54bf4cbc-p8wmj Created container opentelemetry-auto-instrumentation 53s Normal Started pod/py-otel-server-7f54bf4cbc-p8wmj Started container opentelemetry-auto-instrumentation ``` -------------------------------- ### Create Example Directory and File Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/zero-code/python/logs-example.md Creates a directory and an empty Python file for the logs auto-instrumentation example. ```sh mkdir python-logs-example cd python-logs-example touch example.py ``` -------------------------------- ### Complete Main Application File Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2022/go-web-app-instrumentation/index.md This is the complete main.go file incorporating all the instrumentation and setup discussed. ```go package main import ( "context" "log" "net/http" "github.com/aspecto-io/opentelemetry-examples/tracing" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin" "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" ) var client * mongo.Client func main() { ``` -------------------------------- ### Docker Compose Output Example Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2023/logs-collection/index.md Example output from running the Docker Compose setup, showing the application starting, executing, and completing its task. This illustrates the containerized execution of the Python script. ```shell baby-grogu-baby-grogu-1 | Starting to practice The Telemetry for 2 second(s) baby-grogu-baby-grogu-1 | /)|| baby-grogu-baby-grogu-1 | Done practicing baby-grogu-baby-grogu-1 | Practicing The Telemetry completed: True ``` -------------------------------- ### Example Trace Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/go/getting-started.md This JSON snippet shows an example of trace output, including timestamp, severity, body, attributes, trace and span IDs, and resource information. ```json { "Timestamp": "2026-01-28T09:58:44.29900397+01:00", "ObservedTimestamp": "2026-01-28T09:58:44.299031783+01:00", "Severity": 9, "SeverityText": "INFO", "Body": { "Type": "String", "Value": "Alice is rolling the dice" }, "Attributes": [ { "Key": "result", "Value": { "Type": "Int64", "Value": 1 } } ], "TraceID": "f00f8045a6c78b3aa5ecaca9f3b971b4", "SpanID": "f641bd25400a1b70", "TraceFlags": "01", "Resource": [ { "Key": "service.name", "Value": { "Type": "STRING", "Value": "dice" } }, { "Key": "service.version", "Value": { "Type": "STRING", "Value": "0.1.0" } }, { "Key": "telemetry.sdk.language", "Value": { "Type": "STRING", "Value": "go" } }, { "Key": "telemetry.sdk.name", "Value": { "Type": "STRING", "Value": "opentelemetry" } }, { "Key": "telemetry.sdk.version", "Value": { "Type": "STRING", "Value": "1.39.0" } } ], "Scope": { "Name": "go.opentelemetry.io/contrib/examples/dice", "Version": "", "SchemaURL": "", "Attributes": {} }, "DroppedAttributes": 0 } ``` -------------------------------- ### Go To-Do App Setup with Gin and MongoDB Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2022/go-web-app-instrumentation/index.md Sets up a basic Gin web server and connects to MongoDB, seeding it with initial to-do items. Ensure to pass c.Request.Context() to MongoDB operations for proper context propagation. ```go package main import ( "context" "net/http" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) var client * mongo.Client func main() { connectMongo() setupWebServer() } func connectMongo() { opts: = options.Client() opts.ApplyURI("mongodb://localhost:27017") client, _ = mongo.Connect(context.Background(), opts) //Seed the database with todo's docs: = [] interface{} { bson.D { { "id", "1" }, { "title", "Buy groceries" } }, bson.D { { "id", "2" }, { "title", "install Aspecto.io" } }, bson.D { { "id", "3" }, { "title", "Buy dogz.io domain" } }, } client.Database("todo").Collection("todos").InsertMany(context.Background(), docs) } func setupWebServer() { r: = gin.Default() r.GET("/todo", func(c * gin.Context) { collection: = client.Database("todo").Collection("todos") //Important: Make sure to pass c.Request.Context() as the context and not c itself - TBD cur, findErr: = collection.Find(c.Request.Context(), bson.D {}) if findErr != nil { c.AbortWithError(500, findErr) return } results: = make([] interface {}, 0) curErr: = cur.All(c, & results) if curErr != nil { c.AbortWithError(500, curErr) return } c.JSON(http.StatusOK, results) }) _ = r.Run(":8080") } ``` -------------------------------- ### Example Metrics Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/go/getting-started.md This JSON snippet shows an example of metrics output, including resource information, scope metrics, and data points for 'dice.rolls' with attributes like 'roll.value'. ```json { "Resource": [ { "Key": "service.name", "Value": { "Type": "STRING", "Value": "dice" } }, { "Key": "service.version", "Value": { "Type": "STRING", "Value": "0.1.0" } }, { "Key": "telemetry.sdk.language", "Value": { "Type": "STRING", "Value": "go" } }, { "Key": "telemetry.sdk.name", "Value": { "Type": "STRING", "Value": "opentelemetry" } }, { "Key": "telemetry.sdk.version", "Value": { "Type": "STRING", "Value": "1.39.0" } } ], "ScopeMetrics": [ { "Scope": { "Name": "go.opentelemetry.io/contrib/examples/dice", "Version": "", "SchemaURL": "", "Attributes": null }, "Metrics": [ { "Name": "dice.rolls", "Description": "The number of rolls by roll value", "Unit": "{roll}", "Data": { "DataPoints": [ { "Attributes": [ { "Key": "roll.value", "Value": { "Type": "INT64", "Value": 2 } } ], "StartTime": "2026-01-28T09:58:36.297218201+01:00", "Time": "2026-01-28T09:59:04.826103626+01:00", "Value": 2, "Exemplars": [ { "FilteredAttributes": null, "Time": "2026-01-28T09:58:58.310873844+01:00", "Value": 1, "SpanID": "MFfLVpcp2E8=", "TraceID": "KGizZKX5cz9DqgG95WoBvQ==" } ] }, { "Attributes": [ { "Key": "roll.value", "Value": { "Type": "INT64", "Value": 3 } } ], "StartTime": "2026-01-28T09:58:36.297218201+01:00", "Time": "2026-01-28T09:59:04.826103626+01:00", "Value": 1, "Exemplars": [ { "FilteredAttributes": null, "Time": "2026-01-28T09:58:48.446722639+01:00", "Value": 1, "SpanID": "Xa6wKaCre6k=", "TraceID": "VncSsITnUTtWpMAFGRoLng==" } ] }, { "Attributes": [ { "Key": "roll.value", "Value": { "Type": "INT64", "Value": 1 } } ], "StartTime": "2026-01-28T09:58:36.297218201+01:00", "Time": "2026-01-28T09:59:04.826103626+01:00", "Value": 4, "Exemplars": [ { ``` -------------------------------- ### Run OpAMP Server Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2022/opamp/index.md Start the OpAMP server from the opamp-go repository. Visit http://localhost:4321 to verify it's running. ```shell cd internal/examples/server go run . ``` -------------------------------- ### main.cpp for Tracer Initialization and Span Emission Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md This C++ code initializes an OpenTelemetry tracer and emits spans when a request is handled. ```cpp #include "oatpp/web/server/HttpConnectionHandler.hpp" #include "oatpp/network/Server.hpp" #include "oatpp/network/tcp/server/ConnectionProvider.hpp" #include "opentelemetry/exporters/ostream/span_exporter_factory.h" #include "opentelemetry/sdk/trace/exporter.h" #include "opentelemetry/sdk/trace/processor.h" #include "opentelemetry/sdk/trace/simple_processor_factory.h" #include "opentelemetry/sdk/trace/tracer_provider_factory.h" #include "opentelemetry/trace/provider.h" #include #include #include using namespace std; namespace trace_api = opentelemetry::trace; namespace trace_sdk = opentelemetry::sdk::trace; namespace trace_exporter = opentelemetry::exporter::trace; namespace { void InitTracer() { auto exporter = trace_exporter::OStreamSpanExporterFactory::Create(); auto processor = trace_sdk::SimpleSpanProcessorFactory::Create(std::move(exporter)); std::shared_ptr provider = trace_sdk::TracerProviderFactory::Create(std::move(processor)); //set the global trace provider trace_api::Provider::SetTracerProvider(provider); } void CleanupTracer() { std::shared_ptr none; trace_api::Provider::SetTracerProvider(none); } } class Handler : public oatpp::web::server::HttpRequestHandler { public: shared_ptr handle(const shared_ptr& request) override { auto tracer = opentelemetry::trace::Provider::GetTracerProvider()->GetTracer("my-app-tracer"); auto span = tracer->StartSpan("RollDiceServer"); int low = 1; int high = 7; int random = rand() % (high - low) + low; // Convert a std::string to oatpp::String const string response = to_string(random); span->End(); return ResponseFactory::createResponse(Status::CODE_200, response.c_str()); } }; void run() { auto router = oatpp::web::server::HttpRouter::createShared(); router->route("GET", "/rolldice", std::make_shared()); auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router); auto connectionProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"localhost", 8080, oatpp::network::Address::IP_4}); oatpp::network::Server server(connectionProvider, connectionHandler); OATPP_LOGI("Dice Server", "Server running on port %s", static_cast(connectionProvider->getProperty("port").getData())); server.run(); } int main() { oatpp::base::Environment::init(); InitTracer(); srand((int)time(0)); run(); oatpp::base::Environment::destroy(); CleanupTracer(); return 0; } ``` -------------------------------- ### Initialize Tracing in Application File (index.php) Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/php/instrumentation.md Example of acquiring a tracer within an application's main file, setting up necessary dependencies like Slim framework and Monolog logger. ```php getTracer( 'dice-server', '0.1.0', 'https://opentelemetry.io/schemas/1.24.0' ); $logger = new Logger('dice-server'); $logger->pushHandler(new StreamHandler('php://stdout', Logger::INFO)); $app = AppFactory::create(); $dice = new Dice(); $app->get('/rolldice', function (Request $request, Response $response) use ($logger, $dice, $tracer) { // ... ``` -------------------------------- ### Roll Dice Server CMakeLists.txt Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/cpp/getting-started.md Create a file called CMakeLists.txt inside roll-dice to define the Oat++ library directories, include paths, and link against Oat++ during the compilation process. ```cmake cmake_minimum_required(VERSION 3.25) project(RollDiceServer) # Set C++ standard (e.g., C++17) set(CMAKE_CXX_STANDARD 17) set(project_name roll-dice-server) # Define your project's source files set(SOURCES main.cpp # Add your source files here ) ``` -------------------------------- ### Run OpenTelemetry Installer (Basic Mode) Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2023/php-auto-instrumentation/index.md Execute the installer script with the 'basic' argument to automatically configure OpenTelemetry instrumentation. ```sh ./vendor/bin/install-otel-instrumentation basic ``` -------------------------------- ### Add Custom Resources in .NET Code Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/dotnet/resources.md Builds a ResourceBuilder to add custom resources like environment.name and team.name in code. This example extends the getting started sample by adding service details and custom attributes. ```csharp using System.Diagnostics; using System.Collections.Generic; using OpenTelemetry; using OpenTelemetry.Trace; using OpenTelemetry.Resources; var serviceName = "resource-tutorial-dotnet"; var serviceVersion = "1.0"; var resourceBuilder = ResourceBuilder .CreateDefault() .AddService(serviceName: serviceName, serviceVersion: serviceVersion) .AddAttributes(new Dictionary { ["environment.name"] = "production", ["team.name"] = "backend" }); var sourceName = "tutorial-dotnet"; using var tracerProvider = Sdk.CreateTracerProviderBuilder() .AddSource(sourceName) .SetResourceBuilder(resourceBuilder) .AddConsoleExporter() .Build(); var MyActivitySource = new ActivitySource(sourceName); using var activity = MyActivitySource.StartActivity("SayHello"); activity?.SetTag("foo", 1); activity?.SetTag("bar", "Hello, World!"); activity?.SetTag("baz", new int[] { 1, 2, 3 }); ``` -------------------------------- ### Specify Configurations via Environment Variables and HTTP Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/collector/configuration.md Demonstrates providing configurations using environment variables and HTTP URIs. ```shell otelcol --config=env:MY_CONFIG_IN_AN_ENVVAR --config=https://server/config.yaml ``` -------------------------------- ### Initialize the OpenTelemetry SDK Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/go/getting-started.md This Go code snippet demonstrates how to bootstrap the OpenTelemetry SDK, including setting up propagators, trace providers, meter providers, and logger providers with stdout exporters for demonstration purposes. ```go package main import ( "context" "errors" "time" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/stdout/stdoutlog" "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" "go.opentelemetry.io/otel/log/global" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/sdk/log" "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/trace" ) // setupOTelSDK bootstraps the OpenTelemetry pipeline. // If it does not return an error, make sure to call shutdown for proper cleanup. func setupOTelSDK(ctx context.Context) (func(context.Context) error, error) { var shutdownFuncs []func(context.Context) error var err error // shutdown calls cleanup functions registered via shutdownFuncs. // The errors from the calls are joined. // Each registered cleanup will be invoked once. shutdown := func(ctx context.Context) error { var err error for _, fn := range shutdownFuncs { err = errors.Join(err, fn(ctx)) } shutdownFuncs = nil return err } // handleErr calls shutdown for cleanup and makes sure that all errors are returned. handleErr := func(inErr error) { err = errors.Join(inErr, shutdown(ctx)) } // Set up propagator. prop := newPropagator() otel.SetTextMapPropagator(prop) // Set up trace provider. tracerProvider, err := newTracerProvider() if err != nil { handleErr(err) return shutdown, err } shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown) otel.SetTracerProvider(tracerProvider) // Set up meter provider. meterProvider, err := newMeterProvider() if err != nil { handleErr(err) return shutdown, err } shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown) otel.SetMeterProvider(meterProvider) // Set up logger provider. loggerProvider, err := newLoggerProvider() if err != nil { handleErr(err) return shutdown, err } shutdownFuncs = append(shutdownFuncs, loggerProvider.Shutdown) global.SetLoggerProvider(loggerProvider) return shutdown, err } func newPropagator() propagation.TextMapPropagator { return propagation.NewCompositeTextMapPropagator( propagation.TraceContext{}, propagation.Baggage{}, ) } func newTracerProvider() (*trace.TracerProvider, error) { traceExporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint()) if err != nil { return nil, err } tracerProvider := trace.NewTracerProvider( trace.WithBatcher(traceExporter, // Default is 5s. Set to 1s for demonstrative purposes. trace.WithBatchTimeout(time.Second)), ) return tracerProvider, nil } func newMeterProvider() (*metric.MeterProvider, error) { metricExporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint()) if err != nil { return nil, err } meterProvider := metric.NewMeterProvider( metric.WithReader(metric.NewPeriodicReader(metricExporter, // Default is 1m. Set to 3s for demonstrative purposes. metric.WithInterval(3*time.Second))), ) return meterProvider, nil } func newLoggerProvider() (*log.LoggerProvider, error) { logExporter, err := stdoutlog.New(stdoutlog.WithPrettyPrint()) if err != nil { return nil, err } loggerProvider := log.NewLoggerProvider( log.WithProcessor(log.NewBatchProcessor(logExporter)), ) return loggerProvider, nil } ``` -------------------------------- ### Install Jaeger Exporter for Go Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2022/go-web-app-instrumentation/index.md Use go get to install the Jaeger exporter package. ```shell go get go.opentelemetry.io/otel/exporters/jaeger ``` -------------------------------- ### Run the Swift Application Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/swift/getting-started.md Execute your Swift application from the command line to start the server and begin emitting telemetry data. ```sh swift run ``` -------------------------------- ### Install Gin and Mongo-driver Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2022/go-web-app-instrumentation/index.md Installs the Gin web framework and the MongoDB driver for Go. ```shell go get -u github.com/gin-gonic/gin go get go.mongodb.org/mongo-driver/mongo ``` -------------------------------- ### Start Kafka Zookeeper Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/blog/2023/jmx-metric-insight/index.md Start the Zookeeper server, which is required for Kafka to function. Ensure the properties file path is correct for your installation. ```shell zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties ``` -------------------------------- ### Initialize Tracing in Library File (dice.php) Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/php/instrumentation.md Example of acquiring a tracer within a library class, demonstrating how to instrument reusable components. ```php tracer = $tracerProvider->getTracer( 'dice-lib', '0.1.0', 'https://opentelemetry.io/schemas/1.24.0' ); } public function roll($rolls) { $result = []; for ($i = 0; $i < $rolls; $i++) { $result[] = $this->rollOnce(); } return $result; } private function rollOnce() { $result = random_int(1, 6); return $result; } } ``` -------------------------------- ### Install and Enable Custom Resource Detector in PHP Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/php/resources.md Install a custom resource detector package using composer and then enable it using the OTEL_PHP_RESOURCE_DETECTORS environment variable. This example installs and enables the 'container' detector. ```shell composer require open-telemetry/detector-container env OTEL_PHP_RESOURCE_DETECTORS=container \ php example.php ``` -------------------------------- ### Set up Python Virtual Environment (Linux/macOS) Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/python/getting-started.md Creates a new directory, navigates into it, and sets up a Python virtual environment using venv for isolated dependency management. ```shell mkdir otel-getting-started cd otel-getting-started python3 -m venv venv source ./venv/bin/activate ``` -------------------------------- ### Docker Run Command Example Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/ja/docs/security/config-best-practices.md Example of a 'docker run' command to start the OpenTelemetry Collector, specifying hostname and port mapping. ```shell docker run --hostname my-hostname --name container-name -p 127.0.0.1:4567:4317 otel/opentelemetry-collector:{{% param collector_vers %}} ``` -------------------------------- ### Add Specific Instrumentation Packages Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/languages/dotnet/libraries.md Install the ASP.NET Core and HTTP client instrumentation packages. Use the `--prerelease` flag as these packages may be in a pre-release state. ```sh dotnet add package OpenTelemetry.Instrumentation.AspNetCore --prerelease dotnet add package OpenTelemetry.Instrumentation.Http --prerelease ``` -------------------------------- ### Example Instrumentation Resource Output Source: https://github.com/open-telemetry/opentelemetry.io/blob/main/content/en/docs/platforms/kubernetes/operator/troubleshooting/automatic.md This is an example of the output you should see when describing an Instrumentation resource. It shows details about the installed instrumentation, including image versions and exporter configuration. ```yaml Name: python-instrumentation Namespace: application Labels: app.kubernetes.io/managed-by=opentelemetry-operator Annotations: instrumentation.opentelemetry.io/default-auto-instrumentation-apache-httpd-image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-apache-httpd:1.0.3 instrumentation.opentelemetry.io/default-auto-instrumentation-dotnet-image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-dotnet:0.7.0 instrumentation.opentelemetry.io/default-auto-instrumentation-go-image: ghcr.io/open-telemetry/opentelemetry-go-instrumentation/autoinstrumentation-go:v0.2.1-alpha instrumentation.opentelemetry.io/default-auto-instrumentation-java-image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:1.26.0 instrumentation.opentelemetry.io/default-auto-instrumentation-nodejs-image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-nodejs:0.40.0 instrumentation.opentelemetry.io/default-auto-instrumentation-python-image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.39b0 API Version: opentelemetry.io/v1alpha1 Kind: Instrumentation Metadata: Creation Timestamp: 2023-07-28T03:42:12Z Generation: 1 Resource Version: 3385 UID: 646661d5-a8fc-4b64-80b7-8587c9865f53 Spec: ... Exporter: Endpoint: http://otel-collector-collector.opentelemetry.svc.cluster.local:4318 ... Propagators: tracecontext baggage Python: Image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-python:0.39b0 Resource Requirements: Limits: Cpu: 500m Memory: 32Mi Requests: Cpu: 50m Memory: 32Mi Resource: Sampler: Events: ```