Repository navigation
fix: drop the Anthropic SDK's URL query with capture_content off - #234
Merged
Merged
Conversation
In its content mode the anthropic SDK writes url.query and url.full with query parameters it treats as content, such as an email or path_prefix filter. On a span whose instrumentation scope starts with com.anthropic.sdk., the masking exporter now treats both as content: with capture_content off url.query is dropped and url.full keeps only its scheme, host and path; with a mask both run through it. Other spans' URLs are left alone.
…ntent off Drop url.full when it is not a string or nothing is left of it, matching the shared cases.
…old apart Strip userinfo before the query cut, and drop a url.full with an @ but no ://, an @ before it, or an authority with both an @ and a ? or #.
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.
In its content mode (
ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE=content),anthropic2.1.0 writes the call's query tourl.queryandurl.fullon its own API-call spans, including the query parameters it treats as content, such asemailorpath_prefix. Withcapture_content=Falsethese were exported in clear.The masking exporter now treats
url.queryandurl.fullas content on spans whose instrumentation scope starts withcom.anthropic.sdk., and on no other spans:capture_content=False,url.queryis dropped andurl.fullkeeps only its scheme, host and path (no query, fragment or userinfo). If it isn't a string or nothing is left, it is dropped;The keys come from
opentelemetry.semconv.attributes.url_attributes, re-exported fromrius.semconvlikeHTTP_RESPONSE_STATUS_CODE. The scope check reuses_native_spans.is_sdk_span.Tests:
masking.json, which gains an optionalscopethattest_sdk_cases.pynow applies.anthropic_native_span_run.pygains amemories_listcase:beta.memory_stores.memories.list(path_prefix=...)against the local server, which now answers GET with an empty page. With capture off, the native span has nourl.query,url.fullends at the path, and the prefix appears nowhere. A control with capture on shows that the SDK does write the query.masking.pychange, three shared cases and the end-to-end capture-off test fail (the SDK'surl.fullwas...memories?path_prefix=%2Fsecret-path-prefix%2F). The second commit's new shared cases (userinfo,?only=query) also failed before its change. With the changes, the full suite passes.Pinned to rius-semconv v1.9.2: the vendored module (its only change is the comment on
anthropic.tool_result.content) andtests/fixtures/semconv(SOURCE is the v1.9.2 commit, ebb29c2).A later commit hardens how userinfo is handled. Userinfo is removed before the query and fragment are cut.
url.fullis dropped when the host and the credentials can't be told apart: there's an@but no://, an@before://, or an authority (up to the first/) that has both an@and a?or#. The new shared cases failed before that commit (6 of them) and pass after it. Python and TypeScript return the sameurl.fullfor 20,034 generated inputs, and no kept value has an@outside its path.