-
Notifications
You must be signed in to change notification settings - Fork 864
Fix autoinstrumentation docs #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
toumorokoshi
merged 3 commits into
open-telemetry:master
from
mauriciovasquezbernal:mauricio/fix-auinstrumentation-docs
May 6, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| Autoinstrumentation | ||
| =================== | ||
|
|
||
| Overview | ||
| -------- | ||
|
|
||
| This example shows how to use auto-instrumentation in OpenTelemetry. | ||
| This example is also based on a previous example for OpenTracing that | ||
| can be found | ||
| `here <https://github.com/yurishkuro/opentracing-tutorial/tree/master/python>`__. | ||
|
|
||
| The source files of these examples are available :scm_web:`here <docs/examples/auto-instrumentation/>`. | ||
|
|
||
| This example uses 2 scripts whose main difference is they being | ||
| instrumented manually or not: | ||
|
|
||
| 1. ``server_instrumented.py`` which has been instrumented manually | ||
| 2. ``server_uninstrumented.py`` which has not been instrumented manually | ||
|
|
||
| The former will be run without the automatic instrumentation agent and | ||
| the latter with the automatic instrumentation agent. They should produce | ||
| the same result, showing that the automatic instrumentation agent does | ||
| the equivalent of what manual instrumentation does. | ||
|
|
||
| In order to understand this better, here is the relevant part of both | ||
| scripts: | ||
|
|
||
| Manually instrumented server | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| ``server_instrumented.py`` | ||
|
|
||
| .. code:: python | ||
|
|
||
| @app.route("/server_request") | ||
| def server_request(): | ||
| with tracer.start_as_current_span( | ||
| "server_request", | ||
| parent=propagators.extract( | ||
| lambda dict_, key: dict_.get(key, []), request.headers | ||
| )["current-span"], | ||
| ): | ||
| print(request.args.get("param")) | ||
| return "served" | ||
|
|
||
| Publisher not instrumented manually | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| ``server_uninstrumented.py`` | ||
|
|
||
| .. code:: python | ||
|
|
||
| @app.route("/server_request") | ||
| def server_request(): | ||
| print(request.args.get("param")) | ||
| return "served" | ||
|
|
||
| Preparation | ||
| ----------- | ||
|
|
||
| This example will be executed in a separate virtual environment: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ mkdir auto_instrumentation | ||
| $ virtualenv auto_instrumentation | ||
| $ source auto_instrumentation/bin/activate | ||
|
|
||
| Installation | ||
| ------------ | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ pip install opentelemetry-sdk | ||
| $ pip install opentelemetry-auto-instrumentation | ||
| $ pip install opentelemetry-ext-flask | ||
| $ pip install requests | ||
|
|
||
| Execution | ||
| --------- | ||
|
|
||
| Execution of the manually instrumented server | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| This is done in 2 separate consoles, one to run each of the scripts that | ||
| make up this example: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ source auto_instrumentation/bin/activate | ||
| $ python server_instrumented.py | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ source auto_instrumentation/bin/activate | ||
| $ python client.py testing | ||
|
|
||
| The execution of ``server_instrumented.py`` should return an output | ||
| similar to: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| { | ||
| "name": "server_request", | ||
| "context": { | ||
| "trace_id": "0xfa002aad260b5f7110db674a9ddfcd23", | ||
| "span_id": "0x8b8bbaf3ca9c5131", | ||
| "trace_state": "{}" | ||
| }, | ||
| "kind": "SpanKind.SERVER", | ||
| "parent_id": null, | ||
| "start_time": "2020-04-30T17:28:57.886397Z", | ||
| "end_time": "2020-04-30T17:28:57.886490Z", | ||
| "status": { | ||
| "canonical_code": "OK" | ||
| }, | ||
| "attributes": { | ||
| "component": "http", | ||
| "http.method": "GET", | ||
| "http.server_name": "127.0.0.1", | ||
| "http.scheme": "http", | ||
| "host.port": 8082, | ||
| "http.host": "localhost:8082", | ||
| "http.target": "/server_request?param=testing", | ||
| "net.peer.ip": "127.0.0.1", | ||
| "net.peer.port": 52872, | ||
| "http.flavor": "1.1" | ||
| }, | ||
| "events": [], | ||
| "links": [] | ||
| } | ||
|
|
||
| Execution of an automatically instrumented server | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Now, kill the execution of ``server_instrumented.py`` with ``ctrl + c`` | ||
| and run this instead: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ opentelemetry-auto-instrumentation python server_uninstrumented.py | ||
|
|
||
| In the console where you previously executed ``client.py``, run again | ||
| this again: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| $ python client.py testing | ||
|
|
||
| The execution of ``server_uninstrumented.py`` should return an output | ||
| similar to: | ||
|
|
||
| .. code:: sh | ||
|
|
||
| { | ||
| "name": "server_request", | ||
| "context": { | ||
| "trace_id": "0x9f528e0b76189f539d9c21b1a7a2fc24", | ||
| "span_id": "0xd79760685cd4c269", | ||
| "trace_state": "{}" | ||
| }, | ||
| "kind": "SpanKind.SERVER", | ||
| "parent_id": "0xb4fb7eee22ef78e4", | ||
| "start_time": "2020-04-30T17:10:02.400604Z", | ||
| "end_time": "2020-04-30T17:10:02.401858Z", | ||
| "status": { | ||
| "canonical_code": "OK" | ||
| }, | ||
| "attributes": { | ||
| "component": "http", | ||
| "http.method": "GET", | ||
| "http.server_name": "127.0.0.1", | ||
| "http.scheme": "http", | ||
| "host.port": 8082, | ||
| "http.host": "localhost:8082", | ||
| "http.target": "/server_request?param=testing", | ||
| "net.peer.ip": "127.0.0.1", | ||
| "net.peer.port": 48240, | ||
| "http.flavor": "1.1", | ||
| "http.route": "/server_request", | ||
| "http.status_text": "OK", | ||
| "http.status_code": 200 | ||
| }, | ||
| "events": [], | ||
| "links": [] | ||
| } | ||
|
|
||
| Both outputs are equivalent since the automatic instrumentation does | ||
| what the manual instrumentation does too. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.