|
| 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/ |
0 commit comments