* Log an event (synchronous implementation)
(eventName: string, metadata: LogEventMetadata)
| 46 | * Log an event (synchronous implementation) |
| 47 | */ |
| 48 | function logEventImpl(eventName: string, metadata: LogEventMetadata): void { |
| 49 | // Check if this event should be sampled |
| 50 | const sampleResult = shouldSampleEvent(eventName) |
| 51 | |
| 52 | // If sample result is 0, the event was not selected for logging |
| 53 | if (sampleResult === 0) { |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | // If sample result is a positive number, add it to metadata |
| 58 | const metadataWithSampleRate = |
| 59 | sampleResult !== null |
| 60 | ? { ...metadata, sample_rate: sampleResult } |
| 61 | : metadata |
| 62 | |
| 63 | if (shouldTrackDatadog()) { |
| 64 | // Datadog is a general-access backend — strip _PROTO_* keys |
| 65 | // (unredacted PII-tagged values meant only for the 1P privileged column). |
| 66 | void trackDatadogEvent(eventName, stripProtoFields(metadataWithSampleRate)) |
| 67 | } |
| 68 | |
| 69 | // 1P receives the full payload including _PROTO_* — the exporter |
| 70 | // destructures and routes those keys to proto fields itself. |
| 71 | logEventTo1P(eventName, metadataWithSampleRate) |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Log an event (asynchronous implementation) |
no test coverage detected