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.

refactor(logs): keep the internal source service name in its policy (#128068)

Jon McCallumdf746bac56f3
diff --git a/nodejs/src/logs/internal-logs-producer.test.ts b/nodejs/src/logs/internal-logs-producer.test.ts
index 3aa98995ffc3..e53aeef00431 100644
--- a/nodejs/src/logs/internal-logs-producer.test.ts
+++ b/nodejs/src/logs/internal-logs-producer.test.ts
@@ -86,6 +86,7 @@ describe('InternalLogsProducer', () => {
source: 'hog_flow',
billed: false,
teamRules: false,
+ serviceName: 'posthog-internal-workflows',
})
const body = parseJSON(options!.body as string) as any
diff --git a/nodejs/src/logs/internal-logs-producer.ts b/nodejs/src/logs/internal-logs-producer.ts
index a133cf2660d8..58dcc7e2ab93 100644
--- a/nodejs/src/logs/internal-logs-producer.ts
+++ b/nodejs/src/logs/internal-logs-producer.ts
@@ -12,10 +12,6 @@ import type { ValueMatcher } from '~/types'
import type { LogsIngestionConsumerConfig } from './config'
import { INTERNAL_LOGS_HTTP_HEADER, INTERNAL_SOURCE_POLICIES, signInternalLogs } from './internal-logs'
-const SERVICE_NAMES: Readonly<Record<string, string>> = {
- hog_flow: 'posthog-internal-workflows',
-}
-
const SEVERITY_NUMBERS: Readonly<Record<string, number>> = { debug: 5, info: 9, warn: 13, error: 17 }
// Half of capture-logs' default 2 MiB body limit, which leaves room for the envelope.
@@ -101,11 +97,7 @@ export class InternalLogsProducer {
}
enqueue(source: string, entries: InternalLogEntry[]): void {
- if (
- !this.enabled ||
- !Object.hasOwn(INTERNAL_SOURCE_POLICIES, source) ||
- !Object.hasOwn(SERVICE_NAMES, source)
- ) {
+ if (!this.enabled || !Object.hasOwn(INTERNAL_SOURCE_POLICIES, source)) {
return
}
let invalid = 0
@@ -316,7 +308,7 @@ function takeRequest(batch: Batch): Request {
function toOtlpBody(source: string, records: string[]): string {
const resource = JSON.stringify({
- attributes: [{ key: 'service.name', value: { stringValue: SERVICE_NAMES[source] } }],
+ attributes: [{ key: 'service.name', value: { stringValue: INTERNAL_SOURCE_POLICIES[source].serviceName } }],
})
return `{"resourceLogs":[{"resource":${resource},"scopeLogs":[{"scope":${JSON.stringify({ name: source })},"logRecords":[${records.join(',')}]}]}]}`
}
diff --git a/nodejs/src/logs/internal-logs.test.ts b/nodejs/src/logs/internal-logs.test.ts
index e2c03ee3f9d4..65cf99db89b5 100644
--- a/nodejs/src/logs/internal-logs.test.ts
+++ b/nodejs/src/logs/internal-logs.test.ts
@@ -34,6 +34,7 @@ describe('InternalLogsVerifier', () => {
source: SOURCE,
billed: false,
teamRules: false,
+ serviceName: 'posthog-internal-workflows',
})
})
diff --git a/nodejs/src/logs/internal-logs.ts b/nodejs/src/logs/internal-logs.ts
index 86108a119fe8..f692fdaacae6 100644
--- a/nodejs/src/logs/internal-logs.ts
+++ b/nodejs/src/logs/internal-logs.ts
@@ -28,6 +28,8 @@ export type InternalSourcePolicy = {
billed: boolean
/** Runs the team's sampling, drop, transformation, metric and retention rules. */
teamRules: boolean
+ /** The `service.name` a producer stamps on this source's logs. */
+ serviceName: string
}
export type InternalLogs = InternalSourcePolicy & { source: string }
@@ -35,9 +37,9 @@ export type InternalLogs = InternalSourcePolicy & { source: string }
// A signer names the source and this map decides how it is handled, so a leaked key cannot invent
// a free source. Moving a source to billing changes its entry here, not the producer or the header.
export const INTERNAL_SOURCE_POLICIES: Readonly<Record<string, InternalSourcePolicy>> = {
- hog_flow: { billed: false, teamRules: false },
+ hog_flow: { billed: false, teamRules: false, serviceName: 'posthog-internal-workflows' },
// Each log_entries source moves unbilled, one at a time. Add a source when its producer starts signing.
- // hog_function: { billed: false, teamRules: false },
+ // hog_function: { billed: false, teamRules: false, serviceName: '...' },
}
type NotInternalReason =
diff --git a/nodejs/src/logs/logs-ingestion-consumer.test.ts b/nodejs/src/logs/logs-ingestion-consumer.test.ts
index ab611d77da6a..46507ce2e758 100644
--- a/nodejs/src/logs/logs-ingestion-consumer.test.ts
+++ b/nodejs/src/logs/logs-ingestion-consumer.test.ts
@@ -1104,7 +1104,9 @@ describe('LogsIngestionConsumer', () => {
},
{
samplingRulesCache: dropEverything as SamplingRulesCache,
- internalSourcePolicies: { hog_flow: { billed, teamRules: false } },
+ internalSourcePolicies: {
+ hog_flow: { billed, teamRules: false, serviceName: 'posthog-internal-workflows' },
+ },
}
)
// A quota limit drops every billed batch, so it applies only to the rows that test the internal bypass.