Class OtlpTracer
- All Implemented Interfaces:
Tracer
OpenTelemetry tracing over OTLP/HTTP, with no OpenTelemetry library behind it.
The OpenTelemetry Java SDK cannot run here: the server is translated to C against a Java subset with no reflection and no service loading, and a binary that linked the SDK would be carrying it whether or not anyone traced. This is the part of it a server actually needs -- W3C trace context, the standard samplers, a bounded batch exporter, and the OTLP wire format in both its encodings -- and it is only in the binary when the project enables it.
Configured the way every OpenTelemetry SDK is, so operations tooling works
unchanged. Each setting has a cn1.otel.* key, readable from
application.properties like any other, and the standard OTEL_*
environment variable is honoured for it too:
| key | variable | default |
|---|---|---|
| cn1.otel.endpoint | OTEL_EXPORTER_OTLP_ENDPOINT | http://localhost:4318; /v1/traces is appended |
| cn1.otel.traces.endpoint | OTEL_EXPORTER_OTLP_TRACES_ENDPOINT | used as it is, and wins over the one above |
| cn1.otel.headers | OTEL_EXPORTER_OTLP_HEADERS | none; name=value,name=value |
| cn1.otel.protocol | OTEL_EXPORTER_OTLP_PROTOCOL | http/protobuf, or http/json |
| cn1.otel.service.name | OTEL_SERVICE_NAME | what the build named it, else unknown_service |
| cn1.otel.resource.attributes | OTEL_RESOURCE_ATTRIBUTES | none |
| cn1.otel.sampler | OTEL_TRACES_SAMPLER | parentbased_always_on |
| cn1.otel.sampler.arg | OTEL_TRACES_SAMPLER_ARG | the ratio, 1 |
| cn1.otel.disabled | OTEL_SDK_DISABLED | false |
cn1.otel.attributes.exclude names attributes never to record, as a
comma separated list (db.query.text,user_agent.original), and
cn1.otel.relay=true opens the endpoint the app's own spans are relayed
through; see OtlpRelay.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionA tracer whose service name comes from configuration alone.OtlpTracer(String defaultServiceName) -
Method Summary
Modifier and TypeMethodDescriptionvoidflush(int timeoutMillis) Blocks until what has ended so far is exported, or the time runs out.voidAdds this tracer's counters to a metrics snapshot.booleanReads the settings and starts whatever exports spans.static OtlpTracerA tracer opened againstconfig, or null when the configuration turns tracing off.relay()The handler that relays client spans to the collector, or null when this deployment does not offer one.voidshutdown(int timeoutMillis) Flushes, then stops the exporter.A new span.
-
Field Details
-
DISABLED
- See Also:
-
ENDPOINT
- See Also:
-
TRACES_ENDPOINT
- See Also:
-
HEADERS
- See Also:
-
TRACES_HEADERS
- See Also:
-
PROTOCOL
- See Also:
-
TRACES_PROTOCOL
- See Also:
-
SERVICE_NAME
- See Also:
-
RESOURCE_ATTRIBUTES
- See Also:
-
SAMPLER
- See Also:
-
SAMPLER_ARG
- See Also:
-
ATTRIBUTES_EXCLUDE
- See Also:
-
QUEUE_SIZE
- See Also:
-
BATCH_SIZE
- See Also:
-
EXPORT_DELAY
- See Also:
-
RELAY
- See Also:
-
RELAY_PATH
- See Also:
-
RELAY_TOKEN
- See Also:
-
RELAY_MAX_BYTES
- See Also:
-
RELAY_MAX_SPANS
- See Also:
-
RELAY_CORS_ORIGIN
- See Also:
-
-
Constructor Details
-
OtlpTracer
public OtlpTracer()A tracer whose service name comes from configuration alone. -
OtlpTracer
- Parameters:
defaultServiceName- used when neithercn1.otel.service.namenorOTEL_SERVICE_NAMEis set; the build passes the name@OpenTelemetrygave
-
-
Method Details
-
open
A tracer opened against
config, or null when the configuration turns tracing off. For a program that startsHttpServeror the Lambda loop itself:Tracing.install(OtlpTracer.open(Config.load(), "orders"));- Throws:
IOException
-
open
Description copied from interface:TracerReads the settings and starts whatever exports spans. Called once, byBackend.Builder.start()or by the application beforeTracing.install(Tracer).- Specified by:
openin interfaceTracer- Returns:
- false when the configuration turned tracing off, in which case the tracer is not installed and nothing was started
- Throws:
IOException
-
startSpan
Description copied from interface:TracerA new span. Never null: a span the sampler declines is a non-recording one that still carries its trace context. -
flush
public void flush(int timeoutMillis) Description copied from interface:TracerBlocks until what has ended so far is exported, or the time runs out. A Lambda host freezes the process between invocations, so a background exporter there only runs when something waits for it. -
shutdown
-
relay
Description copied from interface:TracerThe handler that relays client spans to the collector, or null when this deployment does not offer one. The builder puts it ahead of the routers. -
metrics
-