Docs » Analyze services with span tags » Add context to traces with span tags

Add context to traces with span tags 🔗

Create span tags that add metadata to traces you send to Splunk Observability Cloud. Span tags are field-value pairs that provide additional metadata about spans in a trace.

There are two ways to add span tags:

  1. Instrument your application to create span tags

  2. Add span tags to spans when you send trace data to a Splunk OpenTelemetry Collector

You can also instrument your application to define some span tags and manage other span tags with an OpenTelemetry Collector. This is useful if you deploy an OpenTelemetry Collector as a gateway to centrally manage data collection from multiple services.

Instrument your application to create span tags 🔗

How you instrument code to create span tags depends on your code’s language.

For more information about adding span tags at the instrumentation level, see resources for the language you are instrumenting:

Documentation

Instrumentation SDK

Instrument a Java application

Splunk distribution of OpenTelemetry Java

Instrument a Node.js application

SignalFx Tracing Library for JavaScript

Instrument a .NET application

SignalFx Tracing Library for .NET

Instrument a Python application

Splunk distribution of OpenTelemetry Python

Instrument a Ruby application

SignalFx Tracing Library for Ruby

Instrument a PHP application

SignalFx Tracing Library for PHP

Add span tags with an OpenTelemetry Collector 🔗

Include span tags in settings for the batch processor in your OpenTelemetry Collector configuration YAML file. You can create span tags with attributes/newenvironment which adds span tags to any spans that don’t already have the tags or with attributes/copyfromexistingkey which overrides an existing span tag value.

The settings look like this in an OpenTelemetry Collector configuration YAML file:

processors:
  # Override an existing tag for a span.
  attributes/copyfromexistingkey:
    actions:
    - key: SPAN_TAG_KEY
      from_attribute: "SPAN_TAG_VALUE"
      action: upsert
  # Add a tag to spans missing it.
  attributes/newenvironment:
    actions:
    - key: SPAN_TAG_KEY
      value: "SPAN_TAG_VALUE"
      action: insert

service:
  pipelines:
    traces:
      # Add the processor to your pipelines.
      processors: [batch]