File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed
Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ ENVIRONMENT: "local"
22AUTH__JWKS_URL : " http://oathkeeper:4456/.well-known/jwks.json"
33# DRAMATIQ__REDIS_URL: "redis://redis:6379/0"
44OTEL_EXPORTER_OTLP_ENDPOINT : " http://otel-collector:4317"
5+ OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED : " true"
Original file line number Diff line number Diff line change @@ -17,8 +17,13 @@ processors:
1717
1818service :
1919 pipelines :
20+ logs :
21+ receivers : [otlp]
22+ processors : []
23+ exporters : [debug]
2024 metrics :
2125 receivers : [otlp]
26+ processors : []
2227 exporters : [debug]
2328 traces :
2429 receivers : [otlp]
Original file line number Diff line number Diff line change 22from typing import List
33
44import structlog
5+ from opentelemetry .sdk ._logs import LoggingHandler
56from structlog .typing import Processor
67
78from ..config import AppConfig
@@ -76,9 +77,18 @@ def init_logger(config: AppConfig) -> None:
7677 )
7778 )
7879
79- # Use structlog to format logs coming from stdlib logger
80+ # Get root logger
8081 stdlib_logger = logging .getLogger ()
81- stdlib_logger .handlers .clear ()
82+
83+ # In case there's a OTEL handler we keep it but remove all the others,
84+ # in case this function is called multiple times.
85+ # NOTE all the processors are not applied to OTEL logs!
86+ for l in stdlib_logger .handlers :
87+ if not isinstance (l , LoggingHandler ):
88+ stdlib_logger .removeHandler (l )
89+
90+
91+ # Use structlog to format logs coming from stdlib logger
8292 stdlib_logger .addHandler (stdlib_handler )
8393 stdlib_logger .setLevel (log_level )
8494
You can’t perform that action at this time.
0 commit comments