Skip to content

Commit bf4328f

Browse files
committed
harden logger
1 parent f7d6d13 commit bf4328f

16 files changed

Lines changed: 435 additions & 108 deletions

File tree

apps/engine/src/api/app.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const ndjsonRef = {
3737
SourceInputMessage: { $ref: '#/components/schemas/SourceInputMessage' },
3838
}
3939
import { ndjsonResponse } from '@stripe/sync-ts-cli/ndjson'
40+
import { REQUEST_HEADER_REDACT } from '@stripe/sync-logger'
4041
import { logger } from '../logger.js'
4142
import {
4243
sslConfigFromConnectionString,
@@ -142,28 +143,22 @@ export async function createApp(resolver: ConnectorResolver) {
142143
}
143144
})
144145
logger.debug(
145-
{ requestId, method: c.req.method, path: c.req.path, headers },
146+
{ requestId, method: c.req.method, path: c.req.path, request_headers: headers },
146147
'request headers'
147148
)
148149
}
149150
logger.info({ requestId, method: c.req.method, path: c.req.path }, 'request start')
150151
if (dangerouslyVerbose) {
151152
const curlParts = [`curl -X ${c.req.method} '${c.req.url}'`]
152153
c.req.raw.headers.forEach((value, key) => {
153-
curlParts.push(` -H '${key}: ${value}'`)
154+
curlParts.push(
155+
REQUEST_HEADER_REDACT.has(key.toLowerCase())
156+
? ` -H '${key}: [REDACTED]'`
157+
: ` -H '${key}: ${value}'`
158+
)
154159
})
155160
if (hasBody(c)) {
156-
const cl = c.req.header('Content-Length')
157-
if (cl && Number(cl) < 100_000) {
158-
try {
159-
const body = await c.req.raw.clone().text()
160-
curlParts.push(` -d '${body.replace(/'/g, "'\\''")}'`)
161-
} catch {
162-
/* skip */
163-
}
164-
} else {
165-
curlParts.push(' --data-binary @-')
166-
}
161+
curlParts.push(' --data-binary @-')
167162
}
168163
logger.debug(curlParts.join(' \\\n'))
169164
}

apps/engine/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { createLogger } from '@stripe/sync-logger'
22

3-
export const logger = createLogger({ name: 'engine', pretty: !!process.env.LOG_PRETTY })
3+
export const logger = createLogger({ name: 'engine' })

apps/service/src/temporal/activities/pipeline-sync.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ApplicationFailure } from '@temporalio/activity'
22
import type { SourceInputMessage, SourceReadOptions } from '@stripe/sync-engine'
3+
import { logger } from '../../logger.js'
34
import type { ActivitiesContext } from './_shared.js'
45
import { asIterable, drainMessages, type RunResult } from './_shared.js'
56
import { classifySyncErrors, summarizeSyncErrors } from '../sync-errors.js'
@@ -33,7 +34,8 @@ export function createPipelineSyncActivity(context: ActivitiesContext) {
3334
const { transient, permanent } = classifySyncErrors(errors)
3435
if (permanent.length > 0) {
3536
if (transient.length > 0) {
36-
console.warn(
37+
logger.warn(
38+
{ transientCount: transient.length, permanentCount: permanent.length },
3739
`Transient errors suppressed by permanent failures: ${summarizeSyncErrors(transient)}`
3840
)
3941
}

packages/destination-postgres/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"src"
2424
],
2525
"dependencies": {
26+
"@stripe/sync-logger": "workspace:*",
2627
"@stripe/sync-protocol": "workspace:*",
2728
"@stripe/sync-util-postgres": "workspace:*",
2829
"pg": "^8.16.3",

packages/destination-postgres/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pg from 'pg'
22
import type { PoolConfig } from 'pg'
33
import type { Destination, DestinationInput, LogMessage } from '@stripe/sync-protocol'
4+
import { createConnectorLogger } from '@stripe/sync-logger'
45
import {
56
sql,
67
sslConfigFromConnectionString,
@@ -13,6 +14,8 @@ import { buildCreateTableDDL } from './schemaProjection.js'
1314
import defaultSpec from './spec.js'
1415
import type { Config } from './spec.js'
1516

17+
const logger = createConnectorLogger('destination-postgres')
18+
1619
function logMsg(message: string, level: LogMessage['log']['level'] = 'info'): LogMessage {
1720
return { type: 'log', log: { level, message } }
1821
}
@@ -109,7 +112,7 @@ function createPool(config: PoolConfig): pg.Pool {
109112
const pool = new pg.Pool(config)
110113
// Destination connectors should surface pool failures without crashing the host process.
111114
pool.on('error', (err) => {
112-
console.error('Postgres destination pool error:', err)
115+
logger.error({ err }, 'Postgres destination pool error')
113116
})
114117
return pool
115118
}

packages/logger/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export {
22
createLogger,
33
createConnectorLogger,
4+
REQUEST_HEADER_REDACT,
45
type CreateLoggerOptions,
56
type Logger,
67
} from './logger.js'

0 commit comments

Comments
 (0)