Request for End-User Usage Tracking for Claude Code on Vertex AI

Status Closed — not planned
Maintainer reply None cached
Activity 14 comments · opened Jul 22, 2025 · closed Jan 11, 2026

Hi,

I’d like to monitor the usage and cost of Claude Code for each team member. We are currently using Claude Code through Vertex AI.

Initially, we considered using LiteLLM for this purpose, but after discussions with their team, we learned that end-user tracking is not yet supported.

Could you please suggest how we can enable end-user-level usage tracking in GCP for Claude Code?

View original on GitHub ↗

14 Comments

github-actions[bot] · 1 year ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/2037
  2. https://github.com/anthropics/claude-code/issues/1325
  3. https://github.com/anthropics/claude-code/issues/1549

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

coygeek · 1 year ago

You can definitely monitor the usage and cost of Claude Code on a per-user basis when using it through Vertex AI. The recommended and most direct way to achieve this is by using Claude Code’s built-in support for OpenTelemetry (OTel).

Enable End-User Tracking with OpenTelemetry (Recommended)

Claude Code can export detailed metrics and events that include user-specific identifiers, allowing you to track usage and costs for each team member.

All metrics and events include a user.account_uuid attribute, which provides the end-user-level granularity you're looking for. Key metrics available include claude_code.cost.usage and claude_code.token.usage.

Here’s how to get started:

  1. Enable Telemetry: Set the following environment variable to turn on OTel exporting:

``bash
export CLAUDE_CODE_ENABLE_TELEMETRY=1
``

  1. Configure Exporters: Choose where to send your data. You can export metrics, events (logs), or both.

```bash
# For metrics (e.g., cost, token counts)
export OTEL_METRICS_EXPORTER=otlp

# For events (e.g., user prompts, tool usage)
export OTEL_LOGS_EXPORTER=otlp
```

  1. Set Up Your OTLP Endpoint: Point Claude Code to your OpenTelemetry collector.

``bash
export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://your-collector-address:4317
``

  1. Add Custom Attributes for Teams (Optional): For even more detailed tracking, you can add custom resource attributes to segment usage by team, department, or cost center.

``bash
export OTEL_RESOURCE_ATTRIBUTES="department=engineering,team.id=platform_team"
``
These attributes will be included in all exported metrics and events.

For a complete guide on configuration, available metrics, and backend setup, please see our documentation on Monitoring with OpenTelemetry.

Using an LLM Gateway (Alternative)

Regarding your note about LiteLLM, our documentation mentions that it can be used to track spend by key, which is a common pattern for per-user tracking. While OpenTelemetry is the natively supported solution, using an LLM Gateway is also a valid approach for centralizing monitoring and control. You can find more details in our LLM Gateway Configuration guide.

We recommend starting with the native OpenTelemetry integration as it provides rich, structured data specifically designed for monitoring Claude Code.

Let us know if you have any other questions

vishalsolanki-AZ · 1 year ago

Thanks @coygeek this is working for me.
Do u know if we can use Dynatrace directly something like below as we are already using Dynatrace for out other applications.

export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT=https://<YOUR_DYNATRACE_ENV>/api/v2/otlp

coygeek · 1 year ago

That's great to hear it's working for you! And yes, that's an excellent question. You can absolutely send Claude Code's OpenTelemetry data directly to your Dynatrace environment. Since Claude Code uses the standard OTLP (OpenTelemetry Protocol), it's compatible with any backend that supports it, including Dynatrace.

Your configuration is very close. The main things to add are your specific Dynatrace environment URL and an authentication token.

Here is the corrected configuration you can use:

  1. Generate a Dynatrace API Token: You'll need to create an API token in your Dynatrace account. Ensure it has the necessary permissions for ingesting OTLP data, which are typically:
  • storage:logs:write (for events/logs)
  • storage:metrics:write (for metrics)
  1. Set Your Environment Variables: Use the API token you just created and your Dynatrace endpoint to set the following variables:

```bash
# Enable Telemetry
export CLAUDE_CODE_ENABLE_TELEMETRY=1

# Configure OTLP exporters for metrics and logs
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp

# Set your Dynatrace OTLP endpoint (replace {your-environment-id})
export OTEL_EXPORTER_OTLP_ENDPOINT=https://{your-environment-id}.live.dynatrace.com/api/v2/otlp

# Set the authentication header (replace {your-dynatrace-api-token})
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Api-Token {your-dynatrace-api-token}"
```

A few key points:

  • The OTLP endpoint for Dynatrace SaaS is specific to your environment ID.
  • The Authorization header needs to be in the format Api-Token <token>.
  • You can still use the OTEL_RESOURCE_ATTRIBUTES variable to add custom metadata for team-level tracking, which will flow into Dynatrace as well.

Once you configure these variables, Claude Code will start sending its cost, usage, and event data directly into your existing Dynatrace setup, allowing you to monitor it alongside your other applications.

Hope this helps, and let me know if you run into any other questions

vishalsolanki-AZ · 12 months ago

Hi @coygeek Thanks I have logs and metrics in my dynatrace now but the problem is "OTEL_RESOURCE_ATTRIBUTES" is not being captured except host.name.

I have tried dfferent variations like this.

Add custom attributes for team identification as per tutorial.

export OTEL_RESOURCE_ATTRIBUTES="department=engineering,team.id=platform,cost_center=eng-123"

