Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/5344.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs: update logs example to use `opentelemetry-instrumentation-logging`
20 changes: 20 additions & 0 deletions docs/examples/logs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ OpenTelemetry Logs SDK

The source files of these examples are available :scm_web:`here <docs/examples/logs/>`.

.. note::

``LoggingHandler`` has moved from the SDK to the
``opentelemetry-instrumentation-logging`` package in the contrib repo
and is no longer available in ``opentelemetry-sdk``.


Installation
------------

.. code-block:: sh

pip install opentelemetry-api
pip install opentelemetry-sdk
pip install opentelemetry-exporter-otlp-proto-grpc
pip install opentelemetry-instrumentation-logging

Run the Example
---------------

Start the Collector locally to see data being exported. Write the following file:

.. code-block:: yaml
Expand Down
4 changes: 4 additions & 0 deletions docs/examples/logs/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
logger1 = logging.getLogger("myapp.area1")
logger2 = logging.getLogger("myapp.area2")

# Ensure log records propagate to root logger so the handler picks them up

@xrmx xrmx Jun 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these really needed? Would be nice to test the examples

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this end to end with the collector, all 6 log records came through fine. I have added the explicit propagate=True based on this from #4738:

only the root logger is instrumented, so seen loggers must have propagate set to True

if you are loading logging settings with logging/.config.dictConfig, you must save the root loggers before applying dictConfig

Also tested locally that dictConfig with a root section does wipe the OTel handler completely. The explicit assignment is hence there as a reminder for users who might use dictConfig. Also happy to just keep it as a comment if you prefer.

logger1.propagate = True
logger2.propagate = True

logger1.debug("Quick zephyrs blow, vexing daft Jim.")
logger1.info("How quickly daft jumping zebras vex.")
logger2.warning("Jail zesty vixen who grabbed pay from quack.")
Expand Down