-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <mauricio@kinvolk.io>
- Loading branch information
1 parent
8d09319
commit f1a7feb
Showing
18 changed files
with
1,242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Datadog Exporter Example | ||
======================== | ||
|
||
These examples show how to use OpenTelemetry to send tracing data to Datadog. | ||
|
||
|
||
Basic Example | ||
------------- | ||
|
||
* Installation | ||
|
||
.. code-block:: sh | ||
pip install opentelemetry-api | ||
pip install opentelemetry-sdk | ||
pip install opentelemetry-ext-datadog | ||
* Start Datadog Agent | ||
|
||
.. code-block:: sh | ||
docker run --rm \ | ||
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
-v /proc/:/host/proc/:ro \ | ||
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \ | ||
-p 127.0.0.1:8126:8126/tcp \ | ||
-e DD_API_KEY="<DATADOG_API_KEY>" \ | ||
-e DD_APM_ENABLED=true \ | ||
datadog/agent:latest | ||
* Run example | ||
|
||
.. code-block:: sh | ||
python datadog_exporter.py | ||
Auto-Instrumention Example | ||
-------------------------- | ||
|
||
* Installation | ||
|
||
.. code-block:: sh | ||
pip install opentelemetry-api | ||
pip install opentelemetry-sdk | ||
pip install opentelemetry-ext-datadog | ||
pip install opentelemetry-auto-instrumentation | ||
pip install opentelemetry-ext-flask | ||
pip install flask | ||
pip install requests | ||
* Start Datadog Agent | ||
|
||
.. code-block:: sh | ||
docker run --rm \ | ||
-v /var/run/docker.sock:/var/run/docker.sock:ro \ | ||
-v /proc/:/host/proc/:ro \ | ||
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \ | ||
-p 127.0.0.1:8126:8126/tcp \ | ||
-e DD_API_KEY="<DATADOG_API_KEY>" \ | ||
-e DD_APM_ENABLED=true \ | ||
datadog/agent:latest | ||
* Start server | ||
|
||
.. code-block:: sh | ||
opentelemetry-auto-instrumentation python server.py | ||
* Run client | ||
|
||
.. code-block:: sh | ||
opentelemetry-auto-instrumentation python client.py testing | ||
* Run client with parameter to raise error | ||
|
||
.. code-block:: sh | ||
opentelemetry-auto-instrumentation python client.py error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from sys import argv | ||
|
||
from requests import get | ||
|
||
from opentelemetry import propagators, trace | ||
from opentelemetry.ext.datadog import ( | ||
DatadogExportSpanProcessor, | ||
DatadogSpanExporter, | ||
) | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
||
trace.set_tracer_provider(TracerProvider()) | ||
|
||
trace.get_tracer_provider().add_span_processor( | ||
DatadogExportSpanProcessor( | ||
DatadogSpanExporter( | ||
agent_url="http://localhost:8126", service="example-client" | ||
) | ||
) | ||
) | ||
|
||
tracer = trace.get_tracer(__name__) | ||
|
||
assert len(argv) == 2 | ||
|
||
with tracer.start_as_current_span("client"): | ||
|
||
with tracer.start_as_current_span("client-server"): | ||
headers = {} | ||
propagators.inject(dict.__setitem__, headers) | ||
requested = get( | ||
"http://localhost:8082/server_request", | ||
params={"param": argv[1]}, | ||
headers=headers, | ||
) | ||
|
||
assert requested.status_code == 200 | ||
print(requested.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.ext.datadog import ( | ||
DatadogExportSpanProcessor, | ||
DatadogSpanExporter, | ||
) | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
||
trace.set_tracer_provider(TracerProvider()) | ||
tracer = trace.get_tracer(__name__) | ||
|
||
exporter = DatadogSpanExporter( | ||
agent_url="http://localhost:8126", service="example" | ||
) | ||
|
||
span_processor = DatadogExportSpanProcessor(exporter) | ||
trace.get_tracer_provider().add_span_processor(span_processor) | ||
|
||
with tracer.start_as_current_span("foo"): | ||
with tracer.start_as_current_span("bar"): | ||
with tracer.start_as_current_span("baz"): | ||
print("Hello world from OpenTelemetry Python!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from flask import Flask, request | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.ext.datadog import ( | ||
DatadogExportSpanProcessor, | ||
DatadogSpanExporter, | ||
) | ||
from opentelemetry.sdk.trace import TracerProvider | ||
|
||
app = Flask(__name__) | ||
|
||
trace.set_tracer_provider(TracerProvider()) | ||
|
||
trace.get_tracer_provider().add_span_processor( | ||
DatadogExportSpanProcessor( | ||
DatadogSpanExporter( | ||
agent_url="http://localhost:8126", service="example-server" | ||
) | ||
) | ||
) | ||
|
||
tracer = trace.get_tracer(__name__) | ||
|
||
|
||
@app.route("/server_request") | ||
def server_request(): | ||
param = request.args.get("param") | ||
with tracer.start_as_current_span("server-inner"): | ||
if param == "error": | ||
raise ValueError("forced server error") | ||
return "served: {}".format(param) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(port=8082) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
OpenTelemetry Datadog Exporter | ||
============================== | ||
|
||
.. automodule:: opentelemetry.ext.datadog | ||
:members: | ||
:undoc-members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Changelog | ||
|
||
## Unreleased | ||
|
||
- Add exporter to Datadog | ||
([#572](https://github.com/open-telemetry/opentelemetry-python/pull/572)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
OpenTelemetry Datadog Exporter | ||
============================== | ||
|
||
|pypi| | ||
|
||
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-datadog.svg | ||
:target: https://pypi.org/project/opentelemetry-ext-datadog/ | ||
|
||
This library allows to export tracing data to `Datadog | ||
<https://www.datadoghq.com/>`_. OpenTelemetry span event and links are not | ||
supported. | ||
|
||
Installation | ||
------------ | ||
|
||
:: | ||
|
||
pip install opentelemetry-ext-datadog | ||
|
||
|
||
.. _Datadog: https://www.datadoghq.com/ | ||
.. _OpenTelemetry: https://github.com/open-telemetry/opentelemetry-python/ | ||
|
||
|
||
References | ||
---------- | ||
|
||
* `Datadog <https://www.datadoghq.com/>`_ | ||
* `OpenTelemetry Project <https://opentelemetry.io/>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
[metadata] | ||
name = opentelemetry-ext-datadog | ||
description = Datadog Span Exporter for OpenTelemetry | ||
long_description = file: README.rst | ||
long_description_content_type = text/x-rst | ||
author = OpenTelemetry Authors | ||
author_email = cncf-opentelemetry-contributors@lists.cncf.io | ||
url = https://github.com/open-telemetry/opentelemetry-python/ext/opentelemetry-ext-datadog | ||
platforms = any | ||
license = Apache-2.0 | ||
classifiers = | ||
Development Status :: 4 - Beta | ||
Intended Audience :: Developers | ||
License :: OSI Approved :: Apache Software License | ||
Programming Language :: Python | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.5 | ||
Programming Language :: Python :: 3.6 | ||
Programming Language :: Python :: 3.7 | ||
Programming Language :: Python :: 3.8 | ||
|
||
[options] | ||
python_requires = >=3.5 | ||
package_dir= | ||
=src | ||
packages=find_namespace: | ||
install_requires = | ||
ddtrace>=0.34.0 | ||
opentelemetry-api==0.7.dev0 | ||
opentelemetry-sdk==0.7.dev0 | ||
|
||
[options.packages.find] | ||
where = src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
|
||
import setuptools | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
VERSION_FILENAME = os.path.join( | ||
BASE_DIR, "src", "opentelemetry", "ext", "datadog", "version.py" | ||
) | ||
PACKAGE_INFO = {} | ||
with open(VERSION_FILENAME) as f: | ||
exec(f.read(), PACKAGE_INFO) | ||
|
||
setuptools.setup(version=PACKAGE_INFO["__version__"]) |
Oops, something went wrong.