current m trying to capture below details.
export OTEL_RESOURCE_ATTRIBUTES="host.name=Vishal.Solanki,team.id=GEN-AI"

I m having host.name but unable to have team.id , tried different variations.

coygeek · 12 months ago

Thanks for the follow-up. This is a great question and a common scenario when integrating OpenTelemetry with specific platforms like Dynatrace. It's fantastic that you have the logs and metrics flowing in!

The issue you're encountering is almost certainly due to how Dynatrace processes and maps incoming OpenTelemetry resource attributes to its own entity model and metadata. While Claude Code sends all the attributes you define in OTEL_RESOURCE_ATTRIBUTES, Dynatrace might treat standard OTel semantic conventions (like host.name) differently from custom ones (like team.id).

Based on the official documentation and best practices for Dynatrace, here are the key things to check and the recommended solution:

1. Naming and Formatting are Crucial

The most likely issue is the formatting of the OTEL_RESOURCE_ATTRIBUTES string. As noted in the Claude Code documentation, this variable is very strict and doesn't allow for spaces around the commas or equal signs.

Your example host.name=Vishal.Solanki,team.id=GEN-AI is syntactically correct. The problem is that Dynatrace likely maps host.name to its core "Host" entity property, while team.id is treated as a generic metadata attribute.

2. Where to Find Your Custom Attributes in Dynatrace

Your custom attributes like team.id might not appear on the main Host entity overview page. Instead, they are attached to the individual metrics and log records themselves. You should be able to use them for filtering and splitting in tools like:

  • Logs and Events: When you query your logs, you should be able to filter by your custom attribute. For example: fetch logs | filter team.id == "GEN-AI"
  • Notebooks and Dashboards: You can use these attributes to build visualizations and segment your data by team.

Recommended Solution: Ensure Correct Formatting and Query in the Right Place

Let's refine your configuration slightly to ensure maximum compatibility and then confirm where to look for the data in Dynatrace.

Step 1: Finalize Your Environment Variables

This configuration ensures that both the standard host.name and your custom team.id are sent in the correct format.

# In your terminal where you run Claude Code:
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export OTEL_METRICS_EXPORTER=otlp
export OTEL_LOGS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_ENDPOINT="https://{your-environment-id}.live.dynatrace.com/api/v2/otlp"
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Api-Token {your-dynatrace-api-token}"

# Correctly formatted custom attributes for Dynatrace
# Note: No spaces around '=' or ',', comma-separated key=value pairs.
export OTEL_RESOURCE_ATTRIBUTES="host.name=Vishal.Solanki,team.id=GEN-AI,cost.center=gen-ai-research"
Step 2: Verify in Dynatrace Logs and Events

After running Claude Code with the variables above, go to your Dynatrace environment and do the following:

  1. Navigate to Logs and Events.
  2. Use a DQL (Dynatrace Query Language) query to find the events from Claude Code and check for your attribute. You can start broad and then narrow down.

``dql
// See all attributes for Claude Code logs
fetch logs, from: now()-1h
| filter contains(content, "claude_code")
| fields team.id, host.name, content
``

You should see your team.id attribute appear as a column in the results. If it's there, you can then use it to create dashboards, alerts, and cost-tracking metrics.

If the team.id attribute appears in your DQL query results, then the data is being ingested correctly, and you can now use it to build your team-specific usage and cost reports within Dynatrace.

Give that a try, especially focusing on querying for the attribute directly in the Logs and Events viewer. Let me know how it goes

JGrubb · 10 months ago

The gap here for me is that I ultimately want to be able to attribute costs on a per-user basis, and this requires a fair bit of setup and data wrangling vs. just being able to pass along some custom labels with the Vertex API call per this GCP doc.

Everything that I need magically works if I can pass custom labels along via an environment variable that we set per-user.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

vishalsolanki-AZ · 8 months ago

Hi @coygeek,
Claude Code is working well, and we now have ~300 users actively using it.

We’re trying to track usage in Dynatrace, and the only challenge we’re facing is that when users are on VPN, they need to manually set the certificate variable. However, the self-signed certificates already exist on the system.

Is there a way to make Claude Code automatically use the available system certificate instead of requiring users to manually set:

_export SSL_CERT_FILE="/Users/vsolanki/AutoZone_Root_CA_01.pem"_

vishalsolanki-AZ · 8 months ago

Hi @coygeek can you please suggest?

JGrubb · 8 months ago
Hi @coygeek, Claude Code is working well, and we now have ~300 users actively using it. We’re trying to track usage in Dynatrace, and the only challenge we’re facing is that when users are on VPN, they need to manually set the certificate variable. However, the self-signed certificates already exist on the system. Is there a way to make Claude Code automatically use the available system certificate instead of requiring users to manually set: _export SSL_CERT_FILE="/Users/vsolanki/AutoZone_Root_CA_01.pem"_

This seems entirely unrelated to the ticket subject.

vishalsolanki-AZ · 8 months ago

@JGrubb
The current setup allows us to successfully track users while we consume Claude Code through Vertex AI, and the solution shared above helped us achieve that.

Just to clarify why this is inline:

We’re using OpenTelemetry for tracking, and it sends logs to Dynatrace once the required variables are set.

However, when users are on VPN, we need to set an additional certificate-related variable because Claude Code is unable to automatically use the existing system certificates. This becomes a bottleneck in completing the end-to-end process for which this ticket was created.

github-actions[bot] · 7 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 7 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.