Repository navigation
tracing: propagate campus trace context on SDK calls - #93
Merged
Merged
Conversation
Instrument CampusRequest's requests.Session so calls made while the host app handles a traced request carry X-Request-ID / X-Parent-Span-ID and land as child spans in the campus audit pipeline (campus#816 item 1, #92). - New campus_python.tracing mirrors the propagation half of campus.audit.middleware.tracing: same headers, same flask.g contract (trace_id/span_id stashed by the middleware's before_request hook), same _campus_trace_instrumented idempotency marker so the two implementations never double-wrap. - Deliberately self-contained: the SDK must not import the server-side audit client stack to emit two headers. Calls outside a traced request context (startup, background threads) stay unparented. - Makes campus.api's existing session instrumentation redundant but compatible (idempotent across both implementations).
2 tasks
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.
Parent: nyjc-computing/campus#816 (item 1 — SDK trace propagation). Refs #92.
What
Instrument
CampusRequest'srequests.Sessionat construction so SDK calls made while the host app is handling a traced request carry campus trace context headers:X-Request-ID— the host request's trace id (32-hex)X-Parent-Span-ID— the host request's span id (16-hex)Receiving campus services already turn these into a child span of the caller's span (nyjc-computing/campus#794). Until now only campus.api's embedded client did this, via server-side instrumentation of the SDK session; with this change every host gets it for free, and campus.api's instrumentation becomes redundant-but-compatible (idempotent across both implementations via the shared
_campus_trace_instrumentedmarker).Design
New module
campus_python/tracing.pymirrors the propagation half ofcampus.audit.middleware.tracing:trace_id/span_id, stashed by the middleware'sbefore_requesthook).campus.common/campus.model), importingcampus.audit.middlewarewould pull the server-side audit client stack into every client construction just to emit two headers. The two modules cross-reference each other to control drift; if the contract grows (W3Ctraceparent), extraction into a shared home remains the longer-term option.Tests
tests/unit/test_trace_propagation.py(5 cases): headers present inside a traced request context; absent outside one; absent when the context has no span state (tracing off / middleware absent); caller-supplied headers take precedence (setdefault semantics); instrumentation is idempotent (construction-time, no double wrap). Full suite: 243 passed.E2E
Acceptance runs through classroom-as-producer (nyjc-computing/campus#816 item 2, nyjc-computing/campus-classroom#37): a classroom login should show auth calls as child spans of classroom requests in the audit waterfall.