Skip to content

Commit

Permalink
don't process logs before dropping them
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Oct 26, 2023
1 parent e94fc6c commit 1b390dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { retryOnDependencyUnavailableError } from '../../../../kafka/error-handl
import { createKafkaProducer, disconnectProducer, flushProducer, produce } from '../../../../kafka/producer'
import { PluginsServerConfig } from '../../../../types'
import { status } from '../../../../utils/status'
import { ConsoleLogEntry, gatherConsoleLogEvents } from '../../../../worker/ingestion/process-event'
import { ConsoleLogEntry, gatherConsoleLogEvents, RRWebEventType } from '../../../../worker/ingestion/process-event'
import { eventDroppedCounter } from '../../metrics'
import { IncomingRecordingMessage } from '../types'
import { OffsetHighWaterMarker } from './offset-high-water-marker'
Expand Down Expand Up @@ -141,29 +141,36 @@ export class ConsoleLogsIngester {
return drop('high_water_mark')
}

// cheapest possible check for any console logs to avoid parsing the events because...
const hasAnyConsoleLogs = event.events.some(
(e) => !!e && e.type === RRWebEventType.Plugin && e.data?.plugin === 'rrweb/console@1'
)

if (!hasAnyConsoleLogs) {
return
}

// ... we don't want to mark events with no console logs as dropped
// this keeps the signal here clean and makes it easier to debug
// when we disable a team's console log ingestion
if (!event.metadata.consoleLogIngestionEnabled) {
return drop('console_log_ingestion_disabled')
}

try {
const consoleLogEvents = deduplicateConsoleLogEvents(
gatherConsoleLogEvents(event.team_id, event.session_id, event.events)
)

if (consoleLogEvents.length === 0) {
return
}

if (event.metadata.consoleLogIngestionEnabled) {
consoleLogEventsCounter.inc(consoleLogEvents.length)

return consoleLogEvents.map((cle: ConsoleLogEntry) =>
produce({
producer,
topic: KAFKA_LOG_ENTRIES,
value: Buffer.from(JSON.stringify(cle)),
key: event.session_id,
})
)
} else {
return drop('console_log_ingestion_disabled')
}
consoleLogEventsCounter.inc(consoleLogEvents.length)

return consoleLogEvents.map((cle: ConsoleLogEntry) =>
produce({
producer,
topic: KAFKA_LOG_ENTRIES,
value: Buffer.from(JSON.stringify(cle)),
key: event.session_id,
})
)
} catch (error) {
status.error('⚠️', '[console-log-events-ingester] processing_error', {
error: error,
Expand Down
2 changes: 1 addition & 1 deletion plugin-server/src/worker/ingestion/process-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function safeString(payload: (string | null)[]) {
.join(' ')
}

enum RRWebEventType {
export enum RRWebEventType {
DomContentLoaded = 0,
Load = 1,
FullSnapshot = 2,
Expand Down

0 comments on commit 1b390dc

Please sign in to comment.