Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class OtlpTracer

  1. Object
  2. 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:

keyvariabledefault
cn1.otel.endpointOTEL_EXPORTER_OTLP_ENDPOINThttp://localhost:4318; /v1/traces is appended
cn1.otel.traces.endpointOTEL_EXPORTER_OTLP_TRACES_ENDPOINTused as it is, and wins over the one above
cn1.otel.headersOTEL_EXPORTER_OTLP_HEADERSnone; name=value,name=value
cn1.otel.protocolOTEL_EXPORTER_OTLP_PROTOCOLhttp/protobuf, or http/json
cn1.otel.service.nameOTEL_SERVICE_NAMEwhat the build named it, else unknown_service
cn1.otel.resource.attributesOTEL_RESOURCE_ATTRIBUTESnone
cn1.otel.samplerOTEL_TRACES_SAMPLERparentbased_always_on
cn1.otel.sampler.argOTEL_TRACES_SAMPLER_ARGthe ratio, 1
cn1.otel.disabledOTEL_SDK_DISABLEDfalse

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

public static final String DISABLED = "cn1.otel.disabled"
public static final String ENDPOINT = "cn1.otel.endpoint"
public static final String TRACES_ENDPOINT = "cn1.otel.traces.endpoint"
public static final String HEADERS = "cn1.otel.headers"
public static final String TRACES_HEADERS = "cn1.otel.traces.headers"
public static final String PROTOCOL = "cn1.otel.protocol"
public static final String TRACES_PROTOCOL = "cn1.otel.traces.protocol"
public static final String SERVICE_NAME = "cn1.otel.service.name"
public static final String RESOURCE_ATTRIBUTES = "cn1.otel.resource.attributes"
public static final String SAMPLER = "cn1.otel.sampler"
public static final String SAMPLER_ARG = "cn1.otel.sampler.arg"
public static final String ATTRIBUTES_EXCLUDE = "cn1.otel.attributes.exclude"
public static final String QUEUE_SIZE = "cn1.otel.queue.size"
public static final String BATCH_SIZE = "cn1.otel.batch.size"
public static final String EXPORT_DELAY = "cn1.otel.export.delayMillis"
public static final String RELAY = "cn1.otel.relay"
public static final String RELAY_PATH = "cn1.otel.relay.path"
public static final String RELAY_TOKEN = "cn1.otel.relay.token"
public static final String RELAY_MAX_BYTES = "cn1.otel.relay.maxBytes"
public static final String RELAY_MAX_SPANS = "cn1.otel.relay.maxSpans"
public static final String RELAY_CORS_ORIGIN = "cn1.otel.relay.corsOrigin"

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 IOExceptionA tracer opened against config, or null when the configuration turns tracing off.
public boolean open(Config config) throws IOExceptionReads 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()
A tracer whose service name comes from configuration alone.

OtlpTracer

public OtlpTracer(String defaultServiceName)

Parameters

defaultServiceName String
used when neither cn1.otel.service.name nor OTEL_SERVICE_NAME is set; the build passes the name @OpenTelemetry gave

Method details

open

public static OtlpTracer open(Config config, String defaultServiceName) throws IOException

A 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"));

open

public boolean open(Config config) throws IOException
Reads the settings and starts whatever exports spans. Called once, by Backend.Builder.start or by the application before Tracing.install.

Returns

false when the configuration turned tracing off, in which case the tracer is not installed and nothing was started

startSpan

public Span startSpan(String name, int kind, Span parent, String traceparent, String tracestate)
A new span. Never null: a span the sampler declines is a non-recording one that still carries its trace context.

Parameters

name String
Not documented.
kind int
Not documented.
parent Span
the local parent, or null
traceparent String
a remote parent’s traceparent header, used when parent is null; null or malformed starts a new trace
tracestate String
the remote parent’s tracestate, or null

flush

public void flush(int timeoutMillis)
Blocks 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

public void shutdown(int timeoutMillis)
Flushes, then stops the exporter.

relay

public HttpServer.Handler relay()
The 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

public void metrics(Map out)
Adds this tracer’s counters to a metrics snapshot.