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?
14 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
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_uuidattribute, which provides the end-user-level granularity you're looking for. Key metrics available includeclaude_code.cost.usageandclaude_code.token.usage.Here’s how to get started:
``
bash
``export CLAUDE_CODE_ENABLE_TELEMETRY=1
```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
```
``
bash
``export OTEL_EXPORTER_OTLP_PROTOCOL=grpc
export OTEL_EXPORTER_OTLP_ENDPOINT=http://your-collector-address:4317
``
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
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
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:
storage:logs:write(for events/logs)storage:metrics:write(for metrics)```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:
Authorizationheader needs to be in the formatApi-Token <token>.OTEL_RESOURCE_ATTRIBUTESvariable 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
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.
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 (likehost.name) differently from custom ones (liketeam.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_ATTRIBUTESstring. 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-AIis syntactically correct. The problem is that Dynatrace likely mapshost.nameto its core "Host" entity property, whileteam.idis treated as a generic metadata attribute.2. Where to Find Your Custom Attributes in Dynatrace
Your custom attributes like
team.idmight 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:fetch logs | filter team.id == "GEN-AI"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.nameand your customteam.idare sent in the correct format.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:
``
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.idattribute 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.idattribute 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
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.
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.
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"_
Hi @coygeek can you please suggest?
This seems entirely unrelated to the ticket subject.
@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.
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.
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.