|
43 | 43 | an optional dependency. This does however limit the number of modifiable spans |
44 | 44 | at any point in the code to one. From here out references to `opentracing` |
45 | 45 | 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. |
46 | 49 |
|
47 | 50 | Tracing |
48 | 51 | ------- |
|
68 | 71 | Tracing functions |
69 | 72 | ----------------- |
70 | 73 |
|
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 |
73 | 75 | the function becomes the operation name for the span. |
74 | 76 |
|
75 | 77 | .. code-block:: python |
76 | 78 |
|
77 | | - from synapse.logging.opentracing import trace, trace_deferred |
| 79 | + from synapse.logging.opentracing import trace |
78 | 80 |
|
79 | | - # Start a span using 'normal_function' as the operation name |
| 81 | + # Start a span using 'interesting_function' as the operation name |
80 | 82 | @trace |
81 | | - def normal_function(*args, **kwargs): |
| 83 | + def interesting_function(*args, **kwargs): |
82 | 84 | # Does all kinds of cool and expected things |
83 | 85 | return something_usual_and_useful |
84 | 86 |
|
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 |
93 | 87 |
|
94 | 88 | 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`` |
97 | 90 |
|
98 | 91 | .. code-block:: python |
99 | 92 |
|
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 |
104 | 94 |
|
105 | 95 | @trace_using_operation_name("A *much* better operation name") |
106 | | - def normal_function(*args, **kwargs): |
| 96 | + def interesting_badly_named_function(*args, **kwargs): |
107 | 97 | # Does all kinds of cool and expected things |
108 | 98 | return something_usual_and_useful |
109 | 99 |
|
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" |
117 | 130 |
|
118 | 131 | Contexts and carriers |
119 | 132 | --------------------- |
|
0 commit comments