feat: bootstrap and runtime_context#237
Draft
LucasAlvesSoares wants to merge 18 commits into
Draft
Conversation
# Conflicts: # pyproject.toml
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
sap_cloud_sdk.core.runtime_context— a provider-agnostic runtime context system that lets SDK modules (auditlog, telemetry, and future modules) read caller-identity information (tenant, user, trigger type) without coupling to a specific auth provider or HTTP framework.Key design decisions:
RuntimeContextis an immutable typed bag keyed byContextKey[T]instances — no fixed fields, fully extensible by any module defining its own keys.ContextProviderprotocol separates extraction logic (IAS JWT, SAP headers) from framework concerns.RequestEnvelopeis a framework-agnostic carrier (headers, body, metadata) that providers read from — they never touch Starlette, Flask, or gRPC types directly.FrameworkAdapterregistry decouplesbootstrap()from framework-specific code — new frameworks are added by registering an adapter, never by editingbootstrap.bootstrap(app)is the single user-facing entry point, exposed atsap_cloud_sdk.bootstrap.Built-in providers:
IASContextProvider(IAS JWT → tenant/user) andHeaderContextProvider(x-sap-origin→ trigger type).Built-in adapter: Starlette/FastAPI.
Type of Change
How to Test
Authorizationheader,get_context()returns an emptyRuntimeContextand all keys returnNone.Checklist
Additional Notes
sdk_context,async_sdk_context, andset_contextare intentionally not exported from the public API — they are internal utilities used by framework middleware.FrameworkAdapterregistry andContextProviderprotocol are both exported for third-party extensibility.bootstrapwill absorbauto_instrument()once theapp-level-instrumentationbranch lands, making it the single SDK setup call.