Skip to content

Commit b7a500c

Browse files
authored
Update OpenTracing section
1 parent 26fb1d6 commit b7a500c

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

README.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,26 @@ This Python package supports [OpenTracing](http://opentracing.io/). When using
3636
```Python
3737
import opentracing
3838

39-
parent_span = opentracing.tracer.start_span(operation_name="asteroid")
40-
# ... work
41-
child_span = opentracing.tracer.start_span(operation_name="spacedust", child_of=parent_span)
42-
child_span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
43-
# ... work
44-
child_span.finish()
45-
# ... work
46-
parent_span.finish()
39+
with ot.tracer.start_active_span('asteroid 💫') as pscope:
40+
pscope.span.set_tag(ext.COMPONENT, "Python simple example app")
41+
pscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_SERVER)
42+
pscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
43+
pscope.span.set_tag(ext.HTTP_URL, "/python/simple/one")
44+
pscope.span.set_tag(ext.HTTP_METHOD, "GET")
45+
pscope.span.set_tag(ext.HTTP_STATUS_CODE, 200)
46+
pscope.span.log_kv({"foo": "bar"})
47+
# ... work ...
48+
49+
with ot.tracer.start_active_span('spacedust 🌚', child_of=pscope.span) as cscope:
50+
cscope.span.set_tag(ext.SPAN_KIND, ext.SPAN_KIND_RPC_CLIENT)
51+
cscope.span.set_tag(ext.PEER_HOSTNAME, "localhost")
52+
cscope.span.set_tag(ext.HTTP_URL, "/python/simple/two")
53+
cscope.span.set_tag(ext.HTTP_METHOD, "POST")
54+
cscope.span.set_tag(ext.HTTP_STATUS_CODE, 204)
55+
cscope.span.set_baggage_item("someBaggage", "someValue")
56+
# ... work ...
4757
```
4858

49-
Note: The Instana sensor has automatic instrumentation that activates at runtime. If you need to get the current tracing context from existing instrumentation, you can use `opentracing.tracer.current_context()` and pass that return value as `childof`:
50-
51-
context = opentracing.tracer.current_context()
52-
span = opentracing.tracer.start_span("my_span", child_of=context)
53-
54-
Also note that under evented systems such as gevent, concurrence and/or greenlets (which aren't supportet yet), the value `opentracing.tracer.current_context()` is likely to be inconsistent.
55-
5659
## Configuration
5760

5861
For details on how to configure the Instana Python package, see [Configuration.md](https://github.com/instana/python-sensor/blob/master/Configuration.md)

0 commit comments

Comments
 (0)