Skip to content

Commit ef6f532

Browse files
authored
Try harder to dump the EDOT configuration at startup (#431)
* elasticotel/distro: accept warning also May be more mnemonic for people instead of warn. * docs: Drop stale note This is not true since 1.1.0 * elasticotel/distro: try harder to print the EDOT configuration at startup Since we rely on the instrumented application logging setup BUT: - by default the python root logger should be at WARNING level - the EDOT Configuration dump is at INFO level - at startup we don't have application logging already setup So we need to add a temporary logging handler just for printing our config
1 parent a379de5 commit ef6f532

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/reference/edot-python/configuration.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ Instrument Python `logging` module to format and forward logs in OTLP format is
115115
export OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true
116116
```
117117

118-
:::{note}
119-
Turning this on will make any call to [logging.basicConfig](https://docs.python.org/3/library/logging.html#logging.basicConfig) from your application a no-op.
120-
:::
121-
122118
#### Differences from OpenTelemetry Python
123119

124120
EDOT Python uses different defaults than OpenTelemetry Python for the following configuration options:

src/elasticotel/distro/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"debug": logging.DEBUG,
4242
"info": logging.INFO,
4343
"warn": logging.WARNING,
44+
"warning": logging.WARNING,
4445
"error": logging.ERROR,
4546
"fatal": logging.CRITICAL,
4647
"off": 1000,
@@ -99,9 +100,17 @@ def log_env_vars(self):
99100
for k, v in os.environ.items()
100101
if k.startswith("OTEL_") or k.startswith("ELASTIC_OTEL_")
101102
]
103+
# we rely on the application setting up logging and we don't want to interfere with that BUT:
104+
# - by default the python root logger should be at WARNING level
105+
# - the EDOT Configuration dump is at INFO level
106+
# - at startup we don't have application logging already setup
107+
# So we add a temporary handler just for printing our config
108+
handler = logging.StreamHandler()
109+
logger.addHandler(handler)
102110
logger.info("EDOT Configuration")
103111
for k, v in sorted(env_vars):
104112
logger.info("%s: %s", k, v)
113+
logger.handlers.remove(handler)
105114

106115
def _handle_logging(self):
107116
# do validation, we only validate logging_level because sampling_rate is handled by the sdk already

tests/integration/test_integration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ def test_script():
213213
self.assertFalse(telemetry["traces"])
214214
self.assertTrue(telemetry["logs"])
215215

216+
def test_configuration_dump_at_startup_with_info_level(self):
217+
def test_script():
218+
pass
219+
220+
env = {"OTEL_LOG_LEVEL": "info", "OTEL_ENV_VAR": "value"}
221+
stdout, stderr, returncode = self.run_script(
222+
test_script, environment_variables=env, wrapper_script="opentelemetry-instrument"
223+
)
224+
225+
assert "EDOT Configuration" in stderr
226+
assert "OTEL_LOG_LEVEL: info" in stderr
227+
assert "OTEL_ENV_VAR: value" in stderr
228+
216229

217230
@pytest.mark.integration
218231
class HTTPIntegrationTestCase(ElasticIntegrationHTTPTestCase):

0 commit comments

Comments
 (0)