Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit c886f97

Browse files
Opentracing doc update (#5776)
Update opentracing docs to use the unified 'trace' method
1 parent d514dac commit c886f97

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

changelog.d/5776.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update opentracing docs to use the unified `trace` method.

synapse/logging/opentracing.py

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
an optional dependency. This does however limit the number of modifiable spans
4444
at any point in the code to one. From here out references to `opentracing`
4545
in the code snippets refer to the Synapses module.
46+
Most methods provided in the module have a direct correlation to those provided
47+
by opentracing. Refer to docs there for a more in-depth documentation on some of
48+
the args and methods.
4649
4750
Tracing
4851
-------
@@ -68,52 +71,62 @@
6871
Tracing functions
6972
-----------------
7073
71-
Functions can be easily traced using decorators. There is a decorator for
72-
'normal' function and for functions which are actually deferreds. The name of
74+
Functions can be easily traced using decorators. The name of
7375
the function becomes the operation name for the span.
7476
7577
.. code-block:: python
7678
77-
from synapse.logging.opentracing import trace, trace_deferred
79+
from synapse.logging.opentracing import trace
7880
79-
# Start a span using 'normal_function' as the operation name
81+
# Start a span using 'interesting_function' as the operation name
8082
@trace
81-
def normal_function(*args, **kwargs):
83+
def interesting_function(*args, **kwargs):
8284
# Does all kinds of cool and expected things
8385
return something_usual_and_useful
8486
85-
# Start a span using 'deferred_function' as the operation name
86-
@trace_deferred
87-
@defer.inlineCallbacks
88-
def deferred_function(*args, **kwargs):
89-
# We start
90-
yield we_wait
91-
# we finish
92-
return something_usual_and_useful
9387
9488
Operation names can be explicitly set for functions by using
95-
``trace_using_operation_name`` and
96-
``trace_deferred_using_operation_name``
89+
``trace_using_operation_name``
9790
9891
.. code-block:: python
9992
100-
from synapse.logging.opentracing import (
101-
trace_using_operation_name,
102-
trace_deferred_using_operation_name
103-
)
93+
from synapse.logging.opentracing import trace_using_operation_name
10494
10595
@trace_using_operation_name("A *much* better operation name")
106-
def normal_function(*args, **kwargs):
96+
def interesting_badly_named_function(*args, **kwargs):
10797
# Does all kinds of cool and expected things
10898
return something_usual_and_useful
10999
110-
@trace_deferred_using_operation_name("Another exciting operation name!")
111-
@defer.inlineCallbacks
112-
def deferred_function(*args, **kwargs):
113-
# We start
114-
yield we_wait
115-
# we finish
116-
return something_usual_and_useful
100+
Setting Tags
101+
------------
102+
103+
To set a tag on the active span do
104+
105+
.. code-block:: python
106+
107+
from synapse.logging.opentracing import set_tag
108+
109+
set_tag(tag_name, tag_value)
110+
111+
There's a convenient decorator to tag all the args of the method. It uses
112+
inspection in order to use the formal parameter names prefixed with 'ARG_' as
113+
tag names. It uses kwarg names as tag names without the prefix.
114+
115+
.. code-block:: python
116+
117+
from synapse.logging.opentracing import tag_args
118+
119+
@tag_args
120+
def set_fates(clotho, lachesis, atropos, father="Zues", mother="Themis"):
121+
pass
122+
123+
set_fates("the story", "the end", "the act")
124+
# This will have the following tags
125+
# - ARG_clotho: "the story"
126+
# - ARG_lachesis: "the end"
127+
# - ARG_atropos: "the act"
128+
# - father: "Zues"
129+
# - mother: "Themis"
117130
118131
Contexts and carriers
119132
---------------------

0 commit comments

Comments
 (0)