-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(instrumentation-pg): ensure db.client.operation.duration metric is recorded for Promises API usage of pg #2480
Changes from 1 commit
5a7e89a
29bc7de
2120edf
21bebd3
fd844d6
f8fb951
a6bba4d
67ac071
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,7 @@ describe('pg-pool', () => { | |
await client.query('SELECT NOW()'); | ||
} finally { | ||
client.release(); | ||
await newPool.end(); | ||
} | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, 0); | ||
|
@@ -519,6 +520,11 @@ describe('pg-pool', () => { | |
); | ||
|
||
const metrics = resourceMetrics.scopeMetrics[0].metrics; | ||
assert.strictEqual( | ||
metrics[0].descriptor.name, | ||
'db.client.operation.duration' | ||
trentm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
|
||
assert.strictEqual( | ||
metrics[1].descriptor.name, | ||
'db.client.connection.count' | ||
|
@@ -567,5 +573,39 @@ describe('pg-pool', () => { | |
}); | ||
}); | ||
}); | ||
|
||
it('should generate `db.client.*` metrics (Promises-style)', async (...args) => { | ||
const client = await pool.connect(); | ||
|
||
try { | ||
const ret = await client.query('SELECT NOW()'); | ||
assert.ok(ret); | ||
} finally { | ||
client.release(); | ||
} | ||
|
||
const { resourceMetrics, errors } = await metricReader.collect(); | ||
assert.deepEqual( | ||
errors, | ||
[], | ||
'expected no errors from the callback during metric collection' | ||
); | ||
|
||
// We just test the expected metric *names* here. The particulars of the | ||
// metric values are already tested in other test cases. | ||
const metrics = resourceMetrics.scopeMetrics[0].metrics; | ||
assert.strictEqual( | ||
metrics[0].descriptor.name, | ||
'db.client.operation.duration' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you use the variable here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in commit 2120edf |
||
); | ||
assert.strictEqual( | ||
metrics[1].descriptor.name, | ||
'db.client.connection.count' | ||
); | ||
assert.strictEqual( | ||
metrics[2].descriptor.name, | ||
'db.client.connection.pending_requests' | ||
); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewer note: This is an unrelated change. It fixes a few-second hang in the test file completing (presumably on a pool connection timeout).