Skip to content

fix(ai): use context distinct_id in LangChain callback handler - #1292

Open
pcbeingused333 wants to merge 2 commits into
PostHog:mainfrom
pcbeingused333:fix/langchain-context-distinct-id
Open

pcbeingused333 wants to merge 2 commits into
PostHog:mainfrom
pcbeingused333:fix/langchain-context-distinct-id

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Related to #1284 (same bug in the LangChain callback handler)

💡 Motivation and Context

CallbackHandler built $ai_span, $ai_trace, $ai_generation and the $exception events from its own distinct_id argument only. A distinct ID set with identify_context() was ignored, so the events were captured personless under the run ID. The OpenAI and Anthropic wrappers already read get_context_distinct_id().

The handler now resolves the ID through a small _resolve_distinct_id helper in posthog/ai/utils.py: the handler's own distinct_id first, then the active context's ID, then the existing run/trace-ID fallback (still personless). An explicit handler distinct_id still wins.

💚 How did you test it?

  • New test test_context_distinct_id_is_used: runs a chain inside new_context() after identify_context("context-user") and asserts every captured event uses that ID without process_person_profile: False; also checks an explicit handler ID wins. It fails on main and passes with the fix.
  • posthog/test/ai/langchain: 132 passed, 8 skipped. Tests use a mocked client; nothing ran against a live API.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed. (n/a)
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file (added .sampo/changesets/langchain-context-distinct-id.md)

🤖 Agent context

Autonomy: Fully autonomous

  • Written with Claude Code (Claude Sonnet 5.5): the fix, the test and this description.

The handler only looked at its own distinct_id argument, so an id set with identify_context() was ignored and $ai_span, $ai_generation, $ai_trace and exception events were captured personless under the run id. Resolve the id from the handler first, then the active context, matching the OpenAI/Anthropic wrappers.

Signed-off-by: Alex <alex.castillog33@gmail.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner November 23, 2026 00:59

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review.

The core change cleanly resolves active PostHog context distinct_id values across LangChain $ai_span, $ai_trace, $ai_generation, and $exception events (verified with unit tests and end-to-end HTTP delivery against sdk-mock-server).

Two concerns to address before approval are noted inline:

  1. _resolve_distinct_id and its three call sites use or truthiness, which drops integer distinct_id=0 (regressing _capture_exception_and_update_properties and misattributing events to an active context user).
  2. The modified _capture_exception_and_update_properties path has no test coverage for active context resolution, and the explicit-override block in test_context_distinct_id_is_used omits a call_count guard and options check.

There is also one optional docstring suggestion inline. (Standard GitHub Actions CI workflows will still need to run on this fork PR before merge.)

Comment thread posthog/ai/utils.py Outdated

