Annotation Type OpenTelemetry


@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.

  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The base URL of an OTLP/HTTP collector to export to directly; /v1/traces is appended.
    Headers for a direct export, each "Name: value".
    Further hosts to send the trace context to.
    boolean
    Whether 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 with cn1.otel.relay.token expects.
    boolean
    Traces only while the user has granted analytics consent through com.codename1.analytics.Analytics.
    double
    The share of new traces recorded, from 0 to 1.
    The service.name the app reports as.
  • Element Details

    • relay

      String relay
      The base URL of a Codename One backend that relays spans to the collector.
      Default:
      ""
    • endpoint

      String endpoint
      The base URL of an OTLP/HTTP collector to export to directly; /v1/traces is appended.
      Default:
      ""
    • serviceName

      String serviceName
      The service.name the app reports as. Defaults to the app's name.
      Default:
      ""
    • headers

      String[] headers
      Headers for a direct export, each "Name: value".
      Default:
      {}
    • relayToken

      String relayToken
      The token a relay configured with cn1.otel.relay.token expects.
      Default:
      ""
    • sampleRatio

      double sampleRatio
      The share of new traces recorded, from 0 to 1.
      Default:
      1.0
    • protobuf

      boolean protobuf
      Whether a direct export is binary protobuf (the default) or JSON.
      Default:
      true
    • propagateTo

      String[] propagateTo
      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.
      Default:
      {}
    • requireAnalyticsConsent

      boolean requireAnalyticsConsent
      Traces only while the user has granted analytics consent through com.codename1.analytics.Analytics. See TelemetryConfig.requireAnalyticsConsent.
      Default:
      false