Migration to OpenTelemetry APM
OpenTelemetry, as an open-source observability framework, offers a vendor-neutral approach to collecting, processing, and exporting telemetry data such as traces, metrics, and logs.
This document aims to guide you through the process of migrating to OpenTelemetry APM. It covers the key steps involved, including preparing your environment and updating instrumentation.
Python
The OpenTelemetry Python consists of two main packages: API and SDK available as part of PyPI.
Installation
pip install opentelemetry-api
pip install opentelemetry-sdk
Instrumentation Setup
The basic steps involved in initialization a tracer and creating spans have been documented at Instrumentation
New Relic supports auto instrumentation of functions through the config file using https://docs.newrelic.com/docs/apm/agents/python-agent/configuration/python-agent-configuration/#txn-tracer-function. OpenTelemetry does not have such support but function spans can be easily created with minimal code through function decorators: Instrumentation
Instrumentation Libraries
You may also want to install certain instrumentation-libraries to auto-instrument standard Python packages. A list of available instrumentation-libraries is available here - opentelemetry-python-contrib/instrumentation at main · open-telemetry/opentelemetry-python-contrib
Examples
Common code scenarios and some example applications have been instrumented using OpenTelemetry. These are available at:
https://opentelemetry-python.readthedocs.io/en/stable/examples/
https://opentelemetry.io/docs/languages/python/cookbook/
Java
Installation
Zero-code instrumentation with Java uses a Java agent JAR attached to any Java 8+ application. It dynamically injects bytecode to capture telemetry from many popular libraries and frameworks.
curl -L -O https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar
export JAVA_TOOL_OPTIONS="-javaagent:PATH/TO/opentelemetry-javaagent.jar"
Instrumentation Setup
To setup the instrumentation and use the APIs for manual instrumentation,
Instrumentation Libraries
OpenTelemetry Java can automatically instrument and support a huge number of libraries, frameworks, and application servers listed out below
Examples
A set of fully-functional, working examples of using the OpenTelemetry Java APIs and SDK that should all be able to be run locally is present at https://github.com/open-telemetry/opentelemetry-java-examples#java-opentelemetry-examples
JavaScript
Installation
npm install @opentelemetry/sdk-node \
@opentelemetry/api \
@opentelemetry/auto-instrumentations-node \
@opentelemetry/sdk-metrics \
@opentelemetry/sdk-trace-node
Instrumentation Setup
The basic steps involved in initialization a tracer has been documented at https://opentelemetry.io/docs/languages/js/instrumentation/#initialize-tracing
For creating spans using the OpenTelemetry JS API, the following doc is useful: https://opentelemetry.io/docs/languages/js/instrumentation/#initialize-tracing
If you only want to use auto-instrumentation and not manually create any spans for your functions, look at the instrumentations libraries section below.
Instrumentation Libraries
For instrumentation-libraries to auto-instrument common third party npm packages. Each instrumentation library is an NPM package. A list of available instrumentation-libraries is available here -Registry
Examples
Some example applications for common use cases and packages have been instrumented using OpenTelemetry.
opentelemetry-js/examples at main · open-telemetry/opentelemetry-js
Go
Installation
Instrumentation Setup
The basic steps involved in initialization a tracer has been documented at Instrumentation
For creating spans using the OpenTelemetry JS API, the following doc is useful: Instrumentation
If you only want to use auto-instrumentation and not manually create any spans for your functions, look at the instrumentations libraries section below.
Instrumentation Libraries
For instrumentation-libraries to auto-instrument common third party npm packages. Each instrumentation library is a package installable through a command like go get go.opentelemetry.io/contrib/instrumentation/{import-path}/otel{package-name}
A list of all the available instrumentation-libraries is here - Registry
Examples
Some example applications for common use cases and packages have been instrumented using OpenTelemetry.
https://github.com/open-telemetry/opentelemetry-go/tree/main/example
.NET
Installation
Instrumentation Setup
To setup the instrumentation and use the APIs for manual instrumentation,
Instrumentation Libraries
To avoid spending time to manually add traces, logs, and metrics to the third-party libraries and frameworks you use, you can use the instrumentation libraries supported for auto instrumentation:
https://opentelemetry.io/ecosystem/registry/?language=dotnet
https://github.com/open-telemetry/opentelemetry-dotnet
Examples
Basic examples for .NET applications: https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/examples
Zero Code Instrumentation
Zero-code instrumentation adds the OpenTelemetry API and SDK capabilities to your application typically as an agent or agent-like installation.
Typically, zero-code instrumentation adds instrumentation for the libraries you’re using (needs to be set up for the libraries used by your application). This means that requests and responses, database calls, message queue calls, and so forth are what are instrumented. Your application’s code, however, is not typically instrumented. To instrument your code, you’ll need to manually instrument using the language specific OpenTelemetry APIs.
Automatic instrumentation is available for the following languages: