OpenTelemetry
Export traces and metrics with the OpenTelemetry operator on OpenShift: a collector, auto-instrumentation, and the environment variables an SDK already understands.
OpenTelemetry is the instrumentation and the protocol, not a database. Libraries in the process create spans and metrics. They export them over OTLP to a collector. The collector forwards traces to Tempo and metrics to Prometheus. The application does not know those backends exist. Tracing is how you read what arrives. This lab is how it leaves the pod.
The Red Hat build of OpenTelemetry is the operator we install. It is the supported distribution of the community collector and the auto-instrumentation images, and it matches the version matrix of the OpenShift release you are on. Install it from OperatorHub into openshift-opentelemetry-operator (the name the operator offers). The CRDs you will use are OpenTelemetryCollector and Instrumentation.
A collector
One collector Deployment for the cluster is enough until its CPU says otherwise. Namespaces send OTLP to it. It is allowed to drop data when it is overloaded (memory_limiter) rather than take the application down with it.
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel
namespace: opentelemetry
spec:
mode: deployment
config:
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 75
spike_limit_percentage: 25
batch: {}
exporters:
otlp:
endpoint: tempo.tempo.svc:4317
tls:
insecure: true
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlp]
insecure: true is for Tempo inside the cluster with no TLS on that port. If Tempo presents a certificate, set insecure: false and name the CA. A collector that cannot export will retry and then drop. The collector's own logs are the first place to look when Grafana shows nothing.
The Service is otel-collector.opentelemetry.svc on 4317 (gRPC) and 4318 (HTTP). Confirm with oc get svc -n opentelemetry. Applications use the HTTP endpoint unless you know the client speaks gRPC.
Apply a NetworkPolicy that allows the application namespaces to reach those ports and allows nothing else to scrape the collector. The collector sees every prompt attribute you were careless enough to attach. Treat its namespace like a log archive.
Auto-instrumentation
For Java and .NET, the operator can inject the agent so you do not rebuild to get HTTP spans. An Instrumentation names the exporter and the propagators:
apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
name: app
namespace: payments
spec:
exporter:
endpoint: http://otel-collector.opentelemetry.svc:4318
propagators:
- tracecontext
- baggage
env:
- name: OTEL_SERVICE_NAME
value: orders
Annotate the workload, not the namespace, until you trust it:
oc patch deploy/orders -n payments --type merge \
-p '{"spec":{"template":{"metadata":{"annotations":{"instrumentation.opentelemetry.io/inject-dotnet":"true"}}}}}'
Use inject-java for a Java Deployment. The pod will restart with an init path that adds the agent. A trace for one GET should appear in Grafana with the service name orders. If the pod fails to start, the image pull of the agent failed (disconnected clusters need the agent mirrored) or the annotation points at an Instrumentation in another namespace. oc describe pod shows the injection error.
Quarkus and recent Spring Boot do not need the agent. They have OpenTelemetry in the framework. Set the exporter endpoint and leave the agent off, or you will send every span twice.
The SDK variables
Any process using the OpenTelemetry SDK honours the same environment, which is what the .NET microservices lab sets:
env:
- name: OTEL_SERVICE_NAME
value: orders
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: http://otel-collector.opentelemetry.svc:4318
- name: OTEL_PROPAGATORS
value: tracecontext,baggage
OTEL_SERVICE_NAME is the label you will search by. A default of unknown_service means the variable was missing and your traces are mixed with everyone else's. OTEL_TRACES_SAMPLER=parentbased_traceidratio and OTEL_TRACES_SAMPLER_ARG=0.1 keep ten percent once the volume is real. In the test namespace, leave the sampler at the default and keep all of them.
Propagators have to match on every hop. tracecontext is the W3C traceparent header. A service that uses a vendor-specific propagator will start a new trace at its door.
Prove one request
curl -sS -D - -o /dev/null https://orders-payments.apps.example.com/health/ready
The response headers may include traceparent if the application echoes it. In Grafana's Tempo datasource, search the last five minutes for service name orders. You want a span for the inbound HTTP server and, once Catalog is instrumented, a child for the outbound HTTP client. A server span with no client child means the HTTP client library is not hooked. Auto-instrumentation covers the common clients. A hand-rolled socket will not appear until you create a span in code.
Metrics from the SDK can go to the same collector and out through a Prometheus exporter on the collector. Do that when an application metric is not already a /metrics endpoint Prometheus scrapes. Do not send the same metric both ways and then wonder why the graph doubled.
What's next
Service mesh instruments the network even when the binary has no SDK, and it is the wrong tool for a span inside one function. Use the SDK or the agent for application detail, and the mesh for the calls the application cannot see. The platform drill that should produce a trace you can open is in Platform testing.