@@ -18,6 +18,11 @@ Ensure that you have the following installed locally:
1818
1919- [ Python 3] ( https://www.python.org/ )
2020
21+ > [ !NOTE]
22+ >
23+ > On Windows, Python is typically invoked using ` python ` rather than ` python3 ` .
24+ > The following examples show the correct commands for your operating system.
25+
2126## Example Application
2227
2328The following example uses a basic [ Flask] ( https://flask.palletsprojects.com/ )
@@ -32,13 +37,26 @@ For more elaborate examples, see [examples](/docs/languages/python/examples/).
3237
3338To begin, set up an environment in a new directory:
3439
40+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
41+
3542``` shell
3643mkdir otel-getting-started
3744cd otel-getting-started
3845python3 -m venv venv
3946source ./venv/bin/activate
4047```
4148
49+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
50+
51+ ``` powershell
52+ mkdir otel-getting-started
53+ cd otel-getting-started
54+ python -m venv venv
55+ .\venv\Scripts\Activate.ps1
56+ ```
57+
58+ {{% /tab %}} {{< /tabpane >}}
59+
4260Now install Flask:
4361
4462``` shell
@@ -109,6 +127,8 @@ This will install Flask instrumentation.
109127You can now run your instrumented app with ` opentelemetry-instrument ` and have
110128it print to the console for now:
111129
130+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
131+
112132``` shell
113133export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
114134opentelemetry-instrument \
@@ -119,6 +139,20 @@ opentelemetry-instrument \
119139 flask run -p 8080
120140```
121141
142+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
143+
144+ ``` powershell
145+ $env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
146+ opentelemetry-instrument `
147+ --traces_exporter console `
148+ --metrics_exporter console `
149+ --logs_exporter console `
150+ --service_name dice-server `
151+ flask run -p 8080
152+ ```
153+
154+ {{% /tab %}} {{< /tabpane >}}
155+
122156Open < http://localhost:8080/rolldice > in your web browser and reload the page a
123157few times. After a while you should see the spans printed in the console, such
124158as the following:
@@ -325,6 +359,8 @@ def roll():
325359
326360Now run the app again:
327361
362+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
363+
328364``` shell
329365export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
330366opentelemetry-instrument \
@@ -335,6 +371,20 @@ opentelemetry-instrument \
335371 flask run -p 8080
336372```
337373
374+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
375+
376+ ``` powershell
377+ $env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
378+ opentelemetry-instrument `
379+ --traces_exporter console `
380+ --metrics_exporter console `
381+ --logs_exporter console `
382+ --service_name dice-server `
383+ flask run -p 8080
384+ ```
385+
386+ {{% /tab %}} {{< /tabpane >}}
387+
338388When you send a request to the server, you'll see two spans in the trace emitted
339389to the console, and the one called ` roll ` registers its parent as the
340390automatically created one:
@@ -472,6 +522,8 @@ def roll():
472522
473523Now run the app again:
474524
525+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
526+
475527``` shell
476528export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
477529opentelemetry-instrument \
@@ -482,6 +534,20 @@ opentelemetry-instrument \
482534 flask run -p 8080
483535```
484536
537+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
538+
539+ ``` powershell
540+ $env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
541+ opentelemetry-instrument `
542+ --traces_exporter console `
543+ --metrics_exporter console `
544+ --logs_exporter console `
545+ --service_name dice-server `
546+ flask run -p 8080
547+ ```
548+
549+ {{% /tab %}} {{< /tabpane >}}
550+
485551When you send a request to the server, you'll see the roll counter metric
486552emitted to the console, with separate counts for each roll value:
487553
@@ -656,11 +722,12 @@ collector in production deployments.
656722
657723### Configure and run a local collector
658724
659- First, save the following collector configuration code to a file in the ` /tmp/ `
660- directory:
725+ First, save the following collector configuration code to a file. On
726+ Linux/macOS, save it to ` /tmp/otel-collector-config.yaml ` . On Windows, save it
727+ to ` $env:TEMP\otel-collector-config.yaml ` :
661728
662729``` yaml
663- # /tmp/ otel-collector-config.yaml
730+ # otel-collector-config.yaml
664731receivers :
665732 otlp :
666733 protocols :
@@ -688,13 +755,26 @@ service:
688755Then run the docker command to acquire and run the collector based on this
689756configuration:
690757
758+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
759+
691760` ` ` shell
692761docker run -p 4317:4317 \
693762 -v /tmp/otel-collector-config.yaml:/etc/otel-collector-config.yaml \
694763 otel/opentelemetry-collector:latest \
695764 --config=/etc/otel-collector-config.yaml
696765```
697766
767+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
768+
769+ ``` powershell
770+ docker run -p 4317:4317 `
771+ -v "${env:TEMP}\otel-collector-config.yaml:/etc/otel-collector-config.yaml" `
772+ otel/opentelemetry-collector:latest `
773+ --config=/etc/otel-collector-config.yaml
774+ ```
775+
776+ {{% /tab %}} {{< /tabpane >}}
777+
698778You will now have an collector instance running locally, listening on port 4317.
699779
700780### Modify the command to export spans and metrics via OTLP
@@ -715,11 +795,22 @@ and default to OTLP export when it's run next.
715795
716796Run the application like before, but don't export to the console:
717797
798+ {{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
799+
718800``` shell
719801export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
720802opentelemetry-instrument --logs_exporter otlp flask run -p 8080
721803```
722804
805+ {{% /tab %}} {{% tab "Windows (PowerShell)" %}}
806+
807+ ``` powershell
808+ $env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
809+ opentelemetry-instrument --logs_exporter otlp flask run -p 8080
810+ ```
811+
812+ {{% /tab %}} {{< /tabpane >}}
813+
723814By default, ` opentelemetry-instrument ` exports traces and metrics over OTLP/gRPC
724815and will send them to ` localhost:4317 ` , which is what the collector is listening
725816on.
0 commit comments