Observability - OpenTelemetry Doc V2
Language APIs & SDKs
OpenTelemetry code instrumentation is supported for many popular programming languages
- OpenTelemetry code instrumentation is supported for the languages listed in the Statuses and Releases table below.
- For Go, .NET, PHP, Python, Java and JavaScript you can use zero-code solutions to add instrumentation to your application without code changes.
- If you are using Kubernetes, you can use the OpenTelemetry Operator for Kubernetes to inject these zero-code solutions into your application.
Status and Releases
Language | Traces | Metrics | Logs |
---|---|---|---|
C++ | Stable | Stable | Stable |
C#/.NET | Stable | Stable | Stable |
Go | Stable | Stable | Beta |
Java | Stable | Stable | Stable |
JavaScript | Stable | Stable | Development |
Python | Stable | Stable | Development |
SDK Configuration
- OpenTelemetry SDKs support configuration in each language and with environment variables.
- Values set with environment variables override equivalent configuration in code using SDK APIs.
General
Support for environment variables is optional.
OTEL_SERVICE_NAME
- Sets the value of the service.name resource attribute.
- Default value - unknown_service
- If service.name is also provided in OTEL_RESOURCE_ATTRIBUTES, then OTEL_SERVICE_NAME takes precedence.
- export OTEL_SERVICE_NAME=”your-service-name”
OTEL_RESOURCE_ATTRIBUTES
- Key-value pairs to be used as resource attributes. See Resource SDK for more details.
- Default value - Empty
- export OTEL_RESOURCE_ATTRIBUTES=”key1=value1,key2=value2”
OTEL_TRACES_SAMPLER
- Specifies the Sampler used to sample traces by the SDK.
- Default value - parentbased_always_on
- export OTEL_TRACES_SAMPLER=”traceidratio”
Accepted values for OTEL_TRACES_SAMPLER are:
Sampler | Desc |
---|---|
always_on | AlwaysOnSampler |
always_off | AlwaysOffSampler |
traceidratio | TraceIdRatioBased |
parentbased_always_on | ParentBased(root=AlwaysOnSampler) |
parentbased_always_off | ParentBased(root=AlwaysOffSampler) |
parentbased_traceidratio | ParentBased(root=TraceIdRatioBased) |
parentbased_jaeger_remote | ParentBased(root=JaegerRemoteSampler) |
jaeger_remote | JaegerRemoteSampler |
xray | AWS X-Ray Centralized Sampling (third party) |
OTEL_TRACES_SAMPLER_ARG
- Specifies arguments, if applicable, to the sampler defined in by OTEL_TRACES_SAMPLER.
- The specified value will only be used if OTEL_TRACES_SAMPLER is set.
- Each Sampler type defines its own expected input, if any.
- Invalid or unrecognized input is logged as an error.
- Default value - Empty
1 | export OTEL_TRACES_SAMPLER="traceidratio" |
Depending on the value of OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG may be set as follows:
- For traceidratio and parentbased_traceidratio samplers: Sampling probability, a number in the [0..1] range, e.g. “0.25”. - Default is 1.0 if unset.
OTEL_PROPAGATORS
- Specifies Propagators to be used in a comma-separated list.
- Default value - tracecontext,baggage
- export OTEL_PROPAGATORS=”b3”
Accepted values for OTEL_PROPAGATORS are:
Propagator | Desc |
---|---|
tracecontext | W3C Trace Context |
baggage | W3C Baggage |
b3 | B3 Single |
b3multi | B3 Multi |
jaeger | Jaeger |
xray | AWS X-Ray |
ottrace | OT Trace |
none | No automatically configured propagator. |
OTEL_TRACES_EXPORTER
- Specifies which exporter is used for traces. Depending on the implementation it may be a comma-separated list.
- Default value - otlp
- export OTEL_TRACES_EXPORTER=”jaeger”
Accepted values for are:
Exporter | Desc |
---|---|
otlp | OTLP |
jaeger | export in Jaeger data model |
zipkin | Zipkin |
console | Standard Output |
none | No automatically configured exporter for traces. |
OTEL_METRICS_EXPORTER
- Specifies which exporter is used for metrics. Depending on the implementation it may be a comma-separated list.
- Default value - otlp
- export OTEL_METRICS_EXPORTER=”prometheus”
Accepted values for OTEL_METRICS_EXPORTER are:
Exporter | Desc |
---|---|
otlp | OTLP |
prometheus | Prometheus |
console | Standard Output |
none | No automatically configured exporter for metrics. |
OTEL_LOGS_EXPORTER
- Specifies which exporter is used for logs. Depending on the implementation it may be a comma-separated list.
- Default value - otlp
- export OTEL_LOGS_EXPORTER=”otlp”
Accepted values for OTEL_LOGS_EXPORTER are:
Exporter | Desc |
---|---|
otlp | OTLP |
console | Standard Output |
none | No automatically configured exporter for logs. |
OTLP Exporter
Endpoint Configuration
The following environment variables let you configure an OTLP/gRPC or OTLP/HTTP endpoint for your traces, metrics, and logs.
OTEL_EXPORTER_OTLP_ENDPOINT
A base endpoint URL for any signal type, with an optionally-specified port number.
Helpful for when you’re sending more than one signal to the same endpoint and want one environment variable to control the endpoint.
Default value
- gRPC - http://localhost:4317
- HTTP - http://localhost:4318
Example
- gRPC - export OTEL_EXPORTER_OTLP_ENDPOINT=”https://my-api-endpoint:443“
- HTTP - export OTEL_EXPORTER_OTLP_ENDPOINT=”http://my-api-endpoint/“
For OTLP/HTTP, exporters in the SDK construct signal-specific URLs when this environment variable is set.
This means that if you’re sending traces, metrics, and logs, the following URLs are constructed from the example above:
Traces - “http://my-api-endpoint**/v1/traces**”
Metrics - “http://my-api-endpoint**/v1/metrics**”
Logs - “http://my-api-endpoint**/v1/logs**”
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
- Endpoint URL for trace data only, with an optionally-specified port number. Typically ends with v1/traces when using OTLP/HTTP.
- Default value
- gRPC - “http://localhost:4317“
- HTTP - “http://localhost:4318**/v1/traces**”
- Example
- gRPC - export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=”https://my-api-endpoint:443“
- HTTP - export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=”http://my-api-endpoint**/v1/traces**”
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT
- Endpoint URL for metric data only, with an optionally-specified port number. Typically ends with v1/metrics when using OTLP/HTTP.
- Default value
- gRPC - “http://localhost:4317“
- HTTP - “http://localhost:4318/**v1/metrics**”
- Example
- gRPC - export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=”https://my-api-endpoint:443“
- HTTP - export OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=”http://my-api-endpoint/**v1/metrics**”
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
- Endpoint URL for log data only, with an optionally-specified port number. Typically ends with v1/logs when using OTLP/HTTP.
- Default value
- gRPC - “http://localhost:4317“
- HTTP - “http://localhost:4318/**v1/logs**”
- Example
- gRPC - export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=”https://my-api-endpoint:443“
- HTTP - export OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=”http://my-api-endpoint/**v1/logs**”
Header configuration
The following environment variables let you configure additional headers as a list of key-value pairs to add in outgoing gRPC or HTTP requests.
OTEL_EXPORTER_OTLP_HEADERS
- A list of headers to apply to all outgoing data (traces, metrics, and logs).
- Default value - N/A
- export OTEL_EXPORTER_OTLP_HEADERS=”api-key=key,other-config-value=value”
OTEL_EXPORTER_OTLP_TRACES_HEADERS
- A list of headers to apply to all outgoing traces.
- Default value - N/A
- export OTEL_EXPORTER_OTLP_TRACES_HEADERS=”api-key=key,other-config-value=value”
OTEL_EXPORTER_OTLP_METRICS_HEADERS
- A list of headers to apply to all outgoing metrics.
- Default value - N/A
- export OTEL_EXPORTER_OTLP_METRICS_HEADERS=”api-key=key,other-config-value=value”
OTEL_EXPORTER_OTLP_LOGS_HEADERS
- A list of headers to apply to all outgoing logs.
- Default value - N/A
- export OTEL_EXPORTER_OTLP_LOGS_HEADERS=”api-key=key,other-config-value=value”
Timeout Configuration
configure the maximum time (in milliseconds) an OTLP Exporter will wait before transmitting the net batch of data.
OTEL_EXPORTER_OTLP_TIMEOUT
- The timeout value for all outgoing data (traces, metrics, and logs) in milliseconds.
- Default value - 10000 - 10s
- export OTEL_EXPORTER_OTLP_TIMEOUT=500
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT
- The timeout value for all outgoing traces in milliseconds.
- Default value - 10000 - 10s
- export OTEL_EXPORTER_OTLP_TRACES_TIMEOUT=500
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT
- The timeout value for all outgoing metrics in milliseconds.
- Default value - 10000 - 10s
- export OTEL_EXPORTER_OTLP_METRICS_TIMEOUT=500
OTEL_EXPORTER_OTLP_LOGS_TIMEOUT
- The timeout value for all outgoing logs in milliseconds.
- Default value - 10000 - 10s
- export OTEL_EXPORTER_OTLP_LOGS_TIMEOUT=500
Protocol configuration
The following environment variables configure the OTLP transport protocol an OTLP exporter uses.
OTEL_EXPORTER_OTLP_PROTOCOL
- Specifies the OTLP transport protocol to be used for all telemetry data.
- Default value - SDK-dependent, but will typically be either http/protobuf or grpc.
- export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
Valid values are:
Transport protocol | Desc |
---|---|
grpc | OTLP/gRPC |
http/protobuf | OTLP/HTTP + protobuf |
http/json | OTLP/HTTP + JSON |
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL
Specifies the OTLP transport protocol to be used for trace data.
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL
Specifies the OTLP transport protocol to be used for metrics data.
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL
Specifies the OTLP transport protocol to be used for log data.