Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit d7d31eb

Browse files
nbutton23lzchen
authored andcommitted
Create README.rst for the Datadog trace exporter (#799)
1 parent c904f48 commit d7d31eb

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
OpenCensus Datadog Exporter
2+
============================================================================
3+
4+
|pypi|
5+
6+
.. |pypi| image:: https://badge.fury.io/py/opencensus-ext-datadog.svg
7+
:target: https://pypi.org/project/opencensus-ext-datadog/
8+
9+
Installation
10+
------------
11+
12+
::
13+
14+
pip install opencensus-ext-datadog
15+
16+
Usage
17+
-----
18+
19+
Trace
20+
~~~~~
21+
22+
The **Datadog Trace Exporter** allows you to export `OpenCensus`_ traces to `Datadog`_.
23+
24+
This example shows how to send a span "hello" to Datadog.
25+
26+
* Set up a `Datadog Agent <https://docs.datadoghq.com/agent/>`_ that is accessible to your app.
27+
* Place the URL for the agent in the `trace_addr` of the configuration options.
28+
29+
.. code:: python
30+
31+
from opencensus.ext.datadog.traces import DatadogTraceExporter, Options
32+
from opencensus.trace.samplers import ProbabilitySampler
33+
from opencensus.trace.tracer import Tracer
34+
35+
tracer = Tracer(
36+
exporter=DatadogTraceExporter(Options(service='app-name',trace_addr='my-datdog-agent:8126`)),
37+
sampler=ProbabilitySampler(1.0)
38+
)
39+
40+
with tracer.span(name='hello'):
41+
print('Hello, World!')
42+
43+
OpenCensus also supports several `integrations <https://github.com/census-instrumentation/opencensus-python#integration>`_ which allows OpenCensus to integrate with third party libraries.
44+
45+
This example shows how to integrate with the `requests <https://2.python-requests.org/en/master/>`_ library.
46+
47+
* Set up a `Datadog Agent <https://docs.datadoghq.com/agent/>`_ that is accessible to your app.
48+
* Place the URL for the agent in the `trace_addr` of the configuration options.
49+
50+
.. code:: python
51+
52+
import requests
53+
54+
from opencensus.ext.datadog.traces import DatadogTraceExporter, Options
55+
from opencensus.trace.samplers import ProbabilitySampler
56+
from opencensus.trace.tracer import Tracer
57+
58+
config_integration.trace_integrations(['requests'])
59+
tracer = Tracer(
60+
exporter=DatadogTraceExporter(
61+
Options(
62+
service='app-name',
63+
trace_addr='my-datdog-agent:8126`
64+
)
65+
),
66+
sampler=ProbabilitySampler(1.0),
67+
)
68+
with tracer.span(name='parent'):
69+
response = requests.get(url='https://www.wikipedia.org/wiki/Rabbit')
70+
71+
72+
References
73+
----------
74+
75+
* `Datadog <https://www.datadoghq.com/product/>`_
76+
* `Examples <https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-datadog/examples>`_
77+
* `OpenCensus Project <https://opencensus.io/>`_
78+
79+
.. _Datadog: https://www.datadoghq.com/product/
80+
.. _OpenCensus: https://github.com/census-instrumentation/opencensus-python/

contrib/opencensus-ext-datadog/examples/datadog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from flask import Flask
22

3+
from opencensus.ext.datadog.traces import DatadogTraceExporter, Options
34
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
45
from opencensus.trace.samplers import AlwaysOnSampler
5-
from traces import DatadogTraceExporter, Options
66

77
app = Flask(__name__)
88
middleware = FlaskMiddleware(app,

0 commit comments

Comments
 (0)