OpenTelemetry¶
Scope: instrumenting services for traces, metrics and logs with OpenTelemetry, and running the OpenTelemetry Collector between services and observability backends. The general rules are in general/operations-reliability.md: instrument with OpenTelemetry and follow its semantic conventions (OPS-11), and monitor the four golden signals (OPS-2). Keeping secrets and personal data out of logs is SEC-4 in general/security.md. For language-specific setup, see .NET (DOTNET-8) and the language pages of the OpenTelemetry documentation; for exporting telemetry from serverless platforms, see Serverless and edge hosting (HOST-13).
Entries are sorted by score from 1 to 10 (criteria): 9–10 start here or strongly recommended, 6–8 recommended, 1–5 further reading or conditional.
Adopted references¶
- 9 OpenTelemetry documentation: the baseline: concepts, signals, context propagation, instrumentation per language, zero-code instrumentation, sampling and the Collector.
- 8 Collector (OpenTelemetry docs): when to use a Collector, its configuration, the agent and gateway deployment patterns, scaling and internal telemetry.
- 8 Trace Context (W3C Recommendation): the
traceparentandtracestateHTTP headers that OpenTelemetry propagates by default. - 8 Handling sensitive data (OpenTelemetry docs): data minimization, and removing, hashing or truncating sensitive attributes with Collector processors.
- 7 Collector configuration best practices and Collector hosting best practices (OpenTelemetry docs): securing the Collector's configuration, network exposure, permissions and resource use.
- 7 OpenTelemetry semantic conventions: standard names for attributes, spans, metrics, events and resources, per area such as HTTP, databases and messaging.
Key rules¶
Resources and naming¶
- 8
OTEL-1Setservice.nameexplicitly in every service, with the same value for all instances of the service, and addservice.versionanddeployment.environment.nameas resource attributes. Otherwise the SDK reportsunknown_service. Set them withOTEL_SERVICE_NAMEandOTEL_RESOURCE_ATTRIBUTES, and let the SDK's resource detectors add host, container, Kubernetes and cloud attributes. (OpenTelemetry, Resources, Service semantic conventions) - 6
OTEL-2Before you name a custom attribute or metric, look for it in the semantic conventions; when none fits, prefix the new name with your company's reverse domain name, such ascom.acme., or with your application's name. Don't reuse an existing semantic convention namespace as the prefix: OpenTelemetry or other instrumentation may later use the same name for something else. (Semantic conventions, Naming: recommendations for application developers)
Instrumentation and context¶
- 8
OTEL-3Propagate trace context across every process boundary, including queues: keep the default W3C Trace Context propagator for HTTP and gRPC, and have producers attach the context to each message. Without it, consumer traces can't be connected to the producers that caused them. (OpenTelemetry, Context propagation, W3C, Trace Context, Semantic conventions for messaging spans: context propagation) - 7
OTEL-4Start with zero-code instrumentation or instrumentation libraries for your frameworks and clients, then add code-based spans, attributes and metrics for the business operations that matter. Zero-code instrumentation covers the edges of the application, such as requests, database calls and queue calls, but usually not your own code. (OpenTelemetry, Instrumentation, Zero-code) - 7
OTEL-5Correlate logs with traces: keep your logging library, connect it to OpenTelemetry with a log appender (bridge) so that each record carries the active trace and span IDs, and prefer structured logs. (OpenTelemetry, Logs: log appender / bridge, OpenTelemetry Logging: log correlation) - 7
OTEL-6Keep span names and metric attributes low-cardinality: use route templates such as/users/{id}instead of raw paths, and keep user IDs, request IDs and other unbounded values off metric attributes. Every attribute combination costs memory. The metrics SDK keeps at most 2000 combinations per metric by default and folds the rest into one data point markedotel.metric.overflow=true. (OpenTelemetry, Metrics: cardinality limits, Tracing API: span, Semantic conventions for HTTP metrics) - 6
OTEL-7Treat trace context from outside as untrusted: ignore or sanitize incoming trace headers from callers you don't trust, don't send internal context to external services, and never put credentials or personal data in baggage. (OpenTelemetry, Context propagation: security best practices)
Sampling¶
- 6
OTEL-8Choose sampling deliberately: don't sample when you produce little data, use consistent probability (head) sampling to cut volume cheaply, and add tail sampling in a Collector tier when you must keep every error or slow trace. All spans of a trace must reach the same tail-sampling Collector, so route them by trace ID with the load-balancing exporter. (OpenTelemetry, Sampling, Gateway deployment pattern, Tail sampling processor)
Collector¶
- 8
OTEL-9Makememory_limiterthe first processor in every Collector pipeline, setGOMEMLIMITto about 80% of the Collector's hard memory limit, and batch data after sampling and filtering, preferably with the exporter'ssending_queuebatching. Without limits, a burst of telemetry can crash the Collector with an out-of-memory error. (OpenTelemetry Collector, Recommended processors, Memory limiter processor: best practices, Exporter helper) - 8
OTEL-10Secure every Collector: bind receivers tolocalhostor a specific interface instead of0.0.0.0, require TLS and authentication on receivers that other hosts send to, keep credentials out of the configuration file, in a secret store or, where nothing else is available, in environment variables, and include only the components you use. This is how a Collector appliesSEC-20andSEC-13. (OpenTelemetry, Collector configuration best practices, Protect against denial of service attacks, Collector hosting best practices) - 7
OTEL-11Send telemetry over OTLP to an OpenTelemetry Collector, running as an agent next to the service or as a gateway, rather than from each service straight to a vendor. The Collector then handles retries, batching, encryption and filtering of sensitive data, and services don't need vendor-specific exporters. (OpenTelemetry, Collector: when to use a collector, Deploy the Collector)
Sensitive data¶
- 8
OTEL-12Keep secrets and personal data out of telemetry: don't record what you don't need, and remove, hash or truncate what instrumentation captures anyway, for example with the Collector'sredaction,attributes,transformorfilterprocessors. You are responsible for what instrumentation libraries capture, too, and a hash of a small value space, such as numeric user IDs, can be reversed. (OpenTelemetry, Handling sensitive data, Collector configuration best practices: scrub sensitive data)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 6 Weaver live check: an OpenTelemetry tool that receives the telemetry your tests emit over OTLP, compares it with the semantic conventions or your own registry, and exits with an error when it finds a violation, such as an attribute missing from the registry. Rego policies add your own checks. Partly checks
OTEL-2andOPS-11. - 5 Collector
validatecommand:otelcol validate --config=…checks a Collector configuration without starting it, so that CI can reject an invalid one. It rejects amemory_limiterwithout a memory limit or check interval, but doesn't require one. Partly checksOTEL-9.
Tutorials and further reading¶
- 7 Getting started (OpenTelemetry docs): where to start as a developer or as an operator.
- 7 OpenTelemetry Demo (OpenTelemetry docs): a multi-language microservice application, instrumented with OpenTelemetry, to run with Docker or Kubernetes and explore.
- 6 Training (OpenTelemetry): the free Linux Foundation course Getting Started with OpenTelemetry and the OpenTelemetry Certified Associate certification.