Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signals): count deduplicated emits as filtered (#123007)

posthog[bot]69a001a53c2d
diff --git a/products/signals/backend/facade/api.py b/products/signals/backend/facade/api.py
index 3a0e2016f756..54e710d4798f 100644
--- a/products/signals/backend/facade/api.py
+++ b/products/signals/backend/facade/api.py
@@ -880,26 +880,30 @@ async def emit_signal(
# that don't go through the data-source pipeline still have a top-of-funnel event. The gap to
# `signal_emitted` surfaces Temporal/dispatch failures, once the steering gate below is
# subtracted: started - signal_data_source_filtered - emitted = failures.
- try:
- posthoganalytics.capture(
- event="signal_emission_started",
- distinct_id=str(team.uuid),
- properties={
- **_telemetry_props_from_extra(extra),
- "source_product": source_product,
- "source_type": source_type,
- "source_id": source_id,
- },
- groups=groups(organization, team),
- )
- except Exception:
- # Swallow the exception, to avoid breaking the flow over failed analytics event
- logger.exception(
- "Failed to capture signal_emission_started event",
- source_product=source_product,
- source_type=source_type,
- source_id=source_id,
- )
+ def capture_emission_event(event: str, properties: dict[str, Any] | None = None) -> None:
+ try:
+ posthoganalytics.capture(
+ event=event,
+ distinct_id=str(team.uuid),
+ properties={
+ **_telemetry_props_from_extra(extra),
+ "source_product": source_product,
+ "source_type": source_type,
+ "source_id": source_id,
+ **(properties or {}),
+ },
+ groups=groups(organization, team),
+ )
+ except Exception:
+ # Swallow the exception, to avoid breaking the flow over failed analytics event
+ logger.exception(
+ f"Failed to capture {event} event",
+ source_product=source_product,
+ source_type=source_type,
+ source_id=source_id,
+ )
+
+ capture_emission_event("signal_emission_started")
signal_id = signal_id or signal_id_for(
team_id=team.id, source_product=source_product, source_type=source_type, idempotency_key=idempotency_key
@@ -975,30 +979,14 @@ async def emit_signal(
except temporalio.exceptions.WorkflowAlreadyStartedError:
if emitter_idempotency_key is None:
raise
+ # A repeated idempotency key is a deliberate dedupe, so label it rather than leave it to
+ # read as a dispatch failure in started - filtered - emitted.
+ capture_emission_event("signal_data_source_filtered", {"filter_reason": "duplicate_emission"})
return
# Fire the analytics event only after the signal is definitively queued so
# Temporal/connection failures don't inflate the "signals emitted" metric.
- try:
- posthoganalytics.capture(
- event="signal_emitted",
- distinct_id=str(team.uuid),
- properties={
- **_telemetry_props_from_extra(extra),
- "source_product": source_product,
- "source_type": source_type,
- "source_id": source_id,
- },
- groups=groups(organization, team),
- )
- except Exception:
- # Swallow the exception, to avoid breaking the flow over failed analytics event
- logger.exception(
- "Failed to capture signal_emitted event",
- source_product=source_product,
- source_type=source_type,
- source_id=source_id,
- )
+ capture_emission_event("signal_emitted")
def forward_report_discussion_note(
diff --git a/products/signals/backend/test/test_api.py b/products/signals/backend/test/test_api.py
index d490d5d72618..5b366c8e8a90 100644
--- a/products/signals/backend/test/test_api.py
+++ b/products/signals/backend/test/test_api.py
@@ -210,6 +210,7 @@ class TestEmitSignalValidation:
with (
patch("products.signals.backend.facade.api.async_connect", return_value=client),
patch.object(SignalSourceConfig, "is_source_enabled", return_value=True),
+ patch("products.signals.backend.facade.api.posthoganalytics.capture") as capture,
):
await emit_signal(
team=team_stub,
@@ -226,6 +227,11 @@ class TestEmitSignalValidation:
team_stub.id, "github:issue:notification-1"
)
assert emitter_call.kwargs["id_reuse_policy"] == WorkflowIDReusePolicy.ALLOW_DUPLICATE_FAILED_ONLY
+ assert [call.kwargs["event"] for call in capture.call_args_list] == [
+ "signal_emission_started",
+ "signal_data_source_filtered",
+ ]
+ assert capture.call_args_list[1].kwargs["properties"]["filter_reason"] == "duplicate_emission"
@pytest.mark.parametrize("idempotency_key", ["", " "])
async def test_emit_signal_rejects_empty_idempotency_keys(self, team_stub, idempotency_key):