feat(traces): before_span_send hook - #956
Draft
turnipdabeets wants to merge 2 commits into
Draft
turnipdabeets wants to merge 2 commits into
turnipdabeets wants to merge 2 commits into
Conversation
Contributor
posthog-python Compliance ReportDate: 2026-09-15 22:10:03 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
Important Files Changed
Prompt To Fix All With AI### Issue 1
posthog/tracing/_before_span_send.py:193
`_hook_status` checks `message` truthiness before calling `safe_str`. A hook that returns `0` or `False` loses that status message. An object whose `__bool__` raises drops the whole span. Use the same non-`None` check as `RecordingSpan.set_status`.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat(traces): before_span_send hook" | Re-trigger Greptile |
This was referenced Sep 14, 2026
turnipdabeets
force-pushed
the
traces/08-before-span-send
branch
from
September 14, 2026 22:58
3715073 to
a187b2a
Compare
turnipdabeets
added this pull request to stack #958
September 14, 2026 23:03
turnipdabeets
force-pushed
the
traces/08-before-span-send
branch
from
September 15, 2026 14:09
a187b2a to
25ad854
Compare
turnipdabeets
force-pushed
the
traces/08-before-span-send
branch
from
September 15, 2026 14:17
25ad854 to
6ebfcae
Compare
turnipdabeets
force-pushed
the
traces/08-before-span-send
branch
from
September 15, 2026 14:25
6ebfcae to
0d5388a
Compare
Adds the traces `before_span_send` option: a callable, or a list run in order, that receives each finished span as a plain dict (like the events before_send hook) and returns it edited, or None to drop it. It is the documented place to scrub sensitive values, so a hook that raises drops the span rather than exporting it unscrubbed. trace_id, span_id and parent_span_id are read-only; names, times, status and events are re-sanitized and the per-span limits re-applied to whatever the hook returns. The hook runs with no tracing lock held, and entries that are not callable are ignored with a warning. Not reachable from the client. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TkZAsCciW4PV8ZdcCHmAbA
A message of 0 or False was dropped, and one whose truth test raises took the whole span with it. Only None now means no message, as in set_status.
turnipdabeets
force-pushed
the
traces/08-before-span-send
branch
from
September 15, 2026 22:04
0d5388a to
c214418
Compare
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.
💡 Motivation and Context
Adds the traces
before_span_sendoption: a callable, or a list run in order, that receives each finished span as a plain dict (like the eventsbefore_sendhook) and returns it edited, orNoneto drop it.It is the documented place to scrub sensitive values, so a hook that raises drops the span rather than exporting it unscrubbed.
trace_id,span_idandparent_span_idare read-only. Names, times, status and events are re-sanitized and the per-span limits re-applied to whatever the hook returns. The hook runs with no tracing lock held, and entries that are not callable are ignored with a warning.Not reachable from the client yet.
Stack (PR 8 of 9, based on
traces/07-span-limits):traces/01-ids-traceparenttraces/02-otlp-encodingtraces/03-span-handlestraces/04-transporttraces/05-pipelinetraces/06-exporttraces/07-span-limitstraces/08-before-span-send← this PRtraces/09-client-wiring💚 How did you test it?
Unit tests in
posthog/test/tracing/test_pipeline.pyandtest_config.pycover edit, drop, raise, read-only ids, re-sanitizing and non-callable entries.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Implemented with Claude Code (Claude Opus 5) against the traces spec, one commit per slice so each PR reviews on its own. Rebased onto main and opened as a stacked draft in a later Claude Code session (Claude Fable 5.1).
🤖 Generated with Claude Code
https://claude.ai/code/session_012o7CtHLfcypjmXL7g9ZGRC