Skip to content

Commit

Permalink
Address final review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelff committed Feb 2, 2023
1 parent 4f789b9 commit cb2f326
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
7 changes: 2 additions & 5 deletions packages/client/tests/functional/logging/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ testMatrix.setupTestSuite((suiteConfig, _suiteMeta, clientMeta) => {
expect(queryLogEvents).toHaveProperty('query')
expect(queryLogEvents).toHaveProperty('duration')
expect(queryLogEvents).toHaveProperty('timestamp')
expect(queryLogEvents).toHaveProperty('params')
expect(queryLogEvents).toHaveProperty('target')

if (suiteConfig.provider === 'mongodb') {
expect(queryLogEvents.query).toContain('db.User.aggregate')
} else {
expect(queryLogEvents.query).toContain('SELECT')
}

if (!clientMeta.dataProxy) {
expect(queryLogEvents).toHaveProperty('params')
expect(queryLogEvents).toHaveProperty('target')
}
})

test('should log queries inside a ITX', async () => {
Expand Down
14 changes: 6 additions & 8 deletions packages/engine-core/src/data-proxy/DataProxyEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type DataProxyLog = {
name: string
level: LogLevel
timestamp: [number, number]
attributes: Record<string, unknown> & { duration_ms: number }
attributes: Record<string, unknown> & { duration_ms: number; params: string; target: string }
}

type DataProxyExtensions = {
Expand Down Expand Up @@ -92,7 +92,6 @@ class DataProxyHeaderBuilder {
tracingConfig: TracingConfig
logLevel: EngineConfig['logLevel']
logQueries: boolean | undefined
engine: DataProxyEngine
}) {
this.apiKey = apiKey
this.tracingConfig = tracingConfig
Expand Down Expand Up @@ -172,7 +171,6 @@ export class DataProxyEngine extends Engine<DataProxyTxInfoPayload> {
tracingConfig: getTracingConfig(this.config.previewFeatures || []),
logLevel: config.logLevel,
logQueries: config.logQueries,
engine: this,
})

this.remoteClientVersion = P.then(() => getClientVersion(this.config))
Expand Down Expand Up @@ -203,11 +201,11 @@ export class DataProxyEngine extends Engine<DataProxyTxInfoPayload> {
case 'trace':
case 'warn':
case 'info':
// TODO these are propgated into the response.errors key
// TODO these are propagated into the response.errors key
break
case 'query': {
let dbQuery =
typeof log.attributes?.query === 'string' && log.attributes?.query ? log.attributes.query : log.name
let dbQuery = typeof log.attributes.query === 'string ? log.attributes.query : ''

if (!tracingConfig.enabled) {
// The engine uses tracing to consolidate logs
// - and so we should strip the generated traceparent
Expand All @@ -221,8 +219,8 @@ export class DataProxyEngine extends Engine<DataProxyTxInfoPayload> {
query: dbQuery,
timestamp: log.timestamp,
duration: log.attributes.duration_ms,
// params: log.params - Missing
// target: log.target - Missing
params: log.attributes.params,
target: log.attributes.target,
})
}
}
Expand Down

0 comments on commit cb2f326

Please sign in to comment.