-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exporter to Datadog #572
Changes from all commits
f56b985
3b3e25e
8ed8ee6
3d9267d
7664e6d
6a02800
0b74eba
f35291e
94908ae
73c71a5
6c19ce7
64c8779
480e977
9561c66
07bbeb4
08451b3
53594b7
9a0cabb
a03aec8
0459105
68c0e26
6e6fbbb
fe2173f
9c451f9
7d10628
c2e82d8
c193b36
7f73fa1
9cbe3d5
87a8c44
88d690c
7ccd8a9
471ebba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to have this example live within a |
||
|
||
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) |
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!") |
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tiny nit: might be nice to have the port easily configurable via environment variable in case there's a conflict. |
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: |
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)) | ||
|
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/>`_ |
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 | ||
mauriciovasquezbernal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
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__"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can roll these up into a single pip install.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at the moment