Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b823a1

Browse files
authored
docs: update datadog docs (open-telemetry#803)
Update the Datadog docs for installation and using propagation.
1 parent 74f2159 commit 0b823a1

File tree

5 files changed

+84
-5
lines changed

5 files changed

+84
-5
lines changed

docs/examples/datadog_exporter/README.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ Basic Example
3232

3333
.. code-block:: sh
3434
35-
python datadog_exporter.py
35+
python basic_example.py
3636
37-
Auto-Instrumention Example
38-
--------------------------
37+
38+
.. code-block:: sh
39+
40+
python basic_example.py
41+
42+
Distributed Example
43+
-------------------
3944

4045
* Installation
4146

@@ -79,3 +84,12 @@ Auto-Instrumention Example
7984
.. code-block:: sh
8085
8186
opentelemetry-instrument python client.py error
87+
88+
* Run Datadog instrumented client
89+
90+
The OpenTelemetry instrumented server is set up with propagation of Datadog trace context.
91+
92+
.. code-block:: sh
93+
94+
pip install ddtrace
95+
ddtrace-run python datadog_client.py testing

docs/examples/datadog_exporter/datadog_exporter.py renamed to docs/examples/datadog_exporter/basic_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
span_processor = DatadogExportSpanProcessor(exporter)
3232
trace.get_tracer_provider().add_span_processor(span_processor)
3333

34+
3435
with tracer.start_as_current_span("foo"):
3536
with tracer.start_as_current_span("bar"):
3637
with tracer.start_as_current_span("baz"):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from sys import argv
16+
17+
import requests
18+
19+
requested = requests.get(
20+
"http://localhost:8082/server_request", params={"param": argv[1]}
21+
)
22+
assert requested.status_code == 200
23+
print(requested.text)

docs/examples/datadog_exporter/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
from flask import Flask, request
1616

17-
from opentelemetry import trace
17+
from opentelemetry import propagators, trace
1818
from opentelemetry.ext.datadog import (
1919
DatadogExportSpanProcessor,
2020
DatadogSpanExporter,
2121
)
22+
from opentelemetry.ext.datadog.propagator import DatadogFormat
2223
from opentelemetry.sdk.trace import TracerProvider
2324

2425
app = Flask(__name__)
@@ -33,6 +34,21 @@
3334
)
3435
)
3536

37+
# append Datadog format for propagation to and from Datadog instrumented services
38+
global_httptextformat = propagators.get_global_httptextformat()
39+
if isinstance(
40+
global_httptextformat, propagators.composite.CompositeHTTPPropagator
41+
) and not any(
42+
isinstance(p, DatadogFormat) for p in global_httptextformat._propagators
43+
):
44+
propagators.set_global_httptextformat(
45+
propagators.composite.CompositeHTTPPropagator(
46+
global_httptextformat._propagators + [DatadogFormat()]
47+
)
48+
)
49+
else:
50+
propagators.set_global_httptextformat(DatadogFormat())
51+
3652
tracer = trace.get_tracer(__name__)
3753

3854

ext/opentelemetry-ext-datadog/src/opentelemetry/ext/datadog/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616
The **OpenTelemetry Datadog Exporter** provides a span exporter from
1717
`OpenTelemetry`_ traces to `Datadog`_ by using the Datadog Agent.
1818
19+
Installation
20+
------------
21+
22+
::
23+
24+
pip install opentelemetry-ext-datadog
25+
26+
1927
Usage
2028
-----
2129
30+
The Datadog exporter provides a span processor that must be added along with the
31+
exporter. In addition, a formatter is provided to handle propagation of trace
32+
context between OpenTelemetry-instrumented and Datadog-instrumented services in
33+
a distributed trace.
34+
2235
.. code:: python
2336
24-
from opentelemetry import trace
37+
from opentelemetry import propagators, trace
2538
from opentelemetry.ext.datadog import DatadogExportSpanProcessor, DatadogSpanExporter
39+
from opentelemetry.ext.datadog.propagator import DatadogFormat
2640
from opentelemetry.sdk.trace import TracerProvider
2741
2842
trace.set_tracer_provider(TracerProvider())
@@ -35,13 +49,24 @@
3549
span_processor = DatadogExportSpanProcessor(exporter)
3650
trace.get_tracer_provider().add_span_processor(span_processor)
3751
52+
# Optional: use Datadog format for propagation in distributed traces
53+
propagators.set_global_httptextformat(DatadogFormat())
54+
3855
with tracer.start_as_current_span("foo"):
3956
print("Hello world!")
4057
58+
59+
Examples
60+
--------
61+
62+
The `docs/examples/datadog_exporter`_ includes examples for using the Datadog
63+
exporter with OpenTelemetry instrumented applications.
64+
4165
API
4266
---
4367
.. _Datadog: https://www.datadoghq.com/
4468
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
69+
.. _docs/examples/datadog_exporter: https://github.com/open-telemetry/opentelemetry-python/tree/master/docs/examples/datadog_exporter
4570
"""
4671
# pylint: disable=import-error
4772

0 commit comments

Comments
 (0)