|
| 1 | +# Overview |
| 2 | + |
| 3 | +This example shows how to use the auto-instrumentation agent in OpenTelemetry. |
| 4 | + |
| 5 | +A uninstrumented script will be executed once without the agent and then a instrumented script will |
| 6 | +be run with the agent. The results should show a `Span` being started in both cases. |
| 7 | + |
| 8 | +## Preparation |
| 9 | + |
| 10 | +This example will be executed in a separate virtual environment: |
| 11 | + |
| 12 | +```sh |
| 13 | +$ mkdir auto_instrumentation |
| 14 | +$ virtualenv auto_instrumentation |
| 15 | +$ source auto_instrumentation/bin/activate |
| 16 | +``` |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +```sh |
| 21 | +$ git clone [email protected]:open-telemetry/opentelemetry-python.git |
| 22 | +$ cd opentelemetry-python |
| 23 | +$ git checkout issue_300 |
| 24 | +$ pip3 install -e opentelemetry-api |
| 25 | +$ pip3 install -e opentelemetry-sdk |
| 26 | +$ pip3 install -e ext/opentelemetry-flask |
| 27 | +$ pip3 install flask |
| 28 | +$ pip3 install requests |
| 29 | +``` |
| 30 | + |
| 31 | +## Execution of manually traced publisher |
| 32 | + |
| 33 | +This is done in 3 separate consoles, one to run each of the scripts that make up this example: |
| 34 | + |
| 35 | +```sh |
| 36 | +$ source auto_instrumentation/bin/activate |
| 37 | +$ python3 opentelemetry-python/examples/auto_instrumentation/formatter.py |
| 38 | +``` |
| 39 | + |
| 40 | +```sh |
| 41 | +$ source auto_instrumentation/bin/activate |
| 42 | +$ python3 opentelemetry-python/examples/auto_instrumentation/publisher.py |
| 43 | +``` |
| 44 | + |
| 45 | +```sh |
| 46 | +$ source auto_instrumentation/bin/activate |
| 47 | +$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing |
| 48 | +``` |
| 49 | + |
| 50 | +The execution of `publisher.py` should return an output similar to: |
| 51 | + |
| 52 | +```sh |
| 53 | +Hello, testing! |
| 54 | +Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) |
| 55 | +127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - |
| 56 | +``` |
| 57 | + |
| 58 | +Now, kill the execution of `publisher.py` with `ctrl + c` and run this instead: |
| 59 | + |
| 60 | +```sh |
| 61 | +$ auto_agent python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing |
| 62 | +``` |
| 63 | + |
| 64 | +In the console where you previously executed `hello.py`, run again this: |
| 65 | + |
| 66 | +```sh |
| 67 | +$ python3 opentelemetry-python/examples/auto_instrumentation/hello.py testing |
| 68 | +``` |
| 69 | + |
| 70 | +That should produce an output similar to this in the console where the `auto_agent` was executed: |
| 71 | + |
| 72 | +```sh |
| 73 | +Hello, testing! |
| 74 | +Span(name="publish", context=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0x6162c475bab8d365, trace_state={}), kind=SpanKind.SERVER, parent=SpanContext(trace_id=0xd18be4c644d3be57a8623bbdbdbcef76, span_id=0xdafb264c5b1b6ed0, trace_state={}), start_time=2019-12-19T01:11:12.172866Z, end_time=2019-12-19T01:11:12.173383Z) |
| 75 | +127.0.0.1 - - [18/Dec/2019 19:11:12] "GET /publish?helloStr=Hello%2C+testing%21 HTTP/1.1" 200 - |
| 76 | +``` |
0 commit comments