Skip to content
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

Merged
merged 33 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f56b985
feat: Add exporter to datadog
majorgreys Apr 13, 2020
3b3e25e
use component for resource
majorgreys Apr 15, 2020
8ed8ee6
add client server example
majorgreys Apr 15, 2020
3d9267d
handle http resources
majorgreys Apr 15, 2020
7664e6d
add span type
majorgreys Apr 15, 2020
6a02800
add exception info
majorgreys Apr 15, 2020
0b74eba
add docs
majorgreys Apr 16, 2020
f35291e
fix span tests
majorgreys Apr 16, 2020
94908ae
Merge branch 'master' into majorgreys/exporter-datadog
majorgreys Apr 16, 2020
73c71a5
feat: add span processor for datadog
majorgreys Apr 23, 2020
6c19ce7
use assertIsNone and assertIsNotNone
majorgreys Apr 27, 2020
64c8779
add note about not supporting events and links
majorgreys Apr 27, 2020
480e977
auto-inst client in example
majorgreys Apr 27, 2020
9561c66
Update docs/examples/datadog_exporter/README.rst
majorgreys Apr 27, 2020
07bbeb4
Merge remote-tracking branch 'upstream/master' into majorgreys/export…
majorgreys Apr 27, 2020
08451b3
Merge branch 'majorgreys/exporter-datadog' of github.com:DataDog/open…
majorgreys Apr 27, 2020
53594b7
only queue trace for export when all spans ended
majorgreys Apr 27, 2020
9a0cabb
Merge remote-tracking branch 'upstream/master' into majorgreys/export…
majorgreys Apr 27, 2020
a03aec8
simplify conversion to uint64
majorgreys Apr 30, 2020
0459105
update examples
majorgreys Apr 30, 2020
68c0e26
Merge remote-tracking branch 'upstream/master' into majorgreys/export…
majorgreys Apr 30, 2020
6e6fbbb
Merge remote-tracking branch 'upstream/master' into majorgreys/export…
majorgreys May 1, 2020
fe2173f
add missing licenses
majorgreys May 7, 2020
9c451f9
fix lint
majorgreys May 7, 2020
7d10628
cleanup lock
majorgreys May 7, 2020
c2e82d8
updates to name, type, resource
majorgreys May 8, 2020
c193b36
update docs
majorgreys May 8, 2020
7f73fa1
Merge remote-tracking branch 'upstream/master' into majorgreys/export…
majorgreys May 8, 2020
9cbe3d5
simplify exportable check
majorgreys May 8, 2020
87a8c44
add changelog
majorgreys May 11, 2020
88d690c
Merge branch 'master' into majorgreys/exporter-datadog
majorgreys May 11, 2020
7ccd8a9
Merge branch 'master' into majorgreys/exporter-datadog
majorgreys May 12, 2020
471ebba
Merge branch 'master' into majorgreys/exporter-datadog
majorgreys May 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2

# Required by ext packages
ddtrace>=0.34.0
aiohttp ~= 3.0
Deprecated>=1.2.6
django>=2.2
Expand Down
81 changes: 81 additions & 0 deletions docs/examples/datadog_exporter/README.rst
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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the moment

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
52 changes: 52 additions & 0 deletions docs/examples/datadog_exporter/client.py
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"):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to have this example live within a while True loop with a slight delay? Might better demonstrate practical usage in the product.


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)
37 changes: 37 additions & 0 deletions docs/examples/datadog_exporter/datadog_exporter.py
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!")
49 changes: 49 additions & 0 deletions docs/examples/datadog_exporter/server.py
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)

Choose a reason for hiding this comment

The 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.

7 changes: 7 additions & 0 deletions docs/ext/datadog/datadog.rst
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:
7 changes: 7 additions & 0 deletions ext/opentelemetry-ext-datadog/CHANGELOG.md
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))

29 changes: 29 additions & 0 deletions ext/opentelemetry-ext-datadog/README.rst
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/>`_
47 changes: 47 additions & 0 deletions ext/opentelemetry-ext-datadog/setup.cfg
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
27 changes: 27 additions & 0 deletions ext/opentelemetry-ext-datadog/setup.py
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__"])
Loading