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

Skip to content

Commit f1a7feb

Browse files
Add exporter to Datadog (open-telemetry#572)
Add an exporter to Datadog. This implementation makes use of ddtrace to handle the creation of Datadog traces and writing them to the Datadog agent. Co-Authored-By: Mauricio Vásquez <[email protected]>
1 parent 8d09319 commit f1a7feb

File tree

18 files changed

+1242
-0
lines changed

18 files changed

+1242
-0
lines changed

docs-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ sphinx-rtd-theme~=0.4
33
sphinx-autodoc-typehints~=1.10.2
44

55
# Required by ext packages
6+
ddtrace>=0.34.0
67
aiohttp ~= 3.0
78
Deprecated>=1.2.6
89
django>=2.2
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Datadog Exporter Example
2+
========================
3+
4+
These examples show how to use OpenTelemetry to send tracing data to Datadog.
5+
6+
7+
Basic Example
8+
-------------
9+
10+
* Installation
11+
12+
.. code-block:: sh
13+
14+
pip install opentelemetry-api
15+
pip install opentelemetry-sdk
16+
pip install opentelemetry-ext-datadog
17+
18+
* Start Datadog Agent
19+
20+
.. code-block:: sh
21+
22+
docker run --rm \
23+
-v /var/run/docker.sock:/var/run/docker.sock:ro \
24+
-v /proc/:/host/proc/:ro \
25+
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
26+
-p 127.0.0.1:8126:8126/tcp \
27+
-e DD_API_KEY="<DATADOG_API_KEY>" \
28+
-e DD_APM_ENABLED=true \
29+
datadog/agent:latest
30+
31+
* Run example
32+
33+
.. code-block:: sh
34+
35+
python datadog_exporter.py
36+
37+
Auto-Instrumention Example
38+
--------------------------
39+
40+
* Installation
41+
42+
.. code-block:: sh
43+
44+
pip install opentelemetry-api
45+
pip install opentelemetry-sdk
46+
pip install opentelemetry-ext-datadog
47+
pip install opentelemetry-auto-instrumentation
48+
pip install opentelemetry-ext-flask
49+
pip install flask
50+
pip install requests
51+
52+
* Start Datadog Agent
53+
54+
.. code-block:: sh
55+
56+
docker run --rm \
57+
-v /var/run/docker.sock:/var/run/docker.sock:ro \
58+
-v /proc/:/host/proc/:ro \
59+
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
60+
-p 127.0.0.1:8126:8126/tcp \
61+
-e DD_API_KEY="<DATADOG_API_KEY>" \
62+
-e DD_APM_ENABLED=true \
63+
datadog/agent:latest
64+
65+
* Start server
66+
67+
.. code-block:: sh
68+
69+
opentelemetry-auto-instrumentation python server.py
70+
71+
* Run client
72+
73+
.. code-block:: sh
74+
75+
opentelemetry-auto-instrumentation python client.py testing
76+
77+
* Run client with parameter to raise error
78+
79+
.. code-block:: sh
80+
81+
opentelemetry-auto-instrumentation python client.py error
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
from requests import get
18+
19+
from opentelemetry import propagators, trace
20+
from opentelemetry.ext.datadog import (
21+
DatadogExportSpanProcessor,
22+
DatadogSpanExporter,
23+
)
24+
from opentelemetry.sdk.trace import TracerProvider
25+
26+
trace.set_tracer_provider(TracerProvider())
27+
28+
trace.get_tracer_provider().add_span_processor(
29+
DatadogExportSpanProcessor(
30+
DatadogSpanExporter(
31+
agent_url="http://localhost:8126", service="example-client"
32+
)
33+
)
34+
)
35+
36+
tracer = trace.get_tracer(__name__)
37+
38+
assert len(argv) == 2
39+
40+
with tracer.start_as_current_span("client"):
41+
42+
with tracer.start_as_current_span("client-server"):
43+
headers = {}
44+
propagators.inject(dict.__setitem__, headers)
45+
requested = get(
46+
"http://localhost:8082/server_request",
47+
params={"param": argv[1]},
48+
headers=headers,
49+
)
50+
51+
assert requested.status_code == 200
52+
print(requested.text)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright The OpenTelemetry Authors
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from opentelemetry import trace
18+
from opentelemetry.ext.datadog import (
19+
DatadogExportSpanProcessor,
20+
DatadogSpanExporter,
21+
)
22+
from opentelemetry.sdk.trace import TracerProvider
23+
24+
trace.set_tracer_provider(TracerProvider())
25+
tracer = trace.get_tracer(__name__)
26+
27+
exporter = DatadogSpanExporter(
28+
agent_url="http://localhost:8126", service="example"
29+
)
30+
31+
span_processor = DatadogExportSpanProcessor(exporter)
32+
trace.get_tracer_provider().add_span_processor(span_processor)
33+
34+
with tracer.start_as_current_span("foo"):
35+
with tracer.start_as_current_span("bar"):
36+
with tracer.start_as_current_span("baz"):
37+
print("Hello world from OpenTelemetry Python!")
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 flask import Flask, request
16+
17+
from opentelemetry import trace
18+
from opentelemetry.ext.datadog import (
19+
DatadogExportSpanProcessor,
20+
DatadogSpanExporter,
21+
)
22+
from opentelemetry.sdk.trace import TracerProvider
23+
24+
app = Flask(__name__)
25+
26+
trace.set_tracer_provider(TracerProvider())
27+
28+
trace.get_tracer_provider().add_span_processor(
29+
DatadogExportSpanProcessor(
30+
DatadogSpanExporter(
31+
agent_url="http://localhost:8126", service="example-server"
32+
)
33+
)
34+
)
35+
36+
tracer = trace.get_tracer(__name__)
37+
38+
39+
@app.route("/server_request")
40+
def server_request():
41+
param = request.args.get("param")
42+
with tracer.start_as_current_span("server-inner"):
43+
if param == "error":
44+
raise ValueError("forced server error")
45+
return "served: {}".format(param)
46+
47+
48+
if __name__ == "__main__":
49+
app.run(port=8082)

docs/ext/datadog/datadog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry Datadog Exporter
2+
==============================
3+
4+
.. automodule:: opentelemetry.ext.datadog
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
- Add exporter to Datadog
6+
([#572](https://github.com/open-telemetry/opentelemetry-python/pull/572))
7+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
OpenTelemetry Datadog Exporter
2+
==============================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-datadog.svg
7+
:target: https://pypi.org/project/opentelemetry-ext-datadog/
8+
9+
This library allows to export tracing data to `Datadog
10+
<https://www.datadoghq.com/>`_. OpenTelemetry span event and links are not
11+
supported.
12+
13+
Installation
14+
------------
15+
16+
::
17+
18+
pip install opentelemetry-ext-datadog
19+
20+
21+
.. _Datadog: https://www.datadoghq.com/
22+
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/
23+
24+
25+
References
26+
----------
27+
28+
* `Datadog <https://www.datadoghq.com/>`_
29+
* `OpenTelemetry Project <https://opentelemetry.io/>`_
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
[metadata]
16+
name = opentelemetry-ext-datadog
17+
description = Datadog Span Exporter for OpenTelemetry
18+
long_description = file: README.rst
19+
long_description_content_type = text/x-rst
20+
author = OpenTelemetry Authors
21+
author_email = [email protected]
22+
url = https://github.com/open-telemetry/opentelemetry-python/ext/opentelemetry-ext-datadog
23+
platforms = any
24+
license = Apache-2.0
25+
classifiers =
26+
Development Status :: 4 - Beta
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
Programming Language :: Python
30+
Programming Language :: Python :: 3
31+
Programming Language :: Python :: 3.5
32+
Programming Language :: Python :: 3.6
33+
Programming Language :: Python :: 3.7
34+
Programming Language :: Python :: 3.8
35+
36+
[options]
37+
python_requires = >=3.5
38+
package_dir=
39+
=src
40+
packages=find_namespace:
41+
install_requires =
42+
ddtrace>=0.34.0
43+
opentelemetry-api==0.7.dev0
44+
opentelemetry-sdk==0.7.dev0
45+
46+
[options.packages.find]
47+
where = src
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
import os
16+
17+
import setuptools
18+
19+
BASE_DIR = os.path.dirname(__file__)
20+
VERSION_FILENAME = os.path.join(
21+
BASE_DIR, "src", "opentelemetry", "ext", "datadog", "version.py"
22+
)
23+
PACKAGE_INFO = {}
24+
with open(VERSION_FILENAME) as f:
25+
exec(f.read(), PACKAGE_INFO)
26+
27+
setuptools.setup(version=PACKAGE_INFO["__version__"])

0 commit comments

Comments
 (0)