Skip to content

Commit 3a0d38f

Browse files
author
alrex
authored
adding documentation for using opentelemetry-distro (open-telemetry#1813)
1 parent 81d80aa commit 3a0d38f

File tree

4 files changed

+121
-8
lines changed

4 files changed

+121
-8
lines changed

docs/examples/auto-instrumentation/README.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Manually instrumented server
4545
return "served"
4646
4747
Server not instrumented manually
48-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4949

5050
``server_uninstrumented.py``
5151

@@ -57,7 +57,7 @@ Server not instrumented manually
5757
return "served"
5858
5959
Prepare
60-
-----------
60+
-------
6161

6262
Execute the following example in a separate virtual environment.
6363
Run the following commands to prepare for auto-instrumentation:
@@ -69,7 +69,7 @@ Run the following commands to prepare for auto-instrumentation:
6969
$ source auto_instrumentation/bin/activate
7070
7171
Install
72-
------------
72+
-------
7373

7474
Run the following commands to install the appropriate packages. The
7575
``opentelemetry-instrumentation`` package provides several
@@ -90,7 +90,7 @@ a server as well as the process of executing an automatically
9090
instrumented server.
9191

9292
Execute a manually instrumented server
93-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9494

9595
Execute the server in two separate consoles, one to run each of the
9696
scripts that make up this example:
@@ -145,7 +145,7 @@ similar to the following example:
145145
}
146146
147147
Execute an automatically instrumented server
148-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149149

150150
Stop the execution of ``server_instrumented.py`` with ``ctrl + c``
151151
and run the following command instead:
@@ -208,7 +208,7 @@ You can see that both outputs are the same because automatic instrumentation doe
208208
exactly what manual instrumentation does.
209209

210210
Instrumentation while debugging
211-
===============================
211+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
212212

213213
The debug mode can be enabled in the Flask app like this:
214214

@@ -226,3 +226,11 @@ reloader. To run instrumentation while the debug mode is enabled, set the
226226
227227
if __name__ == "__main__":
228228
app.run(port=8082, debug=True, use_reloader=False)
229+
230+
231+
Additional resources
232+
~~~~~~~~~~~~~~~~~~~~
233+
234+
In order to send telemetry to an OpenTelemetry Collector without doing any
235+
additional configuration, read about the `OpenTelemetry Distro <../distro/README.html>`_
236+
package.

docs/examples/distro/README.rst

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
OpenTelemetry Distro
2+
====================
3+
4+
In order to make using OpenTelemetry and auto-instrumentation as quick as possible without sacrificing flexibility,
5+
OpenTelemetry distros provide a mechanism to automatically configure some of the more common options for users. By
6+
harnessing their power, users of OpenTelemetry can configure the components as they need. The ``opentelemetry-distro``
7+
package provides some defaults to users looking to get started, it configures:
8+
9+
- the SDK TracerProvider
10+
- a BatchSpanProcessor
11+
- the OTLP ``SpanExporter`` to send data to an OpenTelemetry collector
12+
13+
The package also provides a starting point for anyone interested in producing an alternative distro. The
14+
interfaces implemented by the package are loaded by the auto-instrumentation via the ``opentelemetry_distro``
15+
and ``opentelemetry_configurator`` entry points to configure the application before any other code is
16+
executed.
17+
18+
In order to automatically export data from OpenTelemetry to the OpenTelemetry collector, installing the
19+
package will setup all the required entry points.
20+
21+
.. code:: sh
22+
23+
$ pip install opentelemetry-distro[otlp] opentelemetry-instrumentation
24+
25+
Start the Collector locally to see data being exported. Write the following file:
26+
27+
.. code-block:: yaml
28+
29+
# /tmp/otel-collector-config.yaml
30+
receivers:
31+
otlp:
32+
protocols:
33+
grpc:
34+
http:
35+
exporters:
36+
logging:
37+
loglevel: debug
38+
processors:
39+
batch:
40+
service:
41+
pipelines:
42+
traces:
43+
receivers: [otlp]
44+
exporters: [logging]
45+
processors: [batch]
46+
47+
Then start the Docker container:
48+
49+
.. code-block:: sh
50+
51+
docker run -p 4317:4317 \
52+
-v /tmp/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
53+
otel/opentelemetry-collector:latest \
54+
--config=/etc/otel-collector-config.yaml
55+
56+
The following code will create a span with no configuration.
57+
58+
.. code:: python
59+
60+
# no_configuration.py
61+
from opentelemetry import trace
62+
63+
with trace.get_tracer(__name__).start_as_current_span("foo"):
64+
with trace.get_tracer(__name__).start_as_current_span("bar"):
65+
print("baz")
66+
67+
Lastly, run the ``no_configuration.py`` with the auto-instrumentation:
68+
69+
.. code-block:: sh
70+
71+
$ opentelemetry-instrument python no_configuration.py
72+
73+
The resulting span will appear in the output from the collector and look similar to this:
74+
75+
.. code-block:: sh
76+
77+
Resource labels:
78+
-> telemetry.sdk.language: STRING(python)
79+
-> telemetry.sdk.name: STRING(opentelemetry)
80+
-> telemetry.sdk.version: STRING(1.1.0)
81+
-> service.name: STRING(unknown_service)
82+
InstrumentationLibrarySpans #0
83+
InstrumentationLibrary __main__
84+
Span #0
85+
Trace ID : db3c99e5bfc50ef8be1773c3765e8845
86+
Parent ID : 0677126a4d110cb8
87+
ID : 3163b3022808ed1b
88+
Name : bar
89+
Kind : SPAN_KIND_INTERNAL
90+
Start time : 2021-05-06 22:54:51.23063 +0000 UTC
91+
End time : 2021-05-06 22:54:51.230684 +0000 UTC
92+
Status code : STATUS_CODE_UNSET
93+
Status message :
94+
Span #1
95+
Trace ID : db3c99e5bfc50ef8be1773c3765e8845
96+
Parent ID :
97+
ID : 0677126a4d110cb8
98+
Name : foo
99+
Kind : SPAN_KIND_INTERNAL
100+
Start time : 2021-05-06 22:54:51.230549 +0000 UTC
101+
End time : 2021-05-06 22:54:51.230706 +0000 UTC
102+
Status code : STATUS_CODE_UNSET
103+
Status message :
104+

docs/getting_started/otlpcollector_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
span_exporter = OTLPSpanExporter(
2626
# optional
27-
# endpoint:="myCollectorURL:4317",
27+
# endpoint="myCollectorURL:4317",
2828
# credentials=ChannelCredentials(credentials),
2929
# headers=(("metadata", "metadata")),
3030
)

opentelemetry-distro/README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Installation
1414
pip install opentelemetry-distro
1515

1616

17-
This package provides entrypoints to configure OpenTelemetry
17+
This package provides entrypoints to configure OpenTelemetry.
1818

1919
References
2020
----------
2121

2222
* `OpenTelemetry Project <https://opentelemetry.io/>`_
23+
* `Example using opentelemetry-distro <https://opentelemetry-python.readthedocs.io/en/latest/examples/distro/README.html>`_

0 commit comments

Comments
 (0)