Skip to content

Instrument Applications

Application instrumentation is the process of adding observability signals — traces, metrics, and logs — to your application code. The OpenSearch Observability Stack uses OpenTelemetry (OTel) as its standard instrumentation framework, giving you a vendor-neutral way to collect telemetry from any language.

Your application uses an OpenTelemetry SDK to generate telemetry data and export it to the OTel Collector running alongside your stack:

Application (OTel SDK) → OTel Collector (localhost:4317/4318) → Data Prepper → OpenSearch

The Collector accepts data over two protocols:

ProtocolPortUse case
gRPC4317Server-side applications (recommended)
HTTP/protobuf4318Browser apps, environments where gRPC is unavailable

OpenTelemetry offers two approaches to instrumenting your code:

Auto-instrumentation uses agents or require hooks to automatically capture telemetry from popular frameworks and libraries without code changes. This is the fastest way to get started.

Best for: Getting broad coverage quickly, standard web frameworks, database clients, HTTP libraries.

Available for: Python, Node.js, Java, .NET, Ruby, PHP.

Manual instrumentation gives you full control over what gets traced and measured. You create spans, record metrics, and emit logs explicitly in your code.

Best for: Custom business logic, AI/ML pipelines, agent workflows, fine-grained control.

Available for: All languages with an OpenTelemetry SDK.

Most production applications use both approaches together — auto-instrumentation for framework-level coverage and manual instrumentation for business-specific observability.

All OpenTelemetry SDKs respect a standard set of environment variables. You can configure instrumentation without code changes by setting these:

VariableDescriptionDefault
OTEL_SERVICE_NAMELogical name of your serviceunknown_service
OTEL_EXPORTER_OTLP_ENDPOINTCollector endpoint URLhttp://localhost:4317 (gRPC)
OTEL_EXPORTER_OTLP_PROTOCOLExport protocol (grpc, http/protobuf)grpc
OTEL_TRACES_EXPORTERTraces exporter (otlp, none)otlp
OTEL_METRICS_EXPORTERMetrics exporter (otlp, none)otlp
OTEL_LOGS_EXPORTERLogs exporter (otlp, none)otlp
OTEL_RESOURCE_ATTRIBUTESComma-separated key=value resource attributes
OTEL_TRACES_SAMPLERSampler type (always_on, traceidratio, parentbased_traceidratio)parentbased_always_on
OTEL_TRACES_SAMPLER_ARGSampler argument (e.g., ratio 0.1)
OTEL_PROPAGATORSContext propagation formatstracecontext,baggage

Example using environment variables:

Terminal window
export OTEL_SERVICE_NAME="my-service"
export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317"
export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=production,service.version=2.1.0"

Every telemetry signal includes resource attributes that identify the source. At minimum, set these:

AttributeDescriptionExample
service.nameName of the servicecheckout-service
service.versionVersion of the service1.2.3
deployment.environmentDeployment environmentproduction

Choose your language to get started:

LanguageAuto-instrumentationPageUpstream Docs
PythonYesPythonOTel Python
Node.jsYesNode.jsOTel JS
JavaYesJavaOTel Java
GoNo (use middleware)GoOTel Go
.NETYes.NETOTel .NET
RubyYesRubyOTel Ruby
Browser / FrontendPartialBrowserOTel JS