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(ml-mirror): mirror only web replays (#116911)

Nicholas Waltzb165c5c63fa5
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/ml-mirror-pipeline.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/ml-mirror-pipeline.test.ts
index 93aeceda556c..645cbfc95aa4 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/ml-mirror-pipeline.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/ml-mirror-pipeline.test.ts
@@ -158,6 +158,7 @@ describe('ml-mirror-pipeline', () => {
properties: {
$session_id: sessionId,
$window_id: 'window-1',
+ $snapshot_source: 'web',
$snapshot_items: [
{
type: 3,
@@ -234,7 +235,12 @@ describe('ml-mirror-pipeline', () => {
distinct_id: 'user-123',
data: JSON.stringify({
event: '$snapshot_items',
- properties: { $session_id: sessionId, $window_id: 'window-1', $snapshot_items: [snapshot] },
+ properties: {
+ $session_id: sessionId,
+ $window_id: 'window-1',
+ $snapshot_source: 'web',
+ $snapshot_items: [snapshot],
+ },
}),
})
return {
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/native-anonymize-task.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/native-anonymize-task.test.ts
index cd0bba13e366..eb0a5a3da02f 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/native-anonymize-task.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/native-anonymize-task.test.ts
@@ -33,6 +33,7 @@ describeAddon('native anonymize task', () => {
],
$session_id: 's-1',
$window_id: 'w',
+ $snapshot_source: 'web',
},
})
return Buffer.from(JSON.stringify({ distinct_id: 'd-1', data: inner }))
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.test.ts
index 75a50d10bd34..32f6cee7fab2 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.test.ts
@@ -207,6 +207,33 @@ describe('createParseAndAnonymizeMessageStep', () => {
expect(result).toMatchObject({ type: PipelineResultType.DROP, reason: 'anonymize_failed' })
})
+ it.each([
+ ['web', PipelineResultType.OK],
+ ['mobile', PipelineResultType.DROP],
+ [null, PipelineResultType.DROP],
+ ])('mirrors only web replays (source %p)', async (snapshotSource, expected) => {
+ addonSuccess({ snapshotSource })
+ const result = await step({ message: kafkaMessage(), headers, team })
+ expect(result.type).toBe(expected)
+ if (expected === PipelineResultType.DROP) {
+ expect(result).toMatchObject({ reason: 'ml_mirror_non_web_replay' })
+ }
+ })
+
+ it('drops a replay the addon refused as non-web, without counting an anonymize failure', async () => {
+ mockAnonymizeKafkaPayload.mockResolvedValue({
+ failed: true,
+ reason: 'ml_mirror_non_web_replay',
+ error: 'replay is not from a web SDK',
+ lines: null,
+ images: null,
+ meta: null,
+ timings: null,
+ })
+ const result = await step({ message: kafkaMessage(), headers, team })
+ expect(result).toMatchObject({ type: PipelineResultType.DROP, reason: 'ml_mirror_non_web_replay' })
+ })
+
it('drops messages whose timestamps are too far from now', async () => {
const monthAgo = now - 30 * 24 * 60 * 60 * 1000
addonSuccess({ startTs: monthAgo, endTs: monthAgo + 1000 })
@@ -409,7 +436,7 @@ describe('createParseAndAnonymizeMessageStep with url collection', () => {
distinctId: 'distinct-id',
sessionId: 'session-id',
windowId: 'w',
- snapshotSource: null,
+ snapshotSource: 'web',
snapshotLibrary: null,
startTs: now,
endTs: now,
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.ts
index bafc01bd3799..fff0d8c20353 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/parse-and-anonymize-step.ts
@@ -212,6 +212,9 @@ export function createParseAndAnonymizeMessageStep<
if (result.reason && DLQ_REASONS.has(result.reason)) {
return dlq(result.reason, new Error(result.error ?? result.reason))
}
+ if (result.reason === 'ml_mirror_non_web_replay') {
+ return drop('ml_mirror_non_web_replay')
+ }
if (result.reason === 'message_contained_no_valid_rrweb_events') {
return drop(
'message_contained_no_valid_rrweb_events',
@@ -240,6 +243,10 @@ export function createParseAndAnonymizeMessageStep<
return drop('anonymize_failed')
}
+ if (!isWebReplay(meta.snapshotSource)) {
+ return drop('ml_mirror_non_web_replay')
+ }
+
const startDateTime = DateTime.fromMillis(meta.startTs)
const endDateTime = DateTime.fromMillis(meta.endTs)
const startDiff = Math.abs(startDateTime.diffNow('day').days)
@@ -317,6 +324,15 @@ export function createParseAndAnonymizeMessageStep<
}
}
+/**
+ * The anonymizer scrubs the web rrweb shapes only. Mobile SDKs send wireframes and screenshots, which
+ * none of its scrubbers read, so only a web replay is mirrored. Capture writes `web` when a client
+ * sends no source, so a missing one never comes from capture.
+ */
+export function isWebReplay(snapshotSource: string | null | undefined): boolean {
+ return snapshotSource === 'web'
+}
+
function recordImageSources(meta: AnonymizeMeta): void {
for (const imageSource of meta.imageSources ?? []) {
MlMirrorMetrics.incrementMlImageReferencesByProperty(
diff --git a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/shared-fixtures.test.ts b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/shared-fixtures.test.ts
index 2d9e76d1ffce..b6d4bbdbfe5c 100644
--- a/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/shared-fixtures.test.ts
+++ b/nodejs/src/ingestion/pipelines/sessionreplay/ml-mirror/shared-fixtures.test.ts
@@ -87,7 +87,7 @@ describeAddon('native rust addon matches the shared fixtures', () => {
})
const inner = JSON.stringify({
event: '$snapshot_items',
- properties: { $snapshot_items: items, $session_id: 's-1', $window_id: windowId },
+ properties: { $snapshot_items: items, $session_id: 's-1', $window_id: windowId, $snapshot_source: 'web' },
})
return Buffer.from(JSON.stringify({ distinct_id: 'd-1', data: inner }))
}
@@ -355,6 +355,7 @@ describeAddon('native image collection', () => {
],
$session_id: 's-1',
$window_id: 'w',
+ $snapshot_source: 'web',
},
})
return Buffer.from(JSON.stringify({ distinct_id: 'd-1', data: inner }))
diff --git a/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.test.ts b/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.test.ts
index b567abfa8bc0..72a99c7fb5ba 100644
--- a/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.test.ts
+++ b/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.test.ts
@@ -1,68 +1,78 @@
+import * as anonymizer from '@posthog/replay-anonymizer'
+
import { KAFKA_SESSION_REPLAY_ML_BLOCK_METADATA } from '~/common/config/kafka-topics'
import { getDefaultSessionRecordingConfig } from '~/ingestion/pipelines/sessionreplay/config'
import {
IngestionSessionReplayMlMirrorServer,
+ assertAnonymizerHealthy,
buildMlMirrorServerConfig,
} from './ingestion-session-replay-ml-mirror-server'
-describe('buildMlMirrorServerConfig', () => {
- it.each(['S3_PREFIX', 'PSEUDONYM_SECRET', 'PSEUDONYM_KMS_REGION', 'PSEUDONYM_KEY_FINGERPRINT'] as const)(
- 'applies the legacy %s environment alias when building server configuration',
- (suffix) => {
- const legacy = `SESSION_RECORDING_ML_${suffix}`
- const canonical = `AI_RESEARCH_REPLAY_${suffix}` as const
- const originalEnv = process.env
- try {
- process.env = { ...originalEnv, [legacy]: 'legacy-value' }
- delete process.env[canonical]
- expect(buildMlMirrorServerConfig({})[canonical]).toBe('legacy-value')
- process.env[canonical] = 'canonical-value'
- expect(buildMlMirrorServerConfig({})[canonical]).toBe('canonical-value')
- } finally {
- process.env = originalEnv
- }
- }
- )
- it.each([
- ['', ''],
- ['key-table', ''],
- ['', 'kms-key'],
- ])('rejects missing key manager configuration before starting services (%s, %s)', (table, kmsKey) => {
- expect(
- () =>
- new IngestionSessionReplayMlMirrorServer({
- AI_RESEARCH_REPLAY_KEY_TABLE: table,
- AI_RESEARCH_REPLAY_KMS_KEY_ARN: kmsKey,
- })
- ).toThrow('ML key manager requires a DynamoDB table and a KMS key ARN')
+describe('ingestion-session-replay-ml-mirror-server', () => {
+ it('passes its own startup self-test against the native addon', async () => {
+ anonymizer.initAnonymizer({ text: [], url: [] })
+ await expect(assertAnonymizerHealthy(anonymizer)).resolves.toBeUndefined()
})
- it('defaults the mirror to its own consumer group, distinct from the primary ingester', () => {
- const config = buildMlMirrorServerConfig({})
- expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).toBe('session-replay-ml-mirror')
- // Regression guard for the group-id collision: must not inherit the primary default.
- expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).not.toBe(
- getDefaultSessionRecordingConfig().INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID
+ describe('buildMlMirrorServerConfig', () => {
+ it.each(['S3_PREFIX', 'PSEUDONYM_SECRET', 'PSEUDONYM_KMS_REGION', 'PSEUDONYM_KEY_FINGERPRINT'] as const)(
+ 'applies the legacy %s environment alias when building server configuration',
+ (suffix) => {
+ const legacy = `SESSION_RECORDING_ML_${suffix}`
+ const canonical = `AI_RESEARCH_REPLAY_${suffix}` as const
+ const originalEnv = process.env
+ try {
+ process.env = { ...originalEnv, [legacy]: 'legacy-value' }
+ delete process.env[canonical]
+ expect(buildMlMirrorServerConfig({})[canonical]).toBe('legacy-value')
+ process.env[canonical] = 'canonical-value'
+ expect(buildMlMirrorServerConfig({})[canonical]).toBe('canonical-value')
+ } finally {
+ process.env = originalEnv
+ }
+ }
)
- })
+ it.each([
+ ['', ''],
+ ['key-table', ''],
+ ['', 'kms-key'],
+ ])('rejects missing key manager configuration before starting services (%s, %s)', (table, kmsKey) => {
+ expect(
+ () =>
+ new IngestionSessionReplayMlMirrorServer({
+ AI_RESEARCH_REPLAY_KEY_TABLE: table,
+ AI_RESEARCH_REPLAY_KMS_KEY_ARN: kmsKey,
+ })
+ ).toThrow('ML key manager requires a DynamoDB table and a KMS key ARN')
+ })
- it('wires the ML metadata topic and a flush interval safely under max.poll.interval.ms', () => {
- const config = buildMlMirrorServerConfig({})
- expect(config.INGESTION_SESSIONREPLAY_OUTPUT_ML_BLOCK_METADATA_TOPIC).toBe(
- KAFKA_SESSION_REPLAY_ML_BLOCK_METADATA
- )
- expect(config.SESSION_RECORDING_ML_METADATA_PREFIX).toBe('block-metadata')
- expect(config.AI_RESEARCH_REPLAY_S3_PREFIX).toBe('rrweb_2')
- expect(config.SESSION_RECORDING_ML_PARQUET_FLUSH_INTERVAL_MS).toBeLessThan(300_000)
- })
+ it('defaults the mirror to its own consumer group, distinct from the primary ingester', () => {
+ const config = buildMlMirrorServerConfig({})
+ expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).toBe('session-replay-ml-mirror')
+ // Regression guard for the group-id collision: must not inherit the primary default.
+ expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).not.toBe(
+ getDefaultSessionRecordingConfig().INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID
+ )
+ })
+
+ it('wires the ML metadata topic and a flush interval safely under max.poll.interval.ms', () => {
+ const config = buildMlMirrorServerConfig({})
+ expect(config.INGESTION_SESSIONREPLAY_OUTPUT_ML_BLOCK_METADATA_TOPIC).toBe(
+ KAFKA_SESSION_REPLAY_ML_BLOCK_METADATA
+ )
+ expect(config.SESSION_RECORDING_ML_METADATA_PREFIX).toBe('block-metadata')
+ expect(config.AI_RESEARCH_REPLAY_S3_PREFIX).toBe('rrweb_2')
+ expect(config.SESSION_RECORDING_ML_PARQUET_FLUSH_INTERVAL_MS).toBeLessThan(300_000)
+ })
- it('lets an explicit override win over the mirror default', () => {
- const config = buildMlMirrorServerConfig({
- INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID: 'custom-group',
- SESSION_RECORDING_V2_S3_PREFIX: 'rrweb',
+ it('lets an explicit override win over the mirror default', () => {
+ const config = buildMlMirrorServerConfig({
+ INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID: 'custom-group',
+ SESSION_RECORDING_V2_S3_PREFIX: 'rrweb',
+ })
+ expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).toBe('custom-group')
+ expect(config.AI_RESEARCH_REPLAY_S3_PREFIX).toBe('rrweb_2')
})
- expect(config.INGESTION_SESSION_REPLAY_CONSUMER_GROUP_ID).toBe('custom-group')
- expect(config.AI_RESEARCH_REPLAY_S3_PREFIX).toBe('rrweb_2')
})
})
diff --git a/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.ts b/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.ts
index 52cd737a07d8..f428821d1148 100644
--- a/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.ts
+++ b/nodejs/src/servers/ingestion-session-replay-ml-mirror-server.ts
@@ -40,12 +40,13 @@ import { MlMirrorConsumerServer } from './ml-mirror-consumer-server'
export { type IngestionSessionReplayMlMirrorServerConfig, buildMlMirrorServerConfig } from './ml-mirror-server-config'
/** Boot-time smoke test so a broken addon crashes startup instead of dropping all traffic later. */
-async function assertAnonymizerHealthy(anonymizer: typeof import('@posthog/replay-anonymizer')): Promise<void> {
+export async function assertAnonymizerHealthy(anonymizer: typeof import('@posthog/replay-anonymizer')): Promise<void> {
const inner = JSON.stringify({
event: '$snapshot_items',
properties: {
$session_id: 's',
$window_id: 'w',
+ $snapshot_source: 'web',
$snapshot_items: [{ type: 3, timestamp: Date.now(), data: { source: 5, id: 1, text: 'health check' } }],
},
})
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index be35d2e68c36..0017df7c4429 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -9570,7 +9570,7 @@ dependencies = [
[[package]]
name = "posthog-replay-anonymizer"
-version = "0.11.0"
+version = "0.12.0"
dependencies = [
"ahash 0.8.12",
"anyhow",
diff --git a/rust/replay-anonymizer-node/src/lib.rs b/rust/replay-anonymizer-node/src/lib.rs
index 5938227e92cf..cf48599ce24a 100644
--- a/rust/replay-anonymizer-node/src/lib.rs
+++ b/rust/replay-anonymizer-node/src/lib.rs
@@ -281,7 +281,10 @@ fn anonymize_kafka_payload_ffi(mut cx: FunctionContext) -> JsResult<JsPromise> {
let scrubbed = snapshot::anonymize_kafka_payload_collecting(
allow,
&mut payload,
- snapshot::AnonymizeOpts::default(),
+ snapshot::AnonymizeOpts {
+ web_only: true,
+ ..Default::default()
+ },
Some(&timings),
image_collection,
url_collection,
diff --git a/rust/replay-anonymizer/Cargo.toml b/rust/replay-anonymizer/Cargo.toml
index fe25289f94c6..1c5d07d212e1 100644
--- a/rust/replay-anonymizer/Cargo.toml
+++ b/rust/replay-anonymizer/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "posthog-replay-anonymizer"
-version = "0.11.0"
+version = "0.12.0"
edition = "2021"
description = "PII scrubber for rrweb session-replay events: text/URL redaction, image collection for an out-of-band scrub, and canvas/cv neutralization"
license = "MIT"
diff --git a/rust/replay-anonymizer/src/snapshot.rs b/rust/replay-anonymizer/src/snapshot.rs
index f09510b0b204..bce5a33db2c7 100644
--- a/rust/replay-anonymizer/src/snapshot.rs
+++ b/rust/replay-anonymizer/src/snapshot.rs
@@ -58,6 +58,8 @@ pub enum FailKind {
NoValidEvents,
/// An event could not be scrubbed — fail closed (drop `anonymize_failed`).
AnonymizeFailed,
+ /// A mobile replay under [`AnonymizeOpts::web_only`] (drop `ml_mirror_non_web_replay`).
+ NonWebReplay,
}
impl FailKind {
@@ -69,6 +71,7 @@ impl FailKind {
FailKind::NonSnapshotMessage => "received_non_snapshot_message",
FailKind::NoValidEvents => "message_contained_no_valid_rrweb_events",
FailKind::AnonymizeFailed => "anonymize_failed",
+ FailKind::NonWebReplay => "ml_mirror_non_web_replay",
}
}
}
@@ -235,14 +238,29 @@ pub struct AnonymizeOpts {
/// ([`crate::bytewalk`]) instead of a simd-json tree; anything the walk can't prove safe falls
/// back to the parse per event. The differential tests pin both engines by toggling this.
pub byte_walk: bool,
+ /// Refuse a replay whose `$snapshot_source` is not `web`. Mobile SDKs send wireframes and
+ /// screenshots, which none of the scrubbers read.
+ pub web_only: bool,
}
impl Default for AnonymizeOpts {
fn default() -> Self {
- Self { byte_walk: true }
+ Self {
+ byte_walk: true,
+ web_only: false,
+ }
}
}
+/// Capture writes `web` when a client sends no source, so a missing source never comes from capture.
+pub fn is_web_replay(snapshot_source: Option<&str>) -> bool {
+ snapshot_source == Some("web")
+}
+
+fn non_web_replay() -> Failure {
+ Failure::new(FailKind::NonWebReplay, "replay is not from a web SDK")
+}
+
#[derive(Debug)]
pub struct AnonymizedMessage {
/// Scrubbed JSONL: one `["<windowId>",<event>]\n` line per valid event, in input order.
@@ -554,6 +572,9 @@ fn anonymize_snapshot_data_inner(
anonymize_via_tree_mut(&ctx, distinct_id, inner)?
}
};
+ if opts.web_only && !is_web_replay(msg.meta.snapshot_source.as_deref()) {
+ return Err(non_web_replay());
+ }
msg.meta.url_declines = ctx
.take_url_declines()
.into_iter()
diff --git a/rust/replay-anonymizer/tests/ref_idempotence.rs b/rust/replay-anonymizer/tests/ref_idempotence.rs
index dd0091dacf53..87f1acf389fb 100644
--- a/rust/replay-anonymizer/tests/ref_idempotence.rs
+++ b/rust/replay-anonymizer/tests/ref_idempotence.rs
@@ -91,7 +91,10 @@ fn scrub_ingestion(line: &Value, byte_walk: bool) -> String {
let out = anonymize_kafka_payload_opts(
&AllowLists::default(),
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
)
.expect("anonymize should succeed");
diff --git a/rust/replay-anonymizer/tests/snapshot.rs b/rust/replay-anonymizer/tests/snapshot.rs
index 868c3ae453d4..21417d6d1d04 100644
--- a/rust/replay-anonymizer/tests/snapshot.rs
+++ b/rust/replay-anonymizer/tests/snapshot.rs
@@ -456,8 +456,15 @@ fn assert_stream_matches_tree(allow: &AllowLists, inner_json: &str, label: &str)
// per-event fallbacks) vs the simd path.
for byte_walk in [true, false] {
let mut bytes = payload.as_bytes().to_vec();
- let stream =
- anonymize_kafka_payload_opts(allow, &mut bytes, AnonymizeOpts { byte_walk }, None);
+ let stream = anonymize_kafka_payload_opts(
+ allow,
+ &mut bytes,
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
+ None,
+ );
match (&stream, &tree) {
(Ok(s), Ok(t)) => {
let s_lines = parse_lines(&s.lines);
@@ -858,6 +865,58 @@ fn collect_payload() -> String {
])))
}
+#[test]
+fn web_only_keeps_only_a_web_source() {
+ let allow = AllowLists::new(Vec::<String>::new(), Vec::<String>::new());
+ let event = json!({"type": 3, "timestamp": TS0, "data": {"source": 0, "texts": [], "attributes": [], "removes": [], "adds": []}});
+ let payload = |source: Option<&str>, escape_key: bool| {
+ let mut message = snapshot_message(json!([event.clone()]));
+ match source {
+ Some(source) => message["properties"]["$snapshot_source"] = json!(source),
+ None => {
+ message["properties"]
+ .as_object_mut()
+ .unwrap()
+ .remove("$snapshot_source");
+ }
+ }
+ let mut inner = serde_json::to_string(&message).unwrap();
+ if escape_key {
+ // An escaped envelope key sends the message down the tree path.
+ inner = inner.replace("\"$snapshot_source\"", "\"$snapshot_\\u0073ource\"");
+ }
+ serde_json::to_string(&json!({"distinct_id": "d-1", "data": inner})).unwrap()
+ };
+ let cases = [
+ (Some("web"), false, true),
+ (Some("web"), true, true),
+ (Some("mobile"), false, false),
+ (Some("mobile"), true, false),
+ (None, false, false),
+ ];
+ for (source, escape_key, kept) in cases {
+ for web_only in [true, false] {
+ let mut bytes = payload(source, escape_key).into_bytes();
+ let out = anonymize_kafka_payload_opts(
+ &allow,
+ &mut bytes,
+ AnonymizeOpts {
+ web_only,
+ ..Default::default()
+ },
+ None,
+ );
+ let refused = matches!(&out, Err(f) if f.kind == FailKind::NonWebReplay);
+ assert_eq!(
+ refused,
+ web_only && !kept,
+ "{source:?} escaped={escape_key} web_only={web_only}: {:?}",
+ out.as_ref().err()
+ );
+ }
+ }
+}
+
#[test]
fn both_engines_count_and_collect_an_image_once_or_not_at_all() {
// The byte walk walks children before it knows their parent, then re-walks or discards them.
@@ -898,7 +957,10 @@ fn both_engines_count_and_collect_an_image_once_or_not_at_all() {
let out = anonymize_kafka_payload_opts(
&allow,
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
Some(ImageCollection::new(
"42".to_string(),
"fedcba9876543210fedcba9876543210".to_string(),
@@ -938,7 +1000,10 @@ fn image_collection_replaces_images_with_refs_and_returns_the_bytes() {
let out = anonymize_kafka_payload_opts(
&allow,
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
Some(ImageCollection::new(team_id.clone(), content_key.clone())),
)
.expect("anonymizes (walk={byte_walk})");
diff --git a/rust/replay-anonymizer/tests/url_collection.rs b/rust/replay-anonymizer/tests/url_collection.rs
index d092038e558d..179befdcd54a 100644
--- a/rust/replay-anonymizer/tests/url_collection.rs
+++ b/rust/replay-anonymizer/tests/url_collection.rs
@@ -46,7 +46,10 @@ fn collect_urls_of(tag: &str, attrs: Value) -> Vec<String> {
let msg = anonymize_kafka_payload_collecting(
&allow,
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
None,
Some(UrlCollection {
@@ -156,7 +159,10 @@ fn picture_source_srcset_is_collected_when_its_parent_is_known() {
let message = anonymize_kafka_payload_collecting(
&AllowLists::default(),
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
None,
Some(UrlCollection {
@@ -212,7 +218,10 @@ fn run(attrs: Value, collect: bool) -> Vec<(String, Value)> {
let msg = anonymize_kafka_payload_collecting(
&allow,
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
None,
collection,
@@ -388,7 +397,10 @@ fn an_escaped_or_repeated_dimension_key_still_declines_a_hidden_pixel() {
let message = anonymize_kafka_payload_collecting(
&AllowLists::default(),
&mut bytes,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
None,
Some(UrlCollection {
@@ -649,7 +661,10 @@ fn monthly_refs_survive_compressed_snapshot_fields() {
let output = anonymize_kafka_payload_collecting(
&AllowLists::default(),
&mut payload,
- AnonymizeOpts { byte_walk },
+ AnonymizeOpts {
+ byte_walk,
+ ..Default::default()
+ },
None,
Some(ImageCollection::new(
namespace.to_string(),