perf: hoist OTel import in tracer_injection to module level by lesnik512 · Pull Request #83 · modern-python/lite-bootstrap · GitHub
Skip to content

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

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

perf: hoist OTel import in tracer_injection to module level#83
lesnik512 merged 1 commit into
mainfrom
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

codecov Bot commented May 2, 2026

Copy link
Copy Markdown

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