@@ -263,6 +263,12 @@ MAX_REPO_SIZE_MB=500
263263QUERY_TIMEOUT=30
264264QUERY_CACHE_ENABLED=true
265265QUERY_CACHE_TTL=300
266+
267+ # Telemetry (OpenTelemetry)
268+ OTEL_ENABLED=false
269+ OTEL_SERVICE_NAME=codebadger
270+ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
271+ OTEL_EXPORTER_OTLP_PROTOCOL=grpc
266272```
267273
268274### Config File
@@ -275,6 +281,71 @@ cp config.example.yaml config.yaml
275281
276282Then customize as needed.
277283
284+ ## Telemetry (OpenTelemetry)
285+
286+ CodeBadger has built-in OpenTelemetry support for distributed tracing. When enabled, all MCP tool calls are automatically traced, plus custom spans for CPG generation, Joern server management, and query execution.
287+
288+ ### Quick Start
289+
290+ 1 . Install the telemetry dependencies (included in ` requirements.txt ` ):
291+
292+ ``` bash
293+ pip install opentelemetry-sdk opentelemetry-exporter-otlp
294+ ```
295+
296+ 2 . Enable via environment variables:
297+
298+ ``` bash
299+ export OTEL_ENABLED=true
300+ export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
301+ python main.py
302+ ```
303+
304+ Or via ` config.yaml ` :
305+
306+ ``` yaml
307+ telemetry :
308+ enabled : true
309+ service_name : codebadger
310+ otlp_endpoint : http://localhost:4317
311+ otlp_protocol : grpc # or "http/protobuf"
312+ ` ` `
313+
314+ ### Local Development with Jaeger
315+
316+ ` ` ` bash
317+ # Start Jaeger (provides UI at http://localhost:16686)
318+ docker run -d --name jaeger \
319+ -p 16686:16686 \
320+ -p 4317:4317 \
321+ jaegertracing/all-in-one:latest
322+
323+ # Start CodeBadger with telemetry
324+ OTEL_ENABLED=true python main.py
325+ ```
326+
327+ ### What Gets Traced
328+
329+ | Span | Description |
330+ | ------| -------------|
331+ | ` tools/call {name} ` | Every MCP tool invocation (automatic via FastMCP) |
332+ | ` cpg.generate ` | Full CPG generation pipeline |
333+ | ` cpg.joern_cli_exec ` | Joern CLI command execution inside Docker |
334+ | ` cpg.spawn_server ` | Joern server instance creation |
335+ | ` cpg.load_cpg ` | CPG file loading into Joern server |
336+ | ` query.execute ` | CPGQL query execution with timing and success attributes |
337+
338+ ### Configuration Reference
339+
340+ | Setting | Env Variable | Default | Description |
341+ | ---------| -------------| ---------| -------------|
342+ | ` enabled ` | ` OTEL_ENABLED ` | ` false ` | Enable/disable telemetry |
343+ | ` service_name ` | ` OTEL_SERVICE_NAME ` | ` codebadger ` | Service name in traces |
344+ | ` otlp_endpoint ` | ` OTEL_EXPORTER_OTLP_ENDPOINT ` | ` http://localhost:4317 ` | OTLP collector endpoint |
345+ | ` otlp_protocol ` | ` OTEL_EXPORTER_OTLP_PROTOCOL ` | ` grpc ` | Export protocol (` grpc ` or ` http/protobuf ` ) |
346+
347+ When telemetry is disabled (default), all tracing is no-op with zero overhead.
348+
278349
279350
280351
0 commit comments