def _resolve_distinct_id(distinct_id: Any) -> Any:
"""The caller's distinct id, else the one from the active PostHog context, else None."""
return _user_distinct_id(distinct_id) or _user_distinct_id(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern: _resolve_distinct_id and its three call sites in posthog/ai/langchain/callbacks.py (lines 601, 627, and 783) use Python or truthiness, which silently drops integer distinct_id=0 and causes cross-user misattribution when a PostHog context is active.

Expected contract & evidence: CallbackHandler.__init__ (posthog/ai/langchain/callbacks.py:144) and PostHogMiddleware.__init__ (posthog/ai/langchain/middleware.py:57) accept distinct_id: Optional[Union[str, int, UUID]] = None. _explicit_distinct_id(0) (posthog/client.py:304-309) and _user_distinct_id(0) (posthog/ai/utils.py:70-72) both treat 0 as a present ID (0, not None), and call_llm_and_track_usage (posthog/ai/utils.py:628-629) uses explicit is not None checks.

Minimal caller & base vs. head result:

with new_context():
    identify_context("context-user")
    chain.invoke({}, config={"callbacks": [CallbackHandler(client, distinct_id=0)]})
  • Base (84fc9e06): On a failed run with enable_exception_autocapture=True, _capture_exception_and_update_properties sent $exception with distinct_id="0" and options={} (and without a context did not inject process_person_profile: False). $ai_* fell back to a run/trace UUID (pre-existing or).
  • Head (c4d3d8ca): _user_distinct_id(0) returns 0 (falsy), so _resolve_distinct_id(0) evaluates the right-hand side and returns "context-user". Both $ai_* and $exception events are sent with distinct_id="context-user" and options={} (verified via base/head unit tests and sdk-mock-server HTTP wire capture). Without a context, _resolve_distinct_id(0) returns None, regressing _capture_exception_and_update_properties to inject process_person_profile: False.

Impact: Although "0" is uncommon in production (and PostHog capture v1 disables person processing for "0" via ILLEGAL_DISTINCT_IDS), inside an active context this change turns an explicit distinct_id=0 into "context-user" (a valid person-processed ID), silently attributing those AI and exception events to another user's person profile, and bakes the truthiness bug into the new shared _resolve_distinct_id helper.

Recommendation: Consider replacing or with explicit is not None checks in _resolve_distinct_id (preserving non-string values like UUID expected by test_personless_mode) and at posthog/ai/langchain/callbacks.py:601,627,783:

def _resolve_distinct_id(distinct_id: Any) -> Any:
    """The caller's distinct id, else the one from the active PostHog context, else None."""
    explicit = _user_distinct_id(distinct_id)
    if explicit is not None:
        return explicit
    return _user_distinct_id(contexts.get_context_distinct_id())

and in posthog/ai/langchain/callbacks.py:

distinct_id=resolved_distinct_id if resolved_distinct_id is not None else run_id,           # line 601
distinct_id=resolved_distinct_id if resolved_distinct_id is not None else self._distinct_id, # line 627
distinct_id=resolved_distinct_id if resolved_distinct_id is not None else trace_id,          # line 783

Regression test (executed on base 84fc9e06 vs. head c4d3d8ca; exception assertions pass on base and fail on head):

def test_zero_distinct_id_preserved_over_context(mock_client):
    from langchain_core.runnables import RunnableLambda
    from posthog import identify_context, new_context

    mock_client.enable_exception_autocapture = True
    mock_client.capture_exception.return_value = "exc-id"

    def fail(_):
        raise ValueError("boom")

    with new_context():
        identify_context("context-user")
        with pytest.raises(ValueError):
            RunnableLambda(fail).invoke(
                {}, config={"callbacks": [CallbackHandler(mock_client, distinct_id=0)]}
            )

    assert mock_client.capture_ai.call_count == 1
    assert mock_client.capture_ai.call_args[1]["distinct_id"] == 0
    assert "options" not in mock_client.capture_ai.call_args[1]
    assert mock_client.capture_exception.call_count == 1
    assert mock_client.capture_exception.call_args[1]["distinct_id"] == 0
    assert mock_client.capture_exception.call_args[1]["options"] is None

handler = CallbackHandler(mock_client, distinct_id="explicit")
chain.invoke({}, config={"callbacks": [handler]})
for call in mock_client.capture_ai.call_args_list:
assert call[1]["distinct_id"] == "explicit"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concern: The modified _capture_exception_and_update_properties path (posthog/ai/langchain/callbacks.py:621-631) has no test coverage for active PostHog context resolution, and the explicit-override block here omits call_count and options assertions.

Evidence & impact: Before this PR, a failed LangChain run inside identify_context(...) with enable_exception_autocapture=True emitted $exception with the context user's distinct_id and options={"process_person_profile": False}. This PR fixes both the distinct_id forwarding and exception_options, but test_context_distinct_id_is_used is the only test in posthog/test/ai/langchain/ using identify_context and only covers a successful chain run. In addition, lines 558–559 loop over mock_client.capture_ai.call_args_list without asserting call_count == 3 (so zero calls would pass vacuously) or "options" not in call[1].

Recommendation: Consider:

  1. Adding assert mock_client.capture_ai.call_count == 3 and assert "options" not in call[1] to the explicit-override block.
  2. Adding a test exercising _capture_exception_and_update_properties inside identify_context(...) (and optionally blank explicit distinct_id=" " falling back to context / reusing one CallbackHandler across contexts):
def test_context_distinct_id_exception_autocapture(mock_client):
    from langchain_core.runnables import RunnableLambda
    from posthog import identify_context, new_context

    mock_client.enable_exception_autocapture = True
    mock_client.capture_exception.return_value = "exception-uuid-ctx"

    def failing_span(_):
        raise ValueError("boom")

    with new_context():
        identify_context("context-user")
        with pytest.raises(ValueError):
            RunnableLambda(failing_span).invoke(
                {}, config={"callbacks": [CallbackHandler(mock_client)]}
            )

    assert mock_client.capture_exception.call_count == 1
    exc_kwargs = mock_client.capture_exception.call_args[1]
    assert exc_kwargs["distinct_id"] == "context-user"
    assert exc_kwargs["options"] is None
    assert mock_client.capture_ai.call_count == 1
    assert mock_client.capture_ai.call_args[1]["distinct_id"] == "context-user"
    assert "options" not in mock_client.capture_ai.call_args[1]

(Verified against base 84fc9e06 vs. head c4d3d8ca: fails on base and passes on head.)

finalize_ai_content(outputs, self._ph_client),
)

