Skip to content

Commit 39c02b1

Browse files
committed
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 6c34f54 commit 39c02b1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/elasticotel/distro/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,17 @@ def log_env_vars(self):
100100
for k, v in os.environ.items()
101101
if k.startswith("OTEL_") or k.startswith("ELASTIC_OTEL_")
102102
]
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)
103110
logger.info("EDOT Configuration")
104111
for k, v in sorted(env_vars):
105112
logger.info("%s: %s", k, v)
113+
logger.handlers.remove(handler)
106114

107115
def _handle_logging(self):
108116
# 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)