Repository navigation
Python adapter: report test runs as environment test, and detect the running commit and release - #56
Merged
Merged
Conversation
…ing commit and release init_tracing() now fills in resource attributes the service did not set: - deployment.environment=test under pytest or Django's `manage.py test`, only when the resource has neither deployment.environment.name nor deployment.environment. Off with AUTTER_DETECT_TEST_ENV=false or init_tracing(detect_test_env=False). Logs one info line when it applies. - deployment.commit from the first of AUTTER_COMMIT, GIT_SHA, GIT_COMMIT, COMMIT_SHA, SOURCE_COMMIT, VERCEL_GIT_COMMIT_SHA, GITHUB_SHA, RENDER_GIT_COMMIT, RAILWAY_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, HEROKU_SLUG_COMMIT, SOURCE_VERSION holding 7-40 hex characters. Environment variables only, never git. - service.version, when absent, from AUTTER_RELEASE, else the full commit. Off with AUTTER_DETECT_RELEASE=false or init_tracing(detect_release=False). Applied before the request-count meter provider's resource is derived, so request counts carry the same environment, commit and release as spans. RedactingSpanExporter marks SERVER spans whose raw user agent is exactly `testclient` or whose host is exactly `testserver` with autter.test_client=true, read before the user agent is dropped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…int only Commit variables are now tried in the order runtime-node and the source-map CLI use: AUTTER_COMMIT, GITHUB_SHA, VERCEL_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, GIT_SHA, GIT_COMMIT, COMMIT_SHA, SOURCE_COMMIT, RENDER_GIT_COMMIT, RAILWAY_GIT_COMMIT_SHA, HEROKU_SLUG_COMMIT, SOURCE_VERSION. Same rules: trimmed, 7-40 hex, invalid values skipped. The autter.test_client comment now says it is a hint that nothing may act on (a caller can send any user agent or host); the environment comes from the process alone. A test checks a test-client request outside a test run leaves the environment unset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sagnik11
added a commit
that referenced
this pull request
Nov 15, 2026
…ommit detection, test environments and queue helpers (#57) - @autter/runtime-next/client: initAutterBrowser turns on same-origin trace propagation by default (tracePropagation: false opts out; tracePropagationTargets adds cross-origin APIs). Third-party origins and the tracker's own endpoint never get a traceparent. Does nothing outside a browser. An enableTracePropagation/disableTracePropagation call made before initAutterBrowser keeps its effect. Plain @autter/runtime-browser stays opt-in; its dist is unchanged. - runtime-cli: `sourcemaps setup` prints the trace propagation step (with the CORS note) for browser setups. - runtime-node: log records' resource carries deployment.commit, like the trace resource, for initAutterServer and initAutterLogging. Added in the OTLP log sink, so runtime-core's encoder (shared with runtime-edge) and runtime-edge's dist stay unchanged. - Docs: Getting started (release/commit defaults, enableTracePropagation, test runs), Integrations (FastAPI and Django CORS, Python detection and opt-outs), Requests and errors, Architecture (sink `commit`), package READMEs. CHANGELOG [Unreleased] for #53-#56 and this change. Co-authored-by: Claude Opus 5.5 <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.
What users saw
manage.py test) that ran with Autter tracing on, and with no environment configured, reported its errors and request counts asproduction. Test failures showed up next to real production issues.TestClientcarried nothing that said "test client": the user agenttestclientthat would have told is dropped by the adapter's privacy filter (since 1.19.0) before the spans leave the process, so the ingester cannot see it either.Cause
init_tracing()usedResource.create()as it was: nothing detected a test run, the running commit or a release.What changes (all in
adapters/python/autter_tracing.py)init_tracing()fills in resource attributes the service did not set. An explicit value always wins, fromOTEL_RESOURCE_ATTRIBUTESor a passedresource=.PYTEST_VERSIONorPYTEST_CURRENT_TESTset, orpytestimported) or Django'smanage.py test, a resource with neitherdeployment.environment.namenordeployment.environmentgetsdeployment.environment=test. One info line is logged when this applies. Turn it off withAUTTER_DETECT_TEST_ENV=falseorinit_tracing(detect_test_env=False).RedactingSpanExporteraddsautter.test_client=trueto SERVER spans whose raw user agent (http.user_agent/user_agent.original) is exactlytestclient, or whose host (server.address,net.host.name,http.host,http.server_name) is exactlytestserver. It reads them before the identifying-attribute drop, and the user agent is still dropped. The attribute keys come from real recordings: FastAPITestClientwith the ASGI instrumentation in the old, stable and dup HTTP conventions, and Django's testClient. Limit: in the stable HTTP conventions, Django's instrumentation records no host, so a Django test-client request is not marked there. Themanage.py testenvironment detection still covers that case. The mark is a hint for people reading the trace only: a caller can send any user agent or host, so nothing (alerting, paging, the environment) may act on it. The environment is decided from the process alone (pytest,manage.py test), never from a request.deployment.commitis set from the first ofAUTTER_COMMIT, GITHUB_SHA, VERCEL_GIT_COMMIT_SHA, CF_PAGES_COMMIT_SHA, GIT_SHA, GIT_COMMIT, COMMIT_SHA, SOURCE_COMMIT, RENDER_GIT_COMMIT, RAILWAY_GIT_COMMIT_SHA, HEROKU_SLUG_COMMIT, SOURCE_VERSION(the order runtime-node and the source-map CLI use) that holds 7 to 40 hexadecimal characters (lower-cased). An invalid value is skipped and the next variable is tried. Only environment variables are read: no git, no subprocess.service.versionis absent, it is set toAUTTER_RELEASE, else to the commit (the full SHA). If an explicitdeployment.commitis set, the release defaults to that commit. Turn this off withAUTTER_DETECT_RELEASE=falseorinit_tracing(detect_release=False). Behaviour change: a service with no release now reports its commit as the release.testand carry the same commit and release.New public names:
TEST_CLIENT_ATTRIBUTE,COMMIT_ENV_VARS,detect_commit(),detect_test_runner(). Newinit_tracing()keyword arguments:detect_test_env,detect_release.Tests: new
adapters/python/test_deployment_detection.pycovers runner detection and near misses, explicit-environment precedence, both opt-outs for each feature, commit variable order and hex validation, release precedence, metric resource parity, the test-client mark and its near misses, and a real childpytestrun. Every test there sets the variables it needs and clears the rest, so the suite gives the same results under unittest, under pytest, and on CI whereGITHUB_SHAis set.pytestis added torequirements-test.txtfor the child-run check. The suite itself still runs under unittest and never imports pytest in its own process. Run locally on opentelemetry-sdk 1.45 / Python 3.14 and 1.20 / Python 3.9, under unittest and pytest, and with the stdlib only.Docs and changelog are left for the docs PR (RT-E).
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.