Skip to content

perf: hoist OTel import in tracer_injection to module level#83

Merged
lesnik512 merged 1 commit intomainfrom
fix/tracer-injection-module-import
May 2, 2026
Merged

perf: hoist OTel import in tracer_injection to module level#83
lesnik512 merged 1 commit intomainfrom
fix/tracer-injection-module-import

Conversation

@lesnik512
Copy link
Copy Markdown
Member

tracer_injection runs once per log line. The previous in-function try / from opentelemetry import trace / except ImportError paid the try-machinery and import-lookup cost on every call, even though import_checker.is_opentelemetry_installed already settles the question at startup. Move the import into a module-level guard parallel to the existing is_structlog_installed block, defining a no-op fallback tracer_injection in the else branch for environments without OTel.

tracer_injection runs once per log line. The previous in-function
`try / from opentelemetry import trace / except ImportError` paid the
try-machinery and import-lookup cost on every call, even though
import_checker.is_opentelemetry_installed already settles the question
at startup. Move the import into a module-level guard parallel to the
existing is_structlog_installed block, defining a no-op fallback
tracer_injection in the else branch for environments without OTel.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@lesnik512 lesnik512 self-assigned this May 2, 2026
@lesnik512 lesnik512 merged commit 7717b7b into main May 2, 2026
7 checks passed
@lesnik512 lesnik512 deleted the fix/tracer-injection-module-import branch May 2, 2026 15:27
@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
lite_bootstrap/instruments/logging_instrument.py 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant