@Retention(CLASS) @Target({TYPE})

public @interface OpenTelemetry

Traces the app with OpenTelemetry: every network request becomes a span, and carries the W3C trace context to the server it reaches, so a tap in the app and the backend work it caused are one trace.

Put it on the main class. The build generates a bootstrap that installs com.codename1.telemetry.Telemetry before the app starts, and nothing else in the app changes.

// Through the app's own Codename One backend (cn1.otel.relay=true there),
// which holds the collector's credentials:
@OpenTelemetry(relay = "https://api.example.com", serviceName = "shop-app")
public class ShopApp extends Lifecycle { ... }

// Or straight to a collector. The header ships inside the app, so use a token
// that can write traces and nothing else:
@OpenTelemetry(endpoint = "https://collector.example.com:4318",
        headers = "Authorization: Api-Token dt0c01.ingest-only")
public class ShopApp extends Lifecycle { ... }

Exactly one of relay and endpoint is set. Without the annotation the telemetry classes are never referenced, so the app does not carry them.

Methods

public abstract String relay() default ""The base URL of a Codename One backend that relays spans to the collector.
public abstract String endpoint() default ""The base URL of an OTLP/HTTP collector to export to directly; /v1/traces is appended.
public abstract String serviceName() default ""The service.name the app reports as.
public abstract String[] headers() default {}Headers for a direct export, each "Name: value".
public abstract String relayToken() default ""The token a relay configured with cn1.otel.relay.token expects.
public abstract double sampleRatio() default 1.0The share of new traces recorded, from 0 to 1.
public abstract boolean protobuf() default trueWhether a direct export is binary protobuf (the default) or JSON.
public abstract String[] propagateTo() default {}Further hosts to send the trace context to.
public abstract boolean requireAnalyticsConsent() default falseTraces only while the user has granted analytics consent through com.codename1.analytics.Analytics.

Method details

relay

public abstract String relay() default ""
The base URL of a Codename One backend that relays spans to the collector.

endpoint

public abstract String endpoint() default ""
The base URL of an OTLP/HTTP collector to export to directly; /v1/traces is appended.

serviceName

public abstract String serviceName() default ""
The service.name the app reports as. Defaults to the app’s name.

headers

public abstract String[] headers() default {}
Headers for a direct export, each "Name: value".

relayToken

public abstract String relayToken() default ""
The token a relay configured with cn1.otel.relay.token expects.

sampleRatio

public abstract double sampleRatio() default 1.0
The share of new traces recorded, from 0 to 1.

protobuf

public abstract boolean protobuf() default true
Whether a direct export is binary protobuf (the default) or JSON.

propagateTo

public abstract String[] propagateTo() default {}
Further hosts to send the trace context to. See TelemetryConfig.propagateTo: on the web only the relay’s host and these receive it, because the header needs CORS permission.

requireAnalyticsConsent

public abstract boolean requireAnalyticsConsent() default false
Traces only while the user has granted analytics consent through com.codename1.analytics.Analytics. See TelemetryConfig.requireAnalyticsConsent.