# Baggage vs span attributes

> OpenTelemetry baggage vs attributes, with an agent ID as the example: what travels to other services, what lands on spans, and what to keep private.

Source: https://hashspan.dev/learn/otel-baggage

By Selim Aytaç, maintainer · Published Oct 1, 2026 · Updated Oct 19, 2026

## Short answer

Baggage is a set of key-value pairs carried in the context and sent to downstream services, by default in a W3C baggage header. Span attributes are stored on one span and exported with it. Baggage doesn't become an attribute by itself: something has to read it and copy it onto the span.

You want every span in an agent run to say which agent it was. You set `gen_ai.agent.id` in baggage, and the spans still don't show it. Meanwhile, the ID went out in the [headers](https://hashspan.dev/learn/otel-context-propagation) of every outgoing request.

Figure: OpenTelemetry baggage holding an agent ID is sent downstream in the baggage header automatically, but reaches a span attribute only when code copies it.

## Where does each one go?

| Aspect | Baggage | Span attribute |
|---|---|---|
| Lives in | The context | One span |
| Crosses process boundaries | Yes, as a `baggage` header | No |
| Exported to your backend | Only if copied onto a span | Yes |
| Typical use | Pass a value to code you don't control | Describe the operation |

The [baggage docs](https://opentelemetry.io/docs/concepts/signals/baggage/) say it plainly: baggage is a separate key-value store, unrelated to [span attributes](https://hashspan.dev/learn/otel-span-attributes) unless you add them explicitly.

## Both, side by side

```ts
import { context, propagation } from '@opentelemetry/api';

const bag = propagation.createBaggage({ 'gen_ai.agent.id': { value: 'run-7f3a' } });

context.with(propagation.setBaggage(context.active(), bag), () => {
  tracer.startSpan('send 8453').end(); // baggage is not copied to the span

  const headers: Record<string, string> = {};
  propagation.inject(context.active(), headers); // but it is sent downstream
  console.log(headers.baggage);

  const id = propagation.getBaggage(context.active())?.getEntry('gen_ai.agent.id')?.value;
  tracer.startSpan('send 8453', { attributes: { 'gen_ai.agent.id': id } }).end(); // copied by hand
});
```

```text
gen_ai.agent.id=run-7f3a
send 8453 {}
send 8453 { 'gen_ai.agent.id': 'run-7f3a' }
```

The first span has no attributes, yet the header carries the ID. The second span has it because the code copied it.

## Who can set your baggage?

Anyone who calls you. A service that accepts requests from outside reads whatever `baggage` header arrives. If your instrumentation trusts it, a caller can label its work with an agent ID of their choosing. Your own baggage, in turn, goes to every API your instrumented HTTP client calls.

Rule of thumb: baggage for values that are fine to share and fine to be spoofed, attributes for everything else.

**In a hashspan trace:**
hashspan records `gen_ai.agent.id` and `gen_ai.agent.name` on its `send`, `confirm` and `payment` spans. It reads them in this order:

  1. The tracker's static `agent` option. A field set there always wins and is never propagated.
  2. Baggage entries with the same keys, for fields the option leaves unset.

A per-run ID can travel in baggage while the service names its agent statically. Services that take requests from outside their trust boundary should set `agentFromBaggage: false` ([core options](https://hashspan.dev/docs/adapters/core)). With identity on the transaction spans, your backend can answer [which agent spent what](https://hashspan.dev/blog/agent-trace-stops-at-the-tool-call) without joining spans.

## FAQ

### What is baggage in OpenTelemetry?

A set of key-value pairs carried in the context and sent to downstream services, by default in a W3C baggage header. It is separate from span attributes.

### Does OpenTelemetry add baggage to spans automatically?

No. Baggage is a separate key-value store. Your code, or a baggage span processor, has to read the entries and set them as attributes.

### How is baggage propagated?

The W3C Baggage propagator writes it into a baggage header on outgoing requests, and the receiving service reads it back. NodeTracerProvider.register() installs that propagator by default.

### Is it safe to put user data in baggage?

Only if every service it reaches, including third-party APIs your instrumented HTTP client calls, may see it. Baggage leaves your process in plain headers.
