Repository navigation
feat(observability): OpenTelemetry tracing for the API and the sandbox manager (#489) - #494
Merged
Merged
Conversation
ArthurCRodrigues
force-pushed
the
feat/489
branch
from
November 21, 2026 22:58
12b365d to
1f6a51b
Compare
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
…x manager (#489) Tracing is off unless OTEL_EXPORTER_OTLP_ENDPOINT is set; then each service exports OTLP/HTTP spans batched in the background, configured by the standard OTEL_* variables (OTEL_SERVICE_NAME defaults to SERVICE_NAME, sampler parentbased_always_on). - FastAPI instrumentation in both services continues an incoming W3C traceparent; the sandbox client sends its own (client spans named by the control API's route template). The API also traces SQLAlchemy statements (placeholders only) and the AI provider's httpx calls. A client span never starts a trace, so the idle worker's polls produce none. Probes are not traced. - Spans never carry raw paths, query strings, URLs, client addresses or exception messages: a redacting exporter keeps the route template and the exception type. - Migration 012 stores the accepting request's X-Request-ID and its span's traceparent on the submission. Each grading attempt is its own trace, rooted at grading.attempt and linked to that span; its log lines carry the accepting request id plus attempt_id. Adoption of create_all databases expects 012's columns absent. - Log lines carry trace_id/span_id while a span is active. - opentelemetry-api becomes a base dependency (the sandbox client propagates context); the SDK, exporter and instrumentations live in the sandbox and server extras.
…ew (#489) - Spans no longer export error messages through the status description (SDK, FastAPI and SQLAlchemy put "<type>: <message>" there): the redactor keeps the status code only, and the attempt and sandbox client spans record errors by type. Spans that need no redaction are exported unchanged. - Only W3C trace context is propagated (never baggage), so a caller's baggage cannot reach the AI provider. - A sandbox 4xx is a handled answer, not a failed span; grading.attempt records its outcome status and published error code. - Both lifespans export the remaining batched spans after the drain. - service.name from OTEL_RESOURCE_ATTRIBUTES is honoured; OTEL_SERVICE_NAME is read by the SDK only. - Module-level sampler and exporter classes, one tracer per provider, one unmatched-route constant, adoption reports unexpected columns as text. - Tests: tracing is off suite-wide unless a test turns it on, the create_app wiring, API probes, httpx spans, sampler overrides, unsampled and invalid caller contexts, retries, every control route's template, migration 012 on existing rows. - Docs: one Logs and traces section for both services, what request_id now groups for log consumers, the 012 rollout order.
…wnership (#489) - Rolling back runs downgrade 011 with this release's image before the previous image starts: the previous image neither knows revision 012 nor serves a database past its head. - record_attempt_outcome lives with the API's tracing; the API lifespan calls shutdown_api_tracing, which also removes the process-wide httpx and SQLAlchemy instrumentation. - The redactor always copies: one set of rules, no parallel predicate. - The tracing_setup docstring names service.name in OTEL_RESOURCE_ATTRIBUTES and the tracecontext-only propagation.
ArthurCRodrigues
force-pushed
the
feat/489
branch
from
November 21, 2026 23:07
1f6a51b to
fca2cdc
Compare
ArthurCRodrigues
approved these changes
Nov 21, 2026
ArthurCRodrigues
added a commit
that referenced
this pull request
Nov 21, 2026
Conflicts with the tracing change (#494): CHANGELOG.md (both entries), pyproject.toml and uv.lock (both dependency sets, lock regenerated with uv lock), sandbox_manager/api.py (tracing instrumentation, then the metrics middleware), web/service/worker.py (both recordings of the attempt outcome). tests/unit/sandbox/test_tracing.py: the control API now has GET /metrics, which the remote client never calls, so the route template check skips it like /health. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Closes #489
Part of webtech-network/prisma-infrastructure#92
Stacked on #490 (#487, structured JSON logs). Review this PR's own commits; the base is
feat/487.What
OpenTelemetry tracing for
autograder-apiandautograder-sandbox-manager. Tracing is off unlessOTEL_EXPORTER_OTLP_ENDPOINTis set (it is a no-op in tests). When on, each service exports OTLP over HTTP/protobuf, batched in a background thread. The standardOTEL_*variables apply; the service name defaults toSERVICE_NAME.traceparent. The requests-based sandbox client sends its owntraceparentfrom client spans named by the control API's route template. Only W3C trace context is propagated;baggageis never read or forwarded./metricsare not traced."<type>: <message>". Server spans keep the route template; errors keep their type only.012): each submission stores the accepting request'sX-Request-IDand its acceptance span'straceparent(when sampled). Each grading attempt is its own trace, rooted atgrading.attempt, which links to that acceptance span and records the outcome status and published error code.trace_id/span_idwhile a span context is active. During an attempt,request_idis the accepting request's id, plus anattempt_idfield.opentelemetry-apibecomes a base dependency, because the Action image imports the sandbox client. The SDK, OTLP exporter and FastAPI instrumentation are in thesandboxextra; the SQLAlchemy and httpx instrumentations are in theserverextra.Changes that affect operators and log consumers
request_idsemantics change (log consumers, INF-1 Alloy, INF-3 dashboards): [Observability][AG-1] Sanitize Logs & Emit Structured JSON Logs fromautograder-sandbox-manager#487 used the attempt id as the worker'srequest_id. Nowrequest_idgroups a submission's acceptance and all its attempts. Isolate one attempt withattempt_id(API lines) ortrace_id(each attempt is its own trace, different from the accepting request's).012: runalembic -c web/alembic.ini upgrade headbefore starting this build. To roll back: stop the API, back up, rundowngrade 011with this image, then start the previous image.python -m web.database.schema adoptnow expects 012's columns to be absent (ADDED_AFTER_ADOPTION).OTEL_EXPORTER_OTLP_ENDPOINT=http://alloy:4318andOTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=<env>.The release (1.1.0 version bump) is a separate PR after #487, #488 and #489 merge; no tag is cut here.
Verification
tests/web -m postgres, including migrations and adoption): 35 passed.make contractsandmake docs(strict) pass. Pylint in a clean checkout: rc 0.tests/unit/sandbox/test_tracing.pyandtests/web/test_tracing.py(propagation, redaction including status, sampling, probes, httpx, DB spans without values, attempt links and retries,create_appwiring), the migration 012 test, and a suite-wide guard (tests/conftest.py) that keeps tracing off unless a test turns it on.🤖 Generated with Claude Code