Skip to content

Commit 2e53a43

Browse files
authored
Add back opentracing docs (#1512)
1 parent 50696bb commit 2e53a43

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

docs/opentracing.asciidoc

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// TODO This doc should be removed in 7.0.0
2+
// It continues to exist because older versions point to the latest version on a major
3+
[[opentracing-bridge]]
4+
== OpenTracing API
5+
6+
The Elastic APM OpenTracing bridge allows you to create Elastic APM `Transactions` and `Spans`,
7+
using the OpenTracing API.
8+
In other words,
9+
it translates calls to the OpenTracing API to Elastic APM events, which allows for the reuse of existing instrumentation.
10+
11+
The first span of a service will be converted to an Elastic APM
12+
{apm-guide-ref}/transactions.html[`Transaction`],
13+
subsequent spans are mapped to Elastic APM
14+
{apm-guide-ref}/transaction-spans.html[`Span`].
15+
16+
[float]
17+
[[opentracing-getting-started]]
18+
=== Getting started
19+
The first step in getting started with the OpenTracing API bridge is to install the `opentracing` library:
20+
21+
[source,bash]
22+
----
23+
pip install elastic-apm[opentracing]
24+
----
25+
26+
Or if you already have installed `elastic-apm`
27+
28+
29+
[source,bash]
30+
----
31+
pip install opentracing>=2.0.0
32+
----
33+
34+
35+
[float]
36+
[[opentracing-init-tracer]]
37+
=== Initialize tracer
38+
39+
[source,python]
40+
----
41+
from elasticapm.contrib.opentracing import Tracer
42+
43+
tracer = Tracer();
44+
----
45+
46+
`Tracer` accepts the following optional arguments:
47+
48+
* `client_instance`: an already instantiated Elastic APM client
49+
* `config`: a configuration dictionary, which will be used to instantiate a new Elastic APM client,
50+
e.g. `{"SERVER_URL": "https://example.org"}`. See <<configuration, configuration>> for more information.
51+
* `scope_manager`: a scope manager instance. Defaults to `ThreadLocalScopeManager` (see
52+
53+
54+
[float]
55+
[[opentracing-elastic-apm-tags]]
56+
=== Elastic APM specific tags
57+
58+
Elastic APM defines some tags which are not included in the OpenTracing API but are relevant in the context of Elastic APM.
59+
60+
- `type` - sets the type of the transaction,
61+
for example `request`, `ext` or `db`
62+
- `user.id` - sets the user id,
63+
appears in the "User" tab in the transaction details in the Elastic APM UI
64+
- `user.email` - sets the user email,
65+
appears in the "User" tab in the transaction details in the Elastic APM UI
66+
- `user.username` - sets the user name,
67+
appears in the "User" tab in the transaction details in the Elastic APM UI
68+
- `result` - sets the result of the transaction. Overrides the default value of `success`.
69+
70+
NOTE: these tags need to be set on the first span of an operation (e.g. an incoming request of your webapp).
71+
72+
[float]
73+
[[opentracing-caveats]]
74+
=== Caveats
75+
Not all features of the OpenTracing API are supported.
76+
77+
[float]
78+
[[opentracing-scope-managers]]
79+
==== Scope Managers
80+
Currently, only the `ThreadLocalScopeManager` is supported.
81+
Using other scope managers will lead to unpredictable and possibly app-breaking behavior.
82+
83+
[float]
84+
[[opentracing-instrumentation]]
85+
==== Instrumentation
86+
87+
It is recommended to not use the built-in instrumentations of Elastic APM together with third-party OpenTracing instrumentations
88+
like https://pypi.org/project/opentracing_instrumentation/[opentracing_instrumentation] in the same service.
89+
If you would like to use such instrumentations, we recommend to disable the built-in instrumentation using the <<config-instrument,`instrument`>> config option.
90+
91+
[float]
92+
[[opentracing-propagation]]
93+
==== Context propagation
94+
This bridge only supports the formats `Format.Builtin.TEXT_MAP` and `Format.Builtin.HTTP_HEADERS`.
95+
`Format.Builtin.BINARY` is currently not supported.
96+
97+
[float]
98+
[[opentracing-references]]
99+
==== Span references
100+
Currently, this bridge only supports `child_of` references.
101+
Other references,
102+
like `follows_from` are not supported yet.
103+
104+
[float]
105+
[[opentracing-baggage]]
106+
==== Baggage
107+
The `Span.set_baggage_item(key, value)` method is not supported.
108+
Baggage items are silently dropped.
109+
110+
[float]
111+
[[opentracing-logs]]
112+
==== Logs
113+
Only exception logging is supported.
114+
Logging an Exception on the OpenTracing span will create an Elastic APM
115+
{apm-guide-ref}/errors.html[`Error`].
116+
Example:
117+
118+
[source,python]
119+
----
120+
with tracer.start_active_span("transaction") as tx_scope:
121+
try:
122+
raise ValueError("oops")
123+
except ValueError:
124+
exc_type, exc_val, exc_tb = sys.exc_info()[:3]
125+
tx_scope.span.log_kv({
126+
"python.exception.type": exc_type,
127+
"python.exception.val": exc_val,
128+
"python.exception.tb": exc_tb
129+
})
130+
----

0 commit comments

Comments
 (0)