Skip to content

Monitoring CodeBuddy Code with OpenTelemetry

CodeBuddy Code supports exporting traces to your own OpenTelemetry Collector via the standard OTLP protocol, making it easy to integrate with self-hosted observability platforms.

Current Scope: Supports traces (distributed tracing) + 4 privacy opt-in switches. Custom export of metrics and logs is not yet supported.

Quick Start

bash
# 1. Enable telemetry
export CODEBUDDY_CODE_ENABLE_TELEMETRY=1

# 2. Configure OTLP endpoint
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

# 3. (Optional) Enable privacy opt-in content recording
export OTEL_LOG_USER_PROMPTS=1
export OTEL_LOG_TOOL_DETAILS=1
export OTEL_LOG_TOOL_CONTENT=1

# 4. Run
codebuddy

Claude Code compatibility: CLAUDE_CODE_ENABLE_TELEMETRY is equivalent to CODEBUDDY_CODE_ENABLE_TELEMETRY.

Configuration Variables

Basic Configuration

VariablePurposeExample
CODEBUDDY_CODE_ENABLE_TELEMETRYEnable OTel export (required)1
OTEL_TRACES_EXPORTERExporter typeotlp (default), console, none
OTEL_EXPORTER_OTLP_ENDPOINTOTLP Collector address; /v1/traces is appended automaticallyhttp://localhost:4318
OTEL_EXPORTER_OTLP_TRACES_ENDPOINTFull URL specific to traces; takes higher priorityhttp://localhost:4318/v1/traces
OTEL_EXPORTER_OTLP_HEADERSRequest headers k1=v1,k2=v2; values support URL encodingAuthorization=Bearer%20token
OTEL_EXPORTER_OTLP_TRACES_PROTOCOLTransport protocolhttp/protobuf (only supported)
OTEL_SERVICE_NAMEOverride the default service.namecodebuddy-code
OTEL_RESOURCE_ATTRIBUTESAdditional resource attributesteam=platform,env=prod

Privacy Opt-in Switches

Spans do not record any sensitive information by default (prompt content, tool parameters, tool output, etc.). You need to opt in progressively via the following environment variables:

VariablePurposeRecorded Content
OTEL_LOG_USER_PROMPTS=1Record user promptsuser_prompt attribute (not recorded by default; only user_prompt_length is recorded)
OTEL_LOG_TOOL_DETAILS=1Record tool parameterstool_input attribute (~4KB truncation) + tool-specific attributes (file.path, command, etc.)
OTEL_LOG_TOOL_CONTENT=1Record full tool input/outputtool_input/tool_result span events (60KB truncation)
OTEL_LOG_RAW_API_BODIES=1Record full API request/response bodiesReserved, not yet implemented

Span Structure

Each user prompt produces a codebuddy_code.interaction root span. Tool calls are recorded as child spans:

codebuddy_code.interaction
├── codebuddy_code.tool (Read)
├── codebuddy_code.tool (Bash)
└── codebuddy_code.tool (Agent -> child agent tool spans)

Span Attributes

All spans include a span.type attribute to identify the type.

codebuddy_code.interaction

AttributeDescriptionControlled By
span.typeFixed value "interaction"
conversation.idConversation ID
conversation.agentAgent name
user_promptUser prompt content (not recorded when disabled)OTEL_LOG_USER_PROMPTS
user_prompt_lengthPrompt length (always recorded)
conversation.cancelledtrue when conversation is cancelled

codebuddy_code.tool

