public final class TelemetryConfig
- Object
- TelemetryConfig
Where Telemetry sends spans, and how.
Two ways to reach a collector:
- Relay (the default): the app posts OTLP/JSON to its own backend – a
Codename One backend with
cn1.otel.relay=true– which adds the collector’s credentials and forwards the spans. Nothing secret ships in the app, and a browser never has to reach a third-party collector, so the JavaScript port needs no CORS setup on it. - Direct: the app posts to an OTLP/HTTP collector itself. Simpler to stand up, but whatever header authenticates the export is inside the app package, and anything inside an app package is public. Use an ingest token scoped to writing traces and nothing else.
Telemetry.install(new TelemetryConfig()
.relay("https://api.example.com")
.serviceName("shop-app"));
Nested types
enum TelemetryConfig.Mode | How spans leave the app. |
Constructors
public TelemetryConfig() |
Methods
Inherited methods
Constructor details
TelemetryConfig
public TelemetryConfig()Method details
relay
public TelemetryConfig relay(String backendUrl)Parameters
backendUrlString- the backend’s base URL, such as
https://api.example.com;/otel/v1/tracesis appended. A URL that already names a path ending in/v1/tracesis used as it is, for a relay mounted elsewhere.
Returns
Throws
IllegalArgumentException- when the URL is not http or https with a host and a valid port
direct
public TelemetryConfig direct(String collectorUrl)Parameters
collectorUrlString- the collector’s base URL,
/v1/tracesappended unless it is already there – the same ruleOTEL_EXPORTER_OTLP_ENDPOINTfollows everywhere
Returns
Throws
IllegalArgumentException- when the URL is not http or https with a host and a valid port
serviceName
public TelemetryConfig serviceName(String name)service.name the app’s spans are reported under. Defaults to the
app’s name.Returns
header
public TelemetryConfig header(String name, String value)Returns
Throws
IllegalArgumentException- when the name is not an HTTP token or the value holds a control character
relayToken
public TelemetryConfig relayToken(String token)cn1.otel.relay.token). It keeps casual traffic off the relay; it is not
a credential, since it ships in the app.Returns
Throws
IllegalArgumentException- when the token holds a control character, or begins or ends with whitespace
protobuf
public TelemetryConfig protobuf(boolean protobuf)Returns
sampleRatio
public TelemetryConfig sampleRatio(double ratio)Returns
Throws
IllegalArgumentException- for NaN
batchSize
public TelemetryConfig batchSize(int size)Returns
flushIntervalMillis
public TelemetryConfig flushIntervalMillis(int millis)Returns
propagateTo
public TelemetryConfig propagateTo(String host)Sends the W3C trace context to requests for this host as well.
By default the context goes to the relay’s host – the app’s own backend –
and, on every platform except the web, to every host. The web is the
exception because traceparent is not a CORS-safelisted header: sending it
to a server that does not allow it turns a working cross-origin request
into a failed preflight. Name the hosts that do allow it here.
Returns
propagateToAllHosts
public TelemetryConfig propagateToAllHosts()Returns
requireAnalyticsConsent
public TelemetryConfig requireAnalyticsConsent(boolean require)Records and propagates traces only while the user has granted ANALYTICS
consent through com.codename1.analytics.Analytics, the same consent the
analytics providers honour. Off by default: whether trace data needs consent
is the app’s decision, and depends on what it records and where it ships.
With it on and no consent, requests are sent exactly as they would be
without telemetry – no span, and no traceparent header – and spans
already buffered are dropped rather than exported. Before the user answers,
the analytics ConsentMode decides: OPT_IN (the default) means no.