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"
2
2
AUTH__JWKS_URL : " http://oathkeeper:4456/.well-known/jwks.json"
3
3
# DRAMATIQ__REDIS_URL: "redis://redis:6379/0"
4
4
OTEL_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:
17
17
18
18
service :
19
19
pipelines :
20
+ logs :
21
+ receivers : [otlp]
22
+ processors : []
23
+ exporters : [debug]
20
24
metrics :
21
25
receivers : [otlp]
26
+ processors : []
22
27
exporters : [debug]
23
28
traces :
24
29
receivers : [otlp]
Original file line number Diff line number Diff line change 2
2
from typing import List
3
3
4
4
import structlog
5
+ from opentelemetry .sdk ._logs import LoggingHandler
5
6
from structlog .typing import Processor
6
7
7
8
from ..config import AppConfig
@@ -76,9 +77,18 @@ def init_logger(config: AppConfig) -> None:
76
77
)
77
78
)
78
79
79
- # Use structlog to format logs coming from stdlib logger
80
+ # Get root logger
80
81
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
82
92
stdlib_logger .addHandler (stdlib_handler )
83
93
stdlib_logger .setLevel (log_level )
84
94
You can’t perform that action at this time.
0 commit comments