OpenTelemetry Support from App to Database
A user taps Save. The spinner stays up for three seconds. Your API dashboard says the server is healthy, and the database log contains thousands of queries. Which of those facts explains the wait? What is Codename One? Codename One is an open-source framework for building native iOS, Android, desktop, and web apps from a single Java or Kotlin codebase. Learn more at codenameone.com . Distributed…
Codename One, an open-source framework, now offers support for OpenTelemetry, a common framework for collecting and exchanging observability signals. When a user saves data, the spinner remains active for three seconds, and a substantial number of queries appear in the server log. This wait time can be attributed to the operation that crosses process boundaries during the API request.
OpenTelemetry enables the tracing of application requests and backend work, allowing the operation to be followed into a tracing system utilized by the development team. The framework provides spans, which describe individual operations with start and end times, as well as attributes. A trace connects related spans, creating a pathway for tracing operations involved in a specific request or action.
To implement OpenTelemetry, an annotation is added on each side of the API request and backend work. The backend code includes imports for @GetMapping, @OpenTelemetry, @PathVariable, and @RestController annotations. A controller is created with a GET mapping for the /notes/{id} endpoint, and the @OpenTelemetry annotation includes the serviceName, which is set to "notes" in this case.
On the client-side, the OpenTelemetry annotation is placed on the application's main class, with relay, serviceName, sampleRatio, and requireAnalyticsConsent attributes. The relay must be enabled on the backend using the cn1.otel.enabled, cn1.otel.relay, and cn1.otel.relay.corsOrigin attributes. The client sends spans to the backend's /otel/v1/traces route, which then forwards them using its collector credentials.
While the framework handles much of the observability process, application code is still required to add spans or attributes explicitly. ConnectionRequest becomes the network instrumentation boundary, covering generated REST, GraphQL, and gRPC-Web clients. A parent span can be created to group requests belonging to a single action, and Telemetry.startSpan can be used to start a span when an operation begins, with Telemetry.endSpan called when the operation completes.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.