Instrument an application with OpenTelemetry
Instrumentation adds code to your application to collect telemetry data. This guide helps you set up OpenTelemetry instrumentation for your application.
Goal
Add instrumentation to your application to collect metrics, logs, and traces. Send this telemetry data to Grafana Cloud Application Observability or a self-managed backend.
Prerequisites
- Access to code: You can modify or deploy your application code
- Supported language: Your application uses Java, .NET, JavaScript, Python, PHP, Go, or another language supported by OpenTelemetry
- Data destination: You have access to Grafana Cloud or self-managed Loki, Mimir, or Tempo
Note
For Kubernetes deployments, you don’t need direct code access if you use the OpenTelemetry Operator.
Instrumentation methods
Choose from the following instrumentation approaches:
Grafana distributions: OpenTelemetry SDKs from Grafana with additional features
- Grafana OpenTelemetry Java (JVM agent, no code changes required, includes support for Scala and Kotlin)
- Grafana OpenTelemetry .NET
Upstream distributions: OpenTelemetry SDKs maintained by the community
Grafana Beyla: Auto-instrument applications using eBPF technology
- Grafana Beyla documentation
- Works with all languages and frameworks
- Requires no code changes
- Requires Linux with Kernel 5.8 or higher with BPF Type Format (BTF) enabled
OpenTelemetry Operator: For Kubernetes deployments
- OpenTelemetry Operator documentation
- Injects OpenTelemetry instrumentation into Kubernetes workloads
- Requires no application code changes
Recommended setup for Grafana Cloud
Grafana Labs recommends that you set up OpenTelemetry components, including instrumentation and an OpenTelemetry Collector distribution, using one of the Grafana Cloud setup guides.
These opinionated guides make it easy to get started. They include all the binaries, configuration, and connection parameters you need to set up OpenTelemetry for Grafana Cloud.
Comparison of instrumentation methods
Method | Code changes | Language support | Use case |
---|---|---|---|
Grafana OpenTelemetry Java | Not required (JVM agent) | Java | Offers advanced instrumentation features and Grafana support. |
Grafana OpenTelemetry .NET | Required | .NET | Offers advanced instrumentation features and Grafana support. |
Upstream OpenTelemetry SDKs | Required | Multiple languages | Provides standard instrumentation with community support. |
Grafana Beyla | Not required | Any language | Enables quick setup for any language, supports legacy applications, and requires Linux kernel 5.8+ with BTF enabled. |
OpenTelemetry Operator | Not required | Multiple languages | Manages and injects instrumentation in Kubernetes deployments. |
Next steps
After instrumenting your application, you need to configure your data pipeline:
- Set up an OpenTelemetry Collector distribution to process and forward telemetry data, or
- Send OTLP formatted telemetry data directly to a backend without using an OpenTelemetry Collector
When your data pipeline is configured, you can:
- Create dashboards in Grafana to visualize your application metrics
- Set up alerts for performance issues and anomalies
- Use Explore to investigate traces and logs
- Analyze application performance with Grafana Application Observability