docker-otel-lgtm
repository·main·Indexed 23 days ago
https://github.com/grafana/docker-otel-lgtmAn OpenTelemetry backend bundled into a single Docker image containing the OpenTelemetry Collector, Prometheus, Tempo, Loki, Pyroscope, and Grafana. Designed for development, demo, and testing environments, it includes examples for eBPF profiling, Java JSON logging in Kubernetes, Spring Boot instrumentation, and OpenTelemetry eBPF Instrumentation (OBI) for zero-code traces and metrics.
What's inside docker-otel-lgtm
- OBI (formerly Grafana Beyla) is a language-agnostic instrumentation method that uses Linux eBPF to hook into kernel-level events like network I/O and function calls. It automatically generates OpenTelemetry traces and metrics for HTTP/gRPC services without requiring any code changes, OpenTelemetry SDKs, or language-specific agents within the target applications.
How scheduled releases work
mainReleases for this project are automatically published on a weekly basis via a scheduled GitHub Actions workflow. The workflow runs every Friday at 09:00 UTC. A new release is published only if changes have been detected in thedocker/directory since the latest release. The version number is automatically incremented to the next minor or patch version based on changes to the components installed in the container image.OBI limitations and capabilities
mainWhen choosing between OBI and traditional SDK-based instrumentation, keep the following limitations in mind:
- Protocol Support: OBI instruments network protocols (HTTP/gRPC) only; it cannot instrument application-internal logic.
- Customization: Unlike SDK instrumentation, you cannot add custom spans or attributes.
- Telemetry Types: OBI generates traces and metrics, but it does not generate logs.
- Deployment: Requires a privileged container with access to the host kernel.
- Platform: Linux only.
Quick start with the OBI example
mainTo run the OBI demonstration, which automatically instruments 5 different language applications (Java, Go, Python, .NET, and Node.js), use Docker Compose. The setup requires a Linux host with kernel 5.8+ and Docker support for
privilegedcontainers andpid: "host".docker compose up --buildRun the Java OTLP JSON logging Kubernetes example
mainThis example demonstrates how to export application logs using OTLP logging within a Kubernetes environment. To run the full demonstration, follow these steps:
- Build the Docker image: Use the provided
build.shscript. - Deploy to Kubernetes: Apply the manifests located in the
k8s/directory usingkubectl apply -f k8s/(e.g., using a local cluster like k3d.sh). - Generate traffic: Execute the traffic generator script located at
../../../generate-traffic.shto produce logs. - View logs in Grafana:
- Access the Grafana instance at
http://127.0.0.1:3000. - Use credentials: User
admin/ Passwordadmin. - Navigate to the Explore tab.
- Select Loki as the data source to query the exported logs.
- Access the Grafana instance at
- Build the Docker image: Use the provided
Enable OBI (eBPF auto-instrumentation)
mainOpenTelemetry eBPF Instrumentation (OBI) uses eBPF to automatically generate traces and RED metrics for HTTP/gRPC services with zero code changes.
Requirements
- Linux kernel 5.8+ with BTF support.
- If running
docker rundirectly (instead of using the provided scripts), you must manually add the--pid=hostand--privilegedflags.
Enabling OBI
Add
ENABLE_OBI=trueto your.envfile or pass it as an environment variable.Targeting specific applications
By default, OBI monitors common ports (80, 443, 8080-8099, 3000-3999, 5000-5999). You can override this behavior using
OBI_TARGETorOTEL_EBPF_OPEN_PORT.Variable Purpose OBI_TARGETFriendly language target: java,python,node,dotnet,ruby, or any regular expressionOTEL_EBPF_OPEN_PORTOverride ports to monitor (native OBI environment variable) OTEL_EBPF_AUTO_TARGET_EXEExecutable name pattern (native OBI environment variable, set automatically by OBI_TARGET)# Monitor all Java processes ENABLE_OBI=true OBI_TARGET=java ./run-lgtm.sh # Monitor all Python processes ENABLE_OBI=true OBI_TARGET=python ./run-lgtm.sh # Monitor a specific executable by name ENABLE_OBI=true OBI_TARGET=myapp ./run-lgtm.sh # Monitor specific ports ENABLE_OBI=true OTEL_EBPF_OPEN_PORT=8080,9090 ./run-lgtm.sh # Using mise mise run lgtm-obiRun the Java example with a standalone Dockerfile
mainIf you want to run the instrumented Java application independently of the provided Docker Compose setup, build and run the image manually. You must provide OpenTelemetry environment variables to point the application to your OTLP collector endpoint.
- Build the image:
docker build -t java-rolldice .- Run the container:
On macOS or Windows (Docker Desktop): Use
host.docker.internalto resolve the host machine's network.docker run -p 8080:8080 \ -e OTEL_SERVICE_NAME=rolldice \ -e OTEL_EXPORTER_OTLP_ENDPOINT=http://host.docker.internal:4318 \ java-rolldiceOn Linux: You must manually add the
host.docker.internalmapping using--add-host.docker run -p 8080:8080 \ --add-host=host.docker.internal:host-gateway \ -e OTEL_SERVICE_NAME=rolldice \ -e OTEL_EXPORTER_OTLP_ENDPOINT=http://host.docker.internal:4318 \ java-rolldicedocker build -t java-rolldice . # macOS / Windows (Docker Desktop) docker run -p 8080:8080 \ -e OTEL_SERVICE_NAME=rolldice \ -e OTEL_EXPORTER_OTLP_ENDPOINT=http://host.docker.internal:4318 \ java-rolldiceGet the Docker image
mainThe
grafana/otel-lgtmDocker image is available on Docker Hub. You can pull the latest version using the following command:docker pull grafana/otel-lgtm:latestIntegrate with AI tools via MCP
mainThe stack supports Model Context Protocol (MCP) integration, allowing AI coding tools to query logs, metrics, traces, and dashboards.
Enable Tempo MCP
To enable the Tempo MCP server, set the
TEMPO_EXTRA_ARGSenvironment variable to include--query-frontend.mcp-server.enabled=truewhen running the container.Retrieve MCP Configuration
After starting the container, retrieve the MCP configuration JSON by executing
cat /etc/lgtm/mcp.jsoninside the container. You can then paste this JSON into your AI tool's MCP configuration.Note: Traces can also be queried via the client-side Grafana MCP server using
uvx mcp-grafana.Configure Grafana MCP server in Claude Code
mainTo allow Claude Code to access Grafana data (Dashboards, PromQL, LogQL), you must provide a service account token and the Grafana URL. This requires
uvxto run themcp-grafanaprocess.- Extract the service account token from the running container.
- Use the
claude mcp addcommand to register the server.
# Get the service account token TOKEN=$(docker exec lgtm cat /tmp/grafana-sa-token) # Add the Grafana MCP server (requires uvx) claude mcp add grafana \ -e GRAFANA_URL=http://localhost:3000 \ -e GRAFANA_SERVICE_ACCOUNT_TOKEN="$TOKEN" \ -- uvx mcp-grafanaSet up the Tempo MCP server
mainTo enable the Tempo MCP server inside the container, add the following environment variable to your
.envfile before starting the container:TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=trueThen start the container using the provided script:
./run-lgtm.shecho 'TEMPO_EXTRA_ARGS=--query-frontend.mcp-server.enabled=true' >> .env ./run-lgtm.shRun the Java JSON logging with Logback Kubernetes example
mainThis example demonstrates how to export application logs using JSON logging in a Kubernetes environment. To run the full demonstration, follow these steps:
- Build the Docker image: Execute the
build.shscript. - Deploy to Kubernetes: Apply the manifests located in the
k8s/directory usingkubectl apply -f k8s/(e.g., using k3d.sh). - Generate traffic: Run the traffic generator using
../../../generate-traffic.shto produce logs. - Access Grafana: Log in to
http://127.0.0.1:3000using the credentials:- User:
admin - Password:
admin
- User:
- View Logs: Navigate to the Explore tab and select Loki as the data source to view the JSON-formatted logs.
- Build the Docker image: Execute the