diff --git a/.changelog/5344.changed b/.changelog/5344.changed new file mode 100644 index 00000000000..f99bd173f92 --- /dev/null +++ b/.changelog/5344.changed @@ -0,0 +1 @@ +docs: update logs example to use `opentelemetry-instrumentation-logging` diff --git a/docs/examples/logs/README.rst b/docs/examples/logs/README.rst index 6edebf6e064..2e3c749c7ba 100644 --- a/docs/examples/logs/README.rst +++ b/docs/examples/logs/README.rst @@ -8,6 +8,26 @@ OpenTelemetry Logs SDK The source files of these examples are available :scm_web:`here `. +.. note:: + + ``LoggingHandler`` has moved from the SDK to the + ``opentelemetry-instrumentation-logging`` package in the contrib repo + and is deprecated 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 diff --git a/docs/examples/logs/example.py b/docs/examples/logs/example.py index 08d04e90ac7..0c8b1dd06bb 100644 --- a/docs/examples/logs/example.py +++ b/docs/examples/logs/example.py @@ -48,6 +48,9 @@ # Create different namespaced loggers # It is recommended to not use the root logger with OTLP handler # so telemetry is collected only for the application +# Logger.propagate is True by default, ensure it is not set to False so log +# records reach the root logger handler. See +# https://docs.python.org/3/library/logging.html#logging.Logger.propagate logger1 = logging.getLogger("myapp.area1") logger2 = logging.getLogger("myapp.area2")