AttributeDescriptionControlled By
span.typeFixed value "tool"
tool_nameTool name
tool.call_idTool call ID (always recorded)
file.pathFile path (Read/Write/Edit)OTEL_LOG_TOOL_DETAILS
commandBash commandOTEL_LOG_TOOL_DETAILS
command.timeoutCommand timeout (milliseconds)OTEL_LOG_TOOL_DETAILS
glob.patternGlob search patternOTEL_LOG_TOOL_DETAILS
grep.patternGrep regex patternOTEL_LOG_TOOL_DETAILS
http.urlWebFetch URLOTEL_LOG_TOOL_DETAILS
search.queryWebSearch queryOTEL_LOG_TOOL_DETAILS
agent.promptSub-agent promptOTEL_LOG_TOOL_DETAILS
agent.typeSub-agent typeOTEL_LOG_TOOL_DETAILS
mcp.serverMCP server nameOTEL_LOG_TOOL_DETAILS
mcp.toolMCP tool nameOTEL_LOG_TOOL_DETAILS
tool_inputTool input JSON (~4KB truncation)OTEL_LOG_TOOL_DETAILS
tool_input_truncatedWhether input was truncatedOTEL_LOG_TOOL_DETAILS
tool_input_original_lengthOriginal length before truncationOTEL_LOG_TOOL_DETAILS

codebuddy_code.tool span events (requires OTEL_LOG_TOOL_CONTENT=1)

Event NameAttributeDescription
tool_inputcontentFull tool input (60KB truncation)
tool_inputcontent_truncatedWhether truncated
tool_inputcontent_original_lengthLength before truncation
tool_resultcontentFull tool output (60KB truncation)
tool_resultcontent_truncatedWhether truncated
tool_resultcontent_original_lengthLength before truncation

Typical Scenarios

Export to a Self-Hosted Enterprise Collector

bash
export CODEBUDDY_CODE_ENABLE_TELEMETRY=1
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.corp.example.com
export OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20<TOKEN>
export OTEL_SERVICE_NAME=codebuddy-code
export OTEL_RESOURCE_ATTRIBUTES=deployment.environment=prod,team=copilot

Local Debugging (Console Output)

bash
export CODEBUDDY_CODE_ENABLE_TELEMETRY=1
export OTEL_TRACES_EXPORTER=console
export OTEL_LOG_USER_PROMPTS=1
export OTEL_LOG_TOOL_DETAILS=1
export OTEL_LOG_TOOL_CONTENT=1

Disable Telemetry

bash
export OTEL_TRACES_EXPORTER=none
# Or globally disable:
export DISABLE_TELEMETRY=1

Priority and Fallback

  1. DISABLE_TELEMETRY=1 has the highest priority and disables all telemetry.
  2. Enable evaluation: enabled in the built-in product configuration or CODEBUDDY_CODE_ENABLE_TELEMETRY / CLAUDE_CODE_ENABLE_TELEMETRY is set to a truthy value (1 / true / yes / on).
  3. Endpoint priority: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT > OTEL_EXPORTER_OTLP_ENDPOINT > telemetry.tracing.url in the built-in product configuration.
  4. Headers: env and product configuration are merged; env keys with the same name override product configuration.

Protocol Support

Only http/protobuf (OTLP/HTTP + Protobuf encoding) is supported, consistent with the Claude Code default.

Setting OTEL_EXPORTER_OTLP_PROTOCOL=grpc or http/json will be ignored with a warning logged, falling back to the default protobuf.

Security and Privacy

  • Spans only record tool names and call IDs by default, excluding user prompts, tool parameters, file content, or source code
  • user_prompt_length is always recorded (length only); prompt text requires OTEL_LOG_USER_PROMPTS=1 to be written
  • Tool parameters (file paths, commands, etc.) require OTEL_LOG_TOOL_DETAILS=1; individual values exceeding 512 characters are truncated, with a total limit of ~4KB
  • Full tool input/output requires OTEL_LOG_TOOL_CONTENT=1, recorded via span events, truncated at 60KB
  • All opt-in switches are disabled by default; enterprise administrators can configure them uniformly via managed settings

FAQ

Does it conflict with the internal enterprise reporting channel?

No conflict. OTel custom export and the built-in standard reporting (telemetry.report.standard) are two independent channels and can be enabled simultaneously.

Is metrics / logs supported?

Not yet supported, but planned. If you have a strong need, please provide feedback on the corresponding Issue.

Is it compatible with Claude Code's OTEL format?

Yes. Span naming, attribute naming, and truncation strategies are aligned with Claude Code's conventions ({product}.interaction / {product}.tool), ensuring upstream analysis platforms can process them uniformly.