Skip to content

Commit 7a39e1b

Browse files
xrmxtheletterfvitorvasctammy-baylis-swi
authored
content/en: updated Python log instrumentation docs (#9320)
Co-authored-by: Fabrizio Ferri-Benedetti <[email protected]> Co-authored-by: Vitor Vasconcellos <[email protected]> Co-authored-by: Tammy Baylis <[email protected]>
1 parent 3fae58d commit 7a39e1b

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

content/en/blog/2024/otel-generative-ai/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
131131
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
132132
OTEL_SERVICE_NAME=python-opentelemetry-openai
133133
OTEL_LOGS_EXPORTER=otlp_proto_http
134-
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
135134
# Set to false or remove to disable log events
136135
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true
137136
```

content/en/docs/languages/python/getting-started.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ it print to the console for now:
130130
{{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
131131

132132
```shell
133-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
134133
opentelemetry-instrument \
135134
--traces_exporter console \
136135
--metrics_exporter console \
@@ -142,7 +141,6 @@ opentelemetry-instrument \
142141
{{% /tab %}} {{% tab "Windows (PowerShell)" %}}
143142

144143
```powershell
145-
$env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
146144
opentelemetry-instrument `
147145
--traces_exporter console `
148146
--metrics_exporter console `
@@ -362,7 +360,6 @@ Now run the app again:
362360
{{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
363361

364362
```shell
365-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
366363
opentelemetry-instrument \
367364
--traces_exporter console \
368365
--metrics_exporter console \
@@ -374,7 +371,6 @@ opentelemetry-instrument \
374371
{{% /tab %}} {{% tab "Windows (PowerShell)" %}}
375372

376373
```powershell
377-
$env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
378374
opentelemetry-instrument `
379375
--traces_exporter console `
380376
--metrics_exporter console `
@@ -525,7 +521,6 @@ Now run the app again:
525521
{{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
526522

527523
```shell
528-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
529524
opentelemetry-instrument \
530525
--traces_exporter console \
531526
--metrics_exporter console \
@@ -537,7 +532,6 @@ opentelemetry-instrument \
537532
{{% /tab %}} {{% tab "Windows (PowerShell)" %}}
538533

539534
```powershell
540-
$env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
541535
opentelemetry-instrument `
542536
--traces_exporter console `
543537
--metrics_exporter console `
@@ -798,14 +792,12 @@ Run the application like before, but don't export to the console:
798792
{{< tabpane text=true >}} {{% tab "Linux/macOS" %}}
799793

800794
```shell
801-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
802795
opentelemetry-instrument --logs_exporter otlp flask run -p 8080
803796
```
804797

805798
{{% /tab %}} {{% tab "Windows (PowerShell)" %}}
806799

807800
```powershell
808-
$env:OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true"
809801
opentelemetry-instrument --logs_exporter otlp flask run -p 8080
810802
```
811803

content/en/docs/platforms/kubernetes/operator/troubleshooting/automatic.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ Containers:
171171
OTEL_POD_IP: (v1:status.podIP)
172172
OTEL_METRICS_EXPORTER: console,otlp_proto_http
173173
OTEL_LOGS_EXPORTER: otlp_proto_http
174-
OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED: true
175174
PYTHONPATH: /otel-auto-instrumentation-python/opentelemetry/instrumentation/auto_instrumentation:/otel-auto-instrumentation-python
176175
OTEL_TRACES_EXPORTER: otlp
177176
OTEL_EXPORTER_OTLP_TRACES_PROTOCOL: http/protobuf

content/en/docs/zero-code/python/configuration.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,28 @@ outputted.
119119
logging format
120120
- `OTEL_PYTHON_LOG_LEVEL`: to set a custom log level (info, error, debug,
121121
warning)
122-
- `OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED`: to enable
123-
auto-instrumentation of logs. Attaches OTLP handler to Python root logger. For
124-
an example, see
125-
[Logs Auto-Instrumentation](/docs/zero-code/python/logs-example/).
122+
- `OTEL_PYTHON_LOG_AUTO_INSTRUMENTATION`: controls whether the logging handler
123+
is configured automatically (true, false), enabled by default. Refer to
124+
[Logs Auto-Instrumentation](/docs/zero-code/python/logs-example/)
125+
- `OTEL_PYTHON_LOG_CODE_ATTRIBUTES`: to enable addition of `code` attributes
126+
(`code.file.path`, `code.function.name`, `code.line.number`) to the logs
127+
(true, false)
126128

127129
Examples:
128130

129131
```sh
130132
export OTEL_PYTHON_LOG_CORRELATION=true
131133
export OTEL_PYTHON_LOG_FORMAT="%(msg)s [span_id=%(span_id)s]"
132134
export OTEL_PYTHON_LOG_LEVEL=debug
133-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
135+
export OTEL_PYTHON_LOG_AUTO_INSTRUMENTATION=false
136+
export OTEL_PYTHON_LOG_CODE_ATTRIBUTES=true
134137
```
135138

139+
> Before OpenTelemetry Python 1.40.0 logs auto instrumentation was disabled by
140+
> default and implemented in the `opentelemetry-sdk` package. Setting
141+
> `OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED` to `true` would have
142+
> enabled it.
143+
136144
### Other
137145

138146
There are some more configuration options that can be set that don't fall into a

content/en/docs/zero-code/python/logs-example.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ which provides several commands that help automatically instrument a program.
7575
```sh
7676
pip install opentelemetry-distro
7777
pip install opentelemetry-exporter-otlp
78+
pip install opentelemetry-instrumentation-logging
7879
```
7980

8081
The examples that follow send instrumentation results to the console. Learn more
@@ -111,7 +112,6 @@ Open up another terminal and run the Python program:
111112
```sh
112113
source python_logs_example/bin/activate
113114

114-
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
115115
opentelemetry-instrument \
116116
--traces_exporter console,otlp \
117117
--metrics_exporter console,otlp \
@@ -120,6 +120,9 @@ opentelemetry-instrument \
120120
python $(pwd)/example.py
121121
```
122122

123+
> Prior to OpenTelemetry Python 1.40.0 you had to enable log instrumentation
124+
> with `export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true`
125+
123126
Sample output:
124127

125128
```text

0 commit comments

Comments
 (0)