Skip to content

Commit c09ef1f

Browse files
authored
docs: add opentelemetry mapping (#7579)
The OpenTelemetry API support implements a mapping from OpenTelemetry to Datadog spans. The documentation changes here are to represent the mapping, specifically for attributes to tags. Preview: <img width="846" alt="image" src="https://github.com/DataDog/dd-trace-py/assets/155673/6534eb7c-f350-45ba-ac2e-5bcd04f1a4ec"> ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) - [x] If this PR touches code that signs or publishes builds or packages, or handles credentials of any kind, I've requested a review from `@DataDog/security-design-and-guidance`. - [x] This PR doesn't touch any of that.
1 parent e38aad9 commit c09ef1f

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

ddtrace/opentelemetry/__init__.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=================
44
55
The dd-trace-py library provides an implementation of the
6-
`opentelemetry api <https://opentelemetry-python.readthedocs.io/en/latest/api/index.html>`_.
6+
`OpenTelemetry API <https://opentelemetry-python.readthedocs.io/en/latest/api/index.html>`_.
77
When ddtrace OpenTelemetry support is configured, all operations defined in the
88
OpenTelemetry trace api can be used to create, configure, and propagate a distributed trace.
99
All operations defined the opentelemetry trace api are configured to use the ddtrace global tracer (``ddtrace.tracer``)
@@ -51,7 +51,61 @@
5151
@oteltracer.start_as_current_span("span_name")
5252
def some_function():
5353
pass
54-
"""
54+
55+
56+
Mapping
57+
-------
58+
59+
The OpenTelemetry API support implementation maps OpenTelemetry spans to Datadog spans. This mapping is described by the following table, using the protocol buffer field names used in `OpenTelemetry <https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/trace/v1/trace.proto#L80>`_ and `Datadog <https://github.com/DataDog/datadog-agent/blob/dc4958d9bf9f0e286a0854569012a3bd3e33e968/pkg/proto/datadog/trace/span.proto#L7>`_.
60+
61+
62+
.. list-table::
63+
:header-rows: 1
64+
:widths: 30, 30, 40
65+
66+
* - OpenTelemetry
67+
- Datadog
68+
- Description
69+
* - ``trace_id``
70+
- ``traceID``
71+
-
72+
* - ``span_id``
73+
- ``spanID``
74+
-
75+
* - ``trace_state``
76+
- ``meta["_sampling_priority_v1"]``, ``meta["_dd.origin"]``, ...
77+
- Datadog vendor-specific data is set in trace state using the ``dd=`` prefix
78+
* - ``parent_span_id``
79+
- ``parentID``
80+
-
81+
* - ``name``
82+
- ``name``
83+
-
84+
* - ``kind``
85+
- ``meta["span.kind"]``
86+
-
87+
* - ``start_time_unix_nano``
88+
- ``start``
89+
-
90+
* - ``end_time_unix_nano``
91+
- ``duration``
92+
- Derived from start and end time
93+
* - ``attributes[<key>]``
94+
- ``meta[<key>]``
95+
- Datadog tags (``meta``) are set for each OpenTelemetry attribute
96+
* - ``links[]``
97+
- ``meta["_dd.span_links"]``
98+
-
99+
* - ``status``
100+
- ``error``
101+
- Derived from status
102+
* - ``events[]``
103+
- N/A
104+
- Span events not supported on the Datadog platform
105+
106+
107+
""" # noqa: E501
108+
55109
from ._trace import TracerProvider
56110

57111

ddtrace/opentelemetry/_span.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030

3131

3232
class Span(OtelSpan):
33-
"""Initializes an Open Telemetry compatible shim for a datadog span"""
33+
"""Initializes an OpenTelemetry compatible shim for a Datadog span
34+
35+
TODO: Add mapping table from otel to datadog
36+
"""
3437

3538
_RECORD_EXCEPTION_KEY = "_dd.otel.record_exception"
3639
_SET_EXCEPTION_STATUS_KEY = "_dd.otel.set_status_on_exception"
@@ -140,8 +143,9 @@ def update_name(self, name):
140143
"""Updates the name of a span"""
141144
if not self.is_recording():
142145
return
143-
# Open Telemetry spans have one name while Datadog spans can have two different names (operation and resource).
144-
# Ensure the resource and operation names are equal for Open Telemetry spans
146+
# OpenTelemetry spans have one name while Datadog spans can have two different names (operation and resource).
147+
# Ensure the resource and operation names are equal for OpenTelemetry spans
148+
#
145149
self._ddspan.name = name
146150
self._ddspan.resource = name
147151

ddtrace/opentelemetry/_trace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_tracer(
5757

5858

5959
class Tracer(OtelTracer):
60-
"""Starts and/or activates Open Telemetry compatible Spans using the global Datadog Tracer."""
60+
"""Starts and/or activates OpenTelemetry compatible Spans using the global Datadog Tracer."""
6161

6262
def __init__(self, datadog_tracer):
6363
# type: (DDTracer) -> None

0 commit comments

Comments
 (0)