resolved_distinct_id = _resolve_distinct_id(self._distinct_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Since CallbackHandler (and PostHogMiddleware, whose docstring defers to CallbackHandler) now resolves distinct_id from the active PostHog context before falling back to personless mode, consider noting that fallback in CallbackHandler.__init__'s docstring (posthog/ai/langchain/callbacks.py:154 and 162-163, outside this diff). For example:

distinct_id: Optional distinct ID of the user to associate the trace with. When omitted or blank, falls back to the active PostHog context distinct ID (set via identify_context), or sends personless events if neither is set.

This keeps IDE tooltips and generated SDK reference docs clear about when process_person_profile: False applies (per SDK guidelines: Treat docs and examples as part of the SDK).

@dustinbyrne
dustinbyrne requested a review from a team November 23, 2026 22:55
…in context id

Use explicit is-not-None checks in _resolve_distinct_id and its call sites so distinct_id=0 is not replaced by the context user; add tests for exception autocapture and the 0 id; document the context fallback.
@pcbeingused333

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, both concerns are addressed in the new commit:

  • _resolve_distinct_id and the three call sites in the callback handler now use explicit is not None checks, so an explicit distinct_id=0 is kept instead of being replaced by the context user (and the $exception path no longer loses it); added test_zero_distinct_id_preserved_over_context, which fails without the change.
  • added test_context_distinct_id_exception_autocapture for _capture_exception_and_update_properties inside identify_context(...), and the explicit-override block now asserts call_count == 3 and no options.
  • documented the context fallback in the CallbackHandler distinct_id docstring.

Disclosure: this follow-up was prepared with AI assistance (Claude Code) and submitted by the account owner.

@github-actions

Copy link
Copy Markdown
Contributor

SDK performance: posthog-python

Benchmarks completed. No changes flagged for review.

Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate.

View all results
Test Measurement Before PR With PR Change Assessment
Capture and deliver events (32-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Queue an event (32-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (32-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocated memory per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Queue an event (4,096-byte payload)
Shard: capture
Allocations per operation — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​; head:​ Background preparation has no public completion boundary before flush; see capture.​drain for full-pipeline allocations.​
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Refresh 1,000 flag definitions
Shard: flags-memory
Managed heap after settling — — — unavailable; base:​ unsupported; head:​ unsupported; base:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​; head:​ CPython has no uninstrumented total managed-heap byte counter; tracing would distort this RSS pass.​
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocated memory per operation 133.67 KiB/op 133.67 KiB/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Allocations per operation 1,345.51 count/op 1,345.51 count/op No observed change Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Time per operation 78.33 µs/op 78.49 µs/op 0.2% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Idle process memory (RSS) 37.68 MiB 37.7 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 40.13 MiB 40.15 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 40.13 MiB 40.15 MiB <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Process CPU time per operation 81.82 µs/op 81.87 µs/op <0.1% more time Not flagged
Capture and deliver events (32-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 40.29 MiB 40.33 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocated memory per operation 185.75 KiB/op 185.75 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Allocations per operation 1,337.51 count/op 1,337.51 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Time per operation 102.06 µs/op 101.96 µs/op 0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Idle process memory (RSS) 41.18 MiB 41.25 MiB 0.2% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Observed peak process memory (RSS) 46.97 MiB 47.03 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process memory after settling (RSS) 46.97 MiB 47.03 MiB 0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Process CPU time per operation 97 µs/op 98.58 µs/op 1.6% more time Not flagged
Capture and deliver events (4,096-byte payload, burst)
Shard: capture
Lifetime peak process memory (RSS) 51.44 MiB 51.42 MiB <0.1% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocated memory per operation 138.73 KiB/op 138.73 KiB/op <0.1% more memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Allocations per operation 1,390.29 count/op 1,390.29 count/op <0.1% more Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Time per operation 90.47 µs/op 89.95 µs/op 0.6% less time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Idle process memory (RSS) 37.58 MiB 37.49 MiB 0.2% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 37.76 MiB 37.65 MiB 0.3% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 37.76 MiB 37.65 MiB 0.3% less memory Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Process CPU time per operation 91.55 µs/op 91.91 µs/op 0.4% more time Not flagged
Capture and deliver events (32-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 40.29 MiB 40.29 MiB No observed change Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocated memory per operation 190.9 KiB/op 190.9 KiB/op <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Allocations per operation 1,382.19 count/op 1,382.19 count/op <0.1% fewer Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Time per operation 106.57 µs/op 106.44 µs/op 0.1% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Idle process memory (RSS) 41.06 MiB 41.08 MiB <0.1% more memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Observed peak process memory (RSS) 41.52 MiB 41.52 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process memory after settling (RSS) 41.13 MiB 41.12 MiB <0.1% less memory Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Process CPU time per operation 104.14 µs/op 101.16 µs/op 2.9% less time Not flagged
Capture and deliver events (4,096-byte payload, steady)
Shard: capture
Lifetime peak process memory (RSS) 41.48 MiB 41.43 MiB 0.1% less memory Not flagged
Queue an event (32-byte payload)
Shard: capture
Caller-thread CPU time per operation 57.45 µs/op 57.34 µs/op 0.2% less time Not flagged
Queue an event (32-byte payload)
Shard: capture
Time per operation 57.45 µs/op 57.56 µs/op 0.2% more time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Caller-thread CPU time per operation 57.6 µs/op 57.56 µs/op <0.1% less time Not flagged
Queue an event (4,096-byte payload)
Shard: capture
Time per operation 57.6 µs/op 57.56 µs/op <0.1% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocated memory per operation 225.43 KiB/op 225.43 KiB/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Allocations per operation 2,279.42 count/op 2,279.42 count/op No observed change Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Time per operation 82.35 µs/op 82.1 µs/op 0.3% less time Not flagged
Evaluate all 10 flags
Shard: flags-scaling
Process CPU time per operation 82.35 µs/op 82.1 µs/op 0.3% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocated memory per operation 2.17 MiB/op 2.17 MiB/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Allocations per operation 22,413.69 count/op 22,413.69 count/op No observed change Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Time per operation 774.31 µs/op 773.78 µs/op <0.1% less time Not flagged
Evaluate all 100 flags
Shard: flags-scaling
Process CPU time per operation 774.26 µs/op 773.8 µs/op <0.1% less time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocated memory per operation 21.63 MiB/op 21.63 MiB/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Allocations per operation 223,655.44 count/op 223,655.44 count/op No observed change Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Time per operation 7.66 ms/op 7.69 ms/op 0.4% more time Not flagged
Evaluate all 1,000 flags
Shard: flags-scaling
Process CPU time per operation 7.66 ms/op 7.69 ms/op 0.4% more time Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Idle process memory (RSS) 43.89 MiB 43.88 MiB <0.1% less memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Observed peak process memory (RSS) 44.16 MiB 44.18 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Process memory after settling (RSS) 44.16 MiB 44.18 MiB <0.1% more memory Not flagged
Evaluate 1,000 flags under concurrent load
Shard: flags-memory
Lifetime peak process memory (RSS) 43.9 MiB 43.89 MiB <0.1% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Idle process memory (RSS) 43.02 MiB 42.95 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Observed peak process memory (RSS) 43.03 MiB 42.95 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Process memory after settling (RSS) 43.03 MiB 42.94 MiB 0.2% less memory Not flagged
Refresh 1,000 flag definitions
Shard: flags-memory
Lifetime peak process memory (RSS) 42.82 MiB 43.17 MiB 0.8% more memory Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocated memory per operation 15.74 KiB/op 15.74 KiB/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Allocations per operation 162.77 count/op 162.77 count/op No observed change Not flagged
Evaluate one boolean flag
Shard: flags-single
Time per operation 8.27 µs/op 8.21 µs/op 0.8% less time Not flagged
Evaluate one boolean flag
Shard: flags-single
Process CPU time per operation 8.28 µs/op 8.21 µs/op 0.8% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocated memory per operation 24.6 KiB/op 24.6 KiB/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Allocations per operation 239.28 count/op 239.28 count/op No observed change Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Time per operation 11.42 µs/op 11.38 µs/op 0.4% less time Not flagged
Evaluate a cohort-filtered flag
Shard: flags-single
Process CPU time per operation 11.42 µs/op 11.38 µs/op 0.4% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocated memory per operation 39.81 KiB/op 39.81 KiB/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Allocations per operation 388.27 count/op 388.27 count/op No observed change Not flagged
Evaluate a flag (early match)
Shard: flags-single
Time per operation 16.33 µs/op 16.3 µs/op 0.2% less time Not flagged
Evaluate a flag (early match)
Shard: flags-single
Process CPU time per operation 16.33 µs/op 16.3 µs/op 0.2% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocated memory per operation 60.59 KiB/op 60.59 KiB/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Allocations per operation 584.27 count/op 584.27 count/op No observed change Not flagged
Evaluate a flag (late match)
Shard: flags-single
Time per operation 23.57 µs/op 23.43 µs/op 0.6% less time Not flagged
Evaluate a flag (late match)
Shard: flags-single
Process CPU time per operation 23.57 µs/op 23.43 µs/op 0.6% less time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocated memory per operation 59.22 KiB/op 59.22 KiB/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Allocations per operation 567.77 count/op 567.77 count/op No observed change Not flagged
Evaluate a flag (no match)
Shard: flags-single
Time per operation 22.21 µs/op 22.23 µs/op <0.1% more time Not flagged
Evaluate a flag (no match)
Shard: flags-single
Process CPU time per operation 22.2 µs/op 22.23 µs/op 0.1% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocated memory per operation 19.04 KiB/op 19.04 KiB/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Allocations per operation 192.27 count/op 192.27 count/op No observed change Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Time per operation 9.19 µs/op 9.22 µs/op 0.3% more time Not flagged
Evaluate a property-filtered flag
Shard: flags-single
Process CPU time per operation 9.19 µs/op 9.22 µs/op 0.3% more time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocated memory per operation 20.66 KiB/op 20.66 KiB/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Allocations per operation 197.77 count/op 197.77 count/op No observed change Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Time per operation 9.82 µs/op 9.8 µs/op 0.2% less time Not flagged
Evaluate a regex-filtered flag
Shard: flags-single
Process CPU time per operation 9.82 µs/op 9.8 µs/op 0.2% less time Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocated memory per operation 14.89 KiB/op 14.89 KiB/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Allocations per operation 152.77 count/op 152.77 count/op No observed change Not flagged
Evaluate a rollout flag
Shard: flags-single
Time per operation 7.68 µs/op 7.7 µs/op 0.2% more time Not flagged
Evaluate a rollout flag
Shard: flags-single
Process CPU time per operation 7.68 µs/op 7.7 µs/op 0.2% more time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocated memory per operation 15.9 KiB/op 15.9 KiB/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Allocations per operation 166.77 count/op 166.77 count/op No observed change Not flagged
Evaluate a multivariate flag
Shard: flags-single
Time per operation 8.52 µs/op 8.51 µs/op 0.1% less time Not flagged
Evaluate a multivariate flag
Shard: flags-single
Process CPU time per operation 8.52 µs/op 8.51 µs/op 0.1% less time Not flagged

Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals.

Each shard uses its own runner; compare Before PR against With PR within a row, not across shards.

Compared 84fc9e06bd898fe090e7443138e32010b9aa91db → aa36cf117380f32a789bceb86de86bc7ba413b27.

Full report and diagnostics

102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in comparison.json, including per-runner environments, resource limits, measurement methods, samples and checkpoints.

@dustinbyrne dustinbyrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-assisted review.

Thanks for the quick follow-up — all earlier items are cleanly addressed (is not None checks preserve explicit distinct_id=0, exception-autocapture and explicit-override tests are in place, and the CallbackHandler docstring documents the context fallback). Verified locally with pytest, ruff, mypy, check_public_api.py, and end-to-end sdk-mock-server HTTP delivery across traces, spans, generations, and autocaptured exceptions.

Note: Python 3.11/3.12/3.13 tests, ruff, mypy, and the public API snapshot check all passed on CI; the Python 3.10 failure (test_metrics_autocapture.py::test_keeps_aiohttp_exclusions_for_sessions_created_after_start, which cancelled Python 3.14) is unrelated to this PR and will need a CI rerun before merge.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants