Annotation Type 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.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionThe base URL of an OTLP/HTTP collector to export to directly;/v1/tracesis appended.String[]Headers for a direct export, each"Name: value".String[]Further hosts to send the trace context to.booleanWhether a direct export is binary protobuf (the default) or JSON.The base URL of a Codename One backend that relays spans to the collector.The token a relay configured withcn1.otel.relay.tokenexpects.booleanTraces only while the user has granted analytics consent throughcom.codename1.analytics.Analytics.doubleThe share of new traces recorded, from 0 to 1.Theservice.namethe app reports as.
-
Element Details
-
relay
-
endpoint
String endpointThe base URL of an OTLP/HTTP collector to export to directly;/v1/tracesis appended.- Default:
""
-
serviceName
-
headers
-
relayToken
-
sampleRatio
double sampleRatioThe share of new traces recorded, from 0 to 1.- Default:
1.0
-
protobuf
boolean protobufWhether a direct export is binary protobuf (the default) or JSON.- Default:
true
-
propagateTo
String[] propagateToFurther hosts to send the trace context to. SeeTelemetryConfig.propagateTo: on the web only the relay's host and these receive it, because the header needs CORS permission.- Default:
{}
-
requireAnalyticsConsent
boolean requireAnalyticsConsentTraces only while the user has granted analytics consent throughcom.codename1.analytics.Analytics. SeeTelemetryConfig.requireAnalyticsConsent.- Default:
false
-