Auto-instrumentation
With automatic instrumentation, OpenTelemetry libraries and agents intercept calls to standard frameworks and protocols and automatically generate spans. You get a trace without writing additional code: you just need to connect the agent or library and specify the export parameters.
How it works
Automatic instrumentation is embedded between your application and the libraries in use. Depending on the language, this works in different ways:
- Java: The Java agent modifies bytecode as classes are loaded.
- Python, Node.js: These tools replace calls to standard modules with wrappers that create spans.
In all cases, every intercepted call automatically creates a span with attributes under the OpenTelemetry semantic conventions
What is covered automatically
Automatic instrumentation creates spans for typical operations:
- HTTP servers and clients: Flask, Django, Express, Spring,
requests,net/http, etc. - Database clients: PostgreSQL, MySQL, Redis, and MongoDB.
- Message queues: Kafka and RabbitMQ.
For a complete list of supported libraries for each language, see the OpenTelemetry instrumentation registry
Common connection settings
Regardless of the language, to send traces to Monium Traces, specify the connection settings using environment variables:
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc"
export OTEL_SERVICE_NAME=<application_name>
export OTEL_EXPORTER_OTLP_ENDPOINT="ingest.monium.yandex.cloud:443"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Api-Key <API_key>,x-monium-project=folder__<folder_ID>"
export OTEL_RESOURCE_ATTRIBUTES="cluster=<environment>"
Where:
OTEL_SERVICE_NAME: Your application's name. It is used as theservice.namevalue in the resource attributes.OTEL_EXPORTER_OTLP_ENDPOINT: Monium endpoint.OTEL_EXPORTER_OTLP_HEADERS: Authorization headers and project bindings. To get an API key, create a service account with themonium.traces.writerrole and API key with theyc.monium.traces.writescope.OTEL_RESOURCE_ATTRIBUTES: Resource attributes.clustersets the environment. The default value isdefault.
Connection by languages
Python
-
Install the OpenTelemetry distribution and exporter:
pip install opentelemetry-distro opentelemetry-exporter-otlp -
Install instrumentation for the libraries your application uses:
opentelemetry-bootstrap -a installThe command will automatically detect any installed libraries, such as Flask, Django, requests, psycopg2, etc., and install the matching instrumentation packages.
-
Run the application using the
opentelemetry-instrumentwrapper:opentelemetry-instrument python my_app.py
Java
-
Download the OpenTelemetry Java agent
:curl -L -o opentelemetry-javaagent.jar \ https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar -
Run the application with the agent:
java -javaagent:opentelemetry-javaagent.jar -jar my_app.jarThe agent automatically instruments Spring, Servlet, JAX-RS, JDBC, Kafka, gRPC, and other libraries.
Node.js
-
Install the automatic instrumentation package:
npm install @opentelemetry/auto-instrumentations-node -
Run the application with automatic registration:
node --require @opentelemetry/auto-instrumentations-node/register app.js
Limitations
Automatic instrumentation covers only those operations for which ready-to-use libraries exist. It does not create spans for:
- Internal application business logic.
- Custom components and protocols.
- Operations where you need to add specific attributes.
To trace such operations, use manual instrumentation.