Skip to content

Commit

Permalink
Add Baggage example for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
bm1549 committed Nov 19, 2024
1 parent 3de6a8b commit 0a8cc0d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,38 @@ except TypeError as e:

You can configure the propagation of context for distributed traces by injecting and extracting headers. Read [Trace Context Propagation][2] for information.

### Baggage

Manipulating [Baggage][3] on a span:

```python
from ddtrace import tracer

# Start a new span and set baggage
with tracer.trace("example") as span:
# set_baggage_item
span.context.set_baggage_item("key1", "value1")
span.context.set_baggage_item("key2", "value2")

# get_all_baggage_items
all_baggage = span.context.get_all_baggage_items()
print(all_baggage) # {'key1': 'value1', 'key2': 'value2'}

# remove_baggage_item
span.context.remove_baggage_item("key1")
print(span.context.get_all_baggage_items()) # {'key2': 'value2'}

# get_baggage_item
print(span.context.get_baggage_item("key1")) # None
print(span.context.get_baggage_item("key2")) # value2

# remove_all_baggage_items
span.context.remove_all_baggage_items()
print(span.context.get_all_baggage_items()) # {}
```

To see an example in action, see [flask-baggage on trace-examples][7]

## Resource filtering

Traces can be excluded based on their resource name, to remove synthetic traffic such as health checks from reporting traces to Datadog. This and other security and fine-tuning configurations can be found on the [Security][4] page or in [Ignoring Unwanted Resources][5].
Expand All @@ -241,6 +273,8 @@ Traces can be excluded based on their resource name, to remove synthetic traffic

[1]: /tracing/compatibility_requirements/python
[2]: /tracing/trace_collection/trace_context_propagation/
[3]: /tracing/trace_collection/trace_context_propagation/#baggage
[4]: /tracing/security
[5]: /tracing/guide/ignoring_apm_resources/
[6]: /tracing/setup/python/
[7]: https://github.com/DataDog/trace-examples/tree/baggage/python/flask-baggage
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ In addition to the environment variable configuration, you can also update the p

The Datadog Python SDK supports the following trace context formats, including deprecated configuration values:

| Format | Configuration Value |
|------------------------|---------------------|
| [Datadog][1] | `datadog` |
| [W3C Trace Context][2] | `tracecontext` |
| [B3 Single][3] | `b3` |
| [B3 Multi][4] | `b3multi` |
| [None][5] | `none` |
| Format | Configuration Value |
|------------------------|---------------------------------|
| [Datadog][1] | `datadog` |
| [W3C Trace Context][2] | `tracecontext` |
| [B3 Single][3] | `b3` |
| | `b3 single header` (deprecated) |
| [B3 Multi][4] | `b3multi` |
| [None][5] | `none` |

[1]: #datadog-format
[2]: https://www.w3.org/TR/trace-context/
Expand Down Expand Up @@ -625,9 +626,11 @@ When the Datadog SDK is configured with the Datadog format for extraction or inj

When the Datadog SDK is configured with the None format for extraction or injection (possibly both), the Datadog SDK does _not_ interact with request headers, meaning that the corresponding context propagation operation does nothing.

### Baggage format
### Baggage

_Currently available in Python and Node.js. For other languages, please reach out to [Support][11]_

Baggage propagation through OpenTelemetry's W3C-compatible headers is enabled by default.
By default, Baggage is automatically propagated through a distributed request using OpenTelemetry's [W3C-compatible headers][10].

## Further reading

Expand All @@ -643,3 +646,4 @@ Baggage propagation through OpenTelemetry's W3C-compatible headers is enabled by
[8]: /synthetics/platform/apm
[9]: /opentelemetry/interoperability/environment_variable_support
[10]: https://www.w3.org/TR/baggage/
[11]: /help

0 comments on commit 0a8cc0d

Please sign in to comment.