Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class OtlpTracer
- Object
- OtlpTracer
ImplementsTracer
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.
Fields
Constructors
public OtlpTracer() | A tracer whose service name comes from configuration alone. |
public OtlpTracer(String defaultServiceName) |
Methods
public static OtlpTracer open(Config config, String defaultServiceName)
throws IOException | A tracer opened against config, or null when the configuration turns tracing off. |
public boolean open(Config config)
throws IOException | Reads the settings and starts whatever exports spans. |
public Span startSpan(String name, int kind, Span parent, String traceparent, String tracestate) | A new span. |
public void flush(int timeoutMillis) | Blocks until what has ended so far is exported, or the time runs out. |
public void shutdown(int timeoutMillis) | Flushes, then stops the exporter. |
public HttpServer.Handler relay() | The handler that relays client spans to the collector, or null when this deployment does not offer one. |
public void metrics(Map out) | Adds this tracer’s counters to a metrics snapshot. |
Inherited methods
Field details
DISABLED
public static final String DISABLED = "cn1.otel.disabled"ENDPOINT
public static final String ENDPOINT = "cn1.otel.endpoint"TRACES_ENDPOINT
public static final String TRACES_ENDPOINT = "cn1.otel.traces.endpoint"HEADERS
public static final String HEADERS = "cn1.otel.headers"TRACES_HEADERS
public static final String TRACES_HEADERS = "cn1.otel.traces.headers"PROTOCOL
public static final String PROTOCOL = "cn1.otel.protocol"TRACES_PROTOCOL
public static final String TRACES_PROTOCOL = "cn1.otel.traces.protocol"SERVICE_NAME
public static final String SERVICE_NAME = "cn1.otel.service.name"RESOURCE_ATTRIBUTES
public static final String RESOURCE_ATTRIBUTES = "cn1.otel.resource.attributes"SAMPLER
public static final String SAMPLER = "cn1.otel.sampler"SAMPLER_ARG
public static final String SAMPLER_ARG = "cn1.otel.sampler.arg"ATTRIBUTES_EXCLUDE
public static final String ATTRIBUTES_EXCLUDE = "cn1.otel.attributes.exclude"QUEUE_SIZE
public static final String QUEUE_SIZE = "cn1.otel.queue.size"BATCH_SIZE
public static final String BATCH_SIZE = "cn1.otel.batch.size"EXPORT_DELAY
public static final String EXPORT_DELAY = "cn1.otel.export.delayMillis"RELAY
public static final String RELAY = "cn1.otel.relay"RELAY_PATH
public static final String RELAY_PATH = "cn1.otel.relay.path"RELAY_TOKEN
public static final String RELAY_TOKEN = "cn1.otel.relay.token"RELAY_MAX_BYTES
public static final String RELAY_MAX_BYTES = "cn1.otel.relay.maxBytes"RELAY_MAX_SPANS
public static final String RELAY_MAX_SPANS = "cn1.otel.relay.maxSpans"RELAY_CORS_ORIGIN
public static final String RELAY_CORS_ORIGIN = "cn1.otel.relay.corsOrigin"Constructor details
OtlpTracer
public OtlpTracer()OtlpTracer
public OtlpTracer(String defaultServiceName)Parameters
defaultServiceNameString- used when neither
cn1.otel.service.namenorOTEL_SERVICE_NAMEis set; the build passes the name@OpenTelemetrygave
Method details
open
public static OtlpTracer open(Config config, String defaultServiceName)
throws IOExceptionA tracer opened against config, or null when the configuration
turns tracing off. For a program that starts HttpServer or the
Lambda loop itself:
Tracing.install(OtlpTracer.open(Config.load(), "orders"));
Throws
open
public boolean open(Config config)
throws IOExceptionBackend.Builder.start or by the application before
Tracing.install.Returns
Throws
startSpan
public Span startSpan(String name, int kind, Span parent, String traceparent, String tracestate)Parameters
nameString- Not documented.
kindint- Not documented.
parentSpan- the local parent, or null
traceparentString- a remote parent’s
traceparentheader, used whenparentis null; null or malformed starts a new trace tracestateString- the remote parent’s
tracestate, or null
flush
public void flush(int timeoutMillis)shutdown
public void shutdown(int timeoutMillis)relay
public HttpServer.Handler relay()metrics
public void metrics(Map out)