@@ -449,6 +449,147 @@ following flag or environment variable::
449449
450450 $ PYTHONWARNINGS=all python app.py
451451
452+ .. _opentracing :
453+
454+ OpenTracing
455+ -----------
456+
457+ Datadog OpenTracing Tracer
458+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
459+
460+ The Datadog opentracer provides an OpenTracing-compatible API to the Datadog
461+ tracer so that you can use the Datadog tracer in your OpenTracing-compatible
462+ applications.
463+
464+ Installation
465+ ~~~~~~~~~~~~
466+
467+ To include OpenTracing dependencies in your project with `ddtrace `, ensure you
468+ have the following in `setup.py `::
469+
470+ install_requires=[
471+ "ddtrace[opentracing]",
472+ ],
473+
474+ Configuration
475+ ~~~~~~~~~~~~~
476+
477+ The OpenTracing convention for initializing a tracer is to define an
478+ initiliazation method that will configure and instantiate a new tracer and
479+ overwrite the global `opentracing.tracer ` reference.
480+
481+ Typically this method looks something like::
482+
483+ from ddtrace.opentracer import Tracer, set_global_tracer
484+
485+ def init_tracer(service_name):
486+ """
487+ Initialize a new Datadog opentracer and set it as the
488+ global tracer.
489+
490+ This overwrites the opentracing.tracer reference.
491+ """
492+ config = {
493+ 'agent_hostname': 'localhost',
494+ 'agent_port': 8126,
495+ }
496+ tracer = Tracer(service_name, config=config)
497+ set_global_tracer(tracer)
498+ return tracer
499+
500+ **Opentracer API **
501+
502+ .. autoclass :: ddtrace.opentracer.Tracer
503+ :members:
504+ :special-members: __init__
505+
506+
507+ The Datadog opentracer can be configured via the `config ` dictionary parameter
508+ which accepts the following described fields.
509+
510+ +---------------------+---------------------------------------------------------+---------------+
511+ | Configuration Key | Description | Default Value |
512+ +=====================+=========================================================+===============+
513+ | `enabled ` | enable or disable the tracer | `True ` |
514+ +---------------------+---------------------------------------------------------+---------------+
515+ | `debug ` | enable debug logging | `False ` |
516+ +---------------------+---------------------------------------------------------+---------------+
517+ | `agent_hostname ` | hostname of the Datadog agent to use | `localhost ` |
518+ +---------------------+---------------------------------------------------------+---------------+
519+ | `agent_port ` | port the Datadog agent is listening on | `8126 ` |
520+ +---------------------+---------------------------------------------------------+---------------+
521+ | `global_tags ` | tags that will be applied to each span | `{} ` |
522+ +---------------------+---------------------------------------------------------+---------------+
523+ | `sampler ` | see `Sampling `_ | `AllSampler ` |
524+ +---------------------+---------------------------------------------------------+---------------+
525+ | `priority_sampling ` | see `Priority Sampling `_ | `False ` |
526+ +---------------------+---------------------------------------------------------+---------------+
527+ | `settings ` | see `Advanced Usage `_ | `{} ` |
528+ +---------------------+---------------------------------------------------------+---------------+
529+
530+
531+ Usage
532+ ~~~~~
533+
534+ **Manual tracing **
535+
536+ To explicitly trace::
537+
538+ import time
539+ import opentracing
540+ from ddtrace.opentracer import Tracer, set_global_tracer
541+
542+ def init_tracer(service_name):
543+ config = {
544+ 'agent_hostname': 'localhost',
545+ 'agent_port': 8126,
546+ }
547+ tracer = Tracer(service_name, config=config)
548+ set_global_tracer(tracer)
549+ return tracer
550+
551+ def my_operation():
552+ span = opentracing.tracer.start_span('my_operation_name')
553+ span.set_tag('my_interesting_tag', 'my_interesting_value')
554+ time.sleep(0.05)
555+ span.finish()
556+
557+ init_tracer('my_service_name')
558+ my_operation()
559+
560+ **Context Manager Tracing **
561+
562+ To trace a function using the span context manager::
563+
564+ import time
565+ import opentracing
566+ from ddtrace.opentracer import Tracer, set_global_tracer
567+
568+ def init_tracer(service_name):
569+ config = {
570+ 'agent_hostname': 'localhost',
571+ 'agent_port': 8126,
572+ }
573+ tracer = Tracer(service_name, config=config)
574+ set_global_tracer(tracer)
575+ return tracer
576+
577+ def my_operation():
578+ with opentracing.tracer.start_span('my_operation_name') as span:
579+ span.set_tag('my_interesting_tag', 'my_interesting_value')
580+ time.sleep(0.05)
581+
582+ init_tracer('my_service_name')
583+ my_operation()
584+
585+ See our tracing trace-examples _ repository for concrete, runnable examples of
586+ the Datadog opentracer.
587+
588+ .. _trace-examples : https://github.com/DataDog/trace-examples/tree/master/python
589+
590+ See also the `Python OpenTracing `_ repository for usage of the tracer.
591+
592+ .. _Python OpenTracing : https://github.com/opentracing/opentracing-python
452593
453594Advanced Usage
454595--------------
0 commit comments