[BUG] OTEL_RESOURCE_ATTRIBUTES not applied to metrics, only works for events
Status Fixed / completed
Reported on v2.0.76
Maintainer reply None cached
Activity 7 comments · opened Jan 7, 2026 · closed Mar 1, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The OTEL_RESOURCE_ATTRIBUTES environment variable is not being applied to metrics export. Resource attributes appear correctly in events under resource.attributes, but are completely missing from metrics dataPoints.attributes.
According to the OpenTelemetry specification, resource attributes should be attached to all telemetry signals (events, metrics, and traces), but Claude Code currently only applies them to events.
What Should Happen?
When OTEL_RESOURCE_ATTRIBUTES="user.name=test_user" is set in ~/.claude/settings.json, the attribute should appear in:
- ✅ Events:
resource.attributes - ✅ Metrics: Should be available in metric resource attributes
Error Messages/Logs
Example of event telemetry:
{
resource: {
attributes: {
'user.name': 'test_user',
'host.arch': 'arm64',
'os.type': 'darwin',
'os.version': '24.6.0',
'service.name': 'claude-code',
'service.version': '2.0.76'
}
},
instrumentationScope: {
name: 'com.anthropic.claude_code.events',
version: '2.0.76',
schemaUrl: undefined
},
timestamp: 1767745198782000,
traceId: undefined,
spanId: undefined,
traceFlags: undefined,
severityText: undefined,
severityNumber: undefined,
body: 'claude_code.api_request',
attributes: {
'user.id': '<id>',
'session.id': 'a55b3854-d623-41f1-a3eb-01b74684c363',
'terminal.type': 'Apple_Terminal',
'event.name': 'api_request',
'event.timestamp': '2026-01-07T00:19:58.782Z',
model: 'claude-sonnet-4-5-20250929',
input_tokens: '6',
output_tokens: '245',
cache_read_tokens: '45092',
cache_creation_tokens: '728',
cost_usd: '0.0199506',
duration_ms: '4958'
}
}
Example of metrics telemetry:
{
descriptor: {
name: 'claude_code.cost.usage',
type: 'COUNTER',
description: 'Cost of the Claude Code session',
unit: 'USD',
valueType: 1,
advice: {}
},
dataPointType: 3,
dataPoints: [
{
attributes: {
'user.id': '<user id>',
'session.id': '1d7a8638-c5e9-40d8-baf6-7f6d77dde198',
'terminal.type': 'Apple_Terminal',
model: 'us.anthropic.claude-sonnet-4-5-20250929-v1:0'
},
startTime: [ 1767743754, 82000000 ],
endTime: [ 1767743767, 106000000 ],
value: 0.17903220000000003
},
{
attributes: {
'user.id': '<user id>',
'session.id': '1d7a8638-c5e9-40d8-baf6-7f6d77dde198',
'terminal.type': 'Apple_Terminal',
model: 'us.anthropic.claude-3-5-haiku-20241022-v1:0'
},
startTime: [ 1767743754, 251000000 ],
endTime: [ 1767743767, 106000000 ],
value: 0.0046296
}
]
}
Steps to Reproduce
- Edit ~/.claude/settings.json:
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_RESOURCE_ATTRIBUTES": "user.name=test_user",
"OTEL_LOGS_EXPORTER": "otlp,console",
"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "<some endpoint>",
"OTEL_EXPORTER_OTLP_HEADERS": "<some header>",
"OTEL_METRICS_EXPORTER": "otlp,console",
"OTEL_EXPORTER_OTLP_METRICS_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT": "<some endpoint>"
}
}
- Restart Claude Code
- Observe console output for both events and metrics
- Notice that user.name appears in events' resource.attributes but is missing from metrics' dataPoints.attributes
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.76
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
7 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
My issue is not a duplicate.
For suggested issues:
Hi !
This also applies to GCP and Claude Code 2.1.7
Claude Code Version
2.1.7
Platform
GCP Vertex
Operating System
macOS
Terminal/Shell
iterm.app (macOS)
metrics: only
target_infocontainsOTEL_RESOURCE_ATTRIBUTESversion: 2.1.25
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
why closing this issue. OTEL_RESOURCE_ATTRIBUTES does not work on sending additional telemetry metrics.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.