Tags are key-value pairs attached to spans. They let you filter, group, and search traces in the Datadog UI. This guide covers how to add tags at the span level, in bulk, and globally across all spans.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/datadog/dd-trace-js/llms.txt
Use this file to discover all available pages before exploring further.
Adding tags to a span
Usespan.setTag(key, value) to add a single tag to a span:
Adding multiple tags at once
Usespan.addTags(object) to set multiple tags in a single call:
Tagging spans from integrations
For spans created automatically by integrations, use span hooks to add custom tags without modifying the integration:Tagging the active span
When you need to tag a span created by an integration (e.g., inside a route handler), access it from the current scope:Global tags
Global tags are applied to every span produced by the tracer. Use them for environment-level metadata likeservice, env, and version.
- Environment variables
- Programmatic
The most common approach for Datadog unified service tagging:Add arbitrary tags with
DD_TAGS (comma-separated key:value pairs):Service, env, and version tags
These three tags are the foundation of Datadog unified service tagging. Set them consistently across your services to enable filtering in APM, logs, and infrastructure views.| Tag | Environment variable | Init option | Description |
|---|---|---|---|
service | DD_SERVICE | service | Name of your service. Inferred from package.json if not set. |
env | DD_ENV | env | Deployment environment (e.g., production, staging). |
version | DD_VERSION | version | Application version. Inferred from package.json if not set. |
Resource naming
The resource name identifies the specific operation within a span. For web requests this is usually the route pattern. Set it usingtracer.trace options or by tagging the span directly:
Tag naming best practices
- Use dot-separated namespaces to group related tags:
user.id,user.role,order.id,order.status. - Use lowercase letters, digits, underscores, and dots. Avoid spaces and special characters.
- Keep tag values concise and low-cardinality when possible (e.g., avoid using raw SQL or full URLs as tag values).
- Reserve high-cardinality identifiers (UUIDs, user IDs, order IDs) for tags that you specifically need to filter by — high cardinality can increase costs.
- Follow the Datadog tagging documentation for reserved tag names and naming conventions.
Nested objects as tag values are not supported. When adding an object as a tag value, only its direct (own) properties are included. If you need nested properties, add them individually:
