Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-next-instrumentation-redact.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"evlog": patch
---

fix(next): thread `redact` through `createInstrumentation().register()` β€” it previously re-initialised the logger without redaction and locked it, silently disabling `redact` configured for the Next.js instrumentation path
5 changes: 4 additions & 1 deletion packages/evlog/src/next/instrumentation-create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerDiskPrettyErrorSnippetReader } from '../shared/register-disk-snippet'
import type { DrainContext, EnvironmentContext, LogLevel, Log, SamplingConfig } from '../types'
import type { DrainContext, EnvironmentContext, LogLevel, Log, RedactConfig, SamplingConfig } from '../types'
import type {
NextInstrumentationErrorContext,
NextInstrumentationRequest,
Expand Down Expand Up @@ -58,6 +58,8 @@ export interface InstrumentationOptions {
stringify?: boolean
/** Drain callback called with every emitted event. */
drain?: (ctx: DrainContext) => void | Promise<void>
/** Auto-redaction configuration for PII protection. @default true in production */
redact?: boolean | RedactConfig
/** Capture stdout/stderr as structured log events (Node.js only). */
captureOutput?: boolean | CaptureOutputOptions
}
Expand Down Expand Up @@ -204,6 +206,7 @@ export function createInstrumentation(options: InstrumentationOptions = {}): Ins
minLevel: options.minLevel,
stringify: options.stringify,
drain: options.drain,
redact: options.redact,
})
lockLogger()
if (process.env.NEXT_RUNTIME === 'nodejs') {
Expand Down
2 changes: 2 additions & 0 deletions packages/evlog/test/next/instrumentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe('createInstrumentation', () => {
drain: drainMock,
sampling: { rates: { info: 50 } },
stringify: false,
redact: { paths: ['error.message', 'error.cause'] },
})

await runRegister(register)
Expand All @@ -93,6 +94,7 @@ describe('createInstrumentation', () => {
expect(config.drain).toBe(drainMock)
expect(config.sampling).toEqual({ rates: { info: 50 } })
expect(config.stringify).toBe(false)
expect(config.redact).toEqual({ paths: ['error.message', 'error.cause'] })
})

it('register() with captureOutput patches stdout and stderr', async () => {
Expand Down