feat: app-level instrumentation#236
Open
LucasAlvesSoares wants to merge 9 commits into
Open
Conversation
LucasAlvesSoares
marked this pull request as ready for review
July 21, 2026 08:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Introduces a library instrumentation layer to the SDK's telemetry module. Instead of relying solely on framework-level auto-instrumentation, the SDK now instruments common HTTP clients, web frameworks, and data libraries directly, ensuring spans are created and baggage/context is propagated correctly regardless of how the service is deployed.
The implementation follows an extensible registry pattern:
LibraryInstrumentor— abstract base class withinstrument(),uninstrument(), andis_instrumented(). The public methods handle guards (library not installed, already instrumented); subclasses only implement the inner logic._registry— a module-level list. Any code (including third-party contributors) can callregister()to add a new instrumentor.instrumentors/— one file per library. Each file creates an instrumentor instance and callsregister()at module load time.auto_instrument()— now calls all registered instrumentors after the tracer provider is initialized.Libraries instrumented out of the box:
httpx,requests,grpciostarlette,fastapi[starlette],[fastapi]aiohttp[aiohttp]sqlalchemy,redis[sqlalchemy],[redis]django,flask[django],[flask]The OTEL contrib instrumentation packages (
opentelemetry-instrumentation-*) are hard dependencies — they are always installed with the SDK. The target frameworks remain optional extras, as they are today.Adding a new instrumentor requires only creating a single file in
instrumentors/and callingregister()— no other changes needed.Type of Change
How to Test
pip install sap-cloud-sdk[starlette]auto_instrument()at application startuphttpxorrequests, or serve an inbound request via Starlette/FastAPI/Django/Flaskstarlette) and verify startup does not raiseImportErrorChecklist
Additional Notes
The
grpcioinstrumentor instruments both client and server interceptors (GrpcInstrumentorClientandGrpcInstrumentorServer) since the same package is used for both roles.All
opentelemetry-instrumentation-*packages are pinned with~=0.63b1, the same compatible-release style used for the existing OTEL exporters