Instrumenting Your Application with OpenTelemetry ΒΆ

This tutorial shows how to add custom spans and metrics to your application when you are already using OpenTelemetry auto-instrumentation in Nais.

Prerequisites ΒΆ


1. Why Add Custom Instrumentation? ΒΆ

Auto-instrumentation provides traces and metrics for supported libraries and frameworks out of the box. However, to gain deeper insight into your business logic, you may want to:

  • Add custom spans to trace specific operations or workflows
  • Create custom metrics for business or application-specific events

2. Add Custom Spans ΒΆ

Custom spans let you trace important operations in your code. This is useful for tracking business logic, performance bottlenecks, or external calls not covered by auto-instrumentation.

Example in Java:

java

Other languages: See the OpenTelemetry documentation for language-specific APIs.


3. Add Custom Metrics ΒΆ

Custom metrics help you track application-specific events, counters, or timings. These metrics are exported to Prometheus and visualized in Grafana.

Example in Java:

java

Other languages: See the OpenTelemetry metrics documentation for details.


4. Deploy and Verify ΒΆ

  1. Deploy your application as usual.
  2. In Grafana, use the Tempo data source to view traces (including your custom spans).
  3. Use the Prometheus data source to query your custom metrics.

Next Steps ΒΆ

For more details, see the OpenTelemetry documentation.