[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

  1. 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>"
    }
  }
  1. Restart Claude Code
  2. Observe console output for both events and metrics
  3. 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_

View original on GitHub ↗

7 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/10974
  2. https://github.com/anthropics/claude-code/issues/4338
  3. https://github.com/anthropics/claude-code/issues/10972

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

jongleecambia · 7 months ago

My issue is not a duplicate.

For suggested issues:

  • 10974 is a report on OTEL_RESOURCE_ATTRIBUTES not working at all. My issue is specifically for metrics.
  • 4338 is for OTEL_RESOURCE_ATTRIBUTES not applied to logs. Mine works for log metrics.
  • 10972 is for user.account_uuid and it's unrelated.
satyamagarwal · 7 months ago

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)

Example of event telemetry:

{
  resource: {
    attributes: {
      department: "<removed>",
      "team.id": "<removed>",
      "host.arch": "arm64",
      "os.type": "darwin",
      "os.version": "25.2.0",
      "service.name": "claude-code",
      "service.version": "2.1.7",
    },
  },
  instrumentationScope: {
    name: "com.anthropic.claude_code.events",
    version: "2.1.7",
    schemaUrl: undefined,
  },
  timestamp: 1768557417572000,
  traceId: undefined,
  spanId: undefined,
  traceFlags: undefined,
  severityText: undefined,
  severityNumber: undefined,
  body: "claude_code.user_prompt",
  attributes: {
    "user.id": "<removed>",
    "session.id": "<removed>",
    "app.version": "2.1.7",
    "terminal.type": "iTerm.app",
    "event.name": "user_prompt",
    "event.timestamp": "2026-01-16T09:56:57.572Z",
    prompt_length: "4",
    prompt: "<REDACTED>",
  },
}

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": "<removed>",
        "session.id": "<removed>",
        "app.version": "2.1.7",
        "terminal.type": "iTerm.app",
        model: "claude-haiku-4-5@20251001",
      },
      startTime: [ 1768557419, 260000000 ],
      endTime: [ 1768557420, 3000000 ],
      value: 0.0005679999999999999,
    }, {
      attributes: {
        "user.id": "<removed>",
        "session.id": "<removed>",
        "app.version": "2.1.7",
        "terminal.type": "iTerm.app",
        model: "claude-sonnet-4-5@20250929",
      },
      startTime: [ 1768557420, 1000000 ],
      endTime: [ 1768557420, 3000000 ],
      value: 0.07395900000000001,
    }
  ],
}
mchtech · 7 months ago

metrics: only target_info contains OTEL_RESOURCE_ATTRIBUTES
version: 2.1.25

github-actions[bot] · 6 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

clude · 6 months ago

why closing this issue. OTEL_RESOURCE_ATTRIBUTES does not work on sending additional telemetry metrics.

github-actions[bot] · 5 months ago

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.