Skip to content

Commit ea19d7d

Browse files
committed
test(mongodb): target bulkWrite peer service parent
1 parent 571fe98 commit ea19d7d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/datadog-plugin-mongodb-core/test/mongodb.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ describe('Plugin', () => {
119119
() => collection.bulkWrite([{ insertOne: { document: { a: 1 } } }]),
120120
'test',
121121
'peer.service',
122-
{ component: 'mongodb', desc: 'with bulkWrite' }
122+
{
123+
component: 'mongodb',
124+
desc: 'with bulkWrite',
125+
resource: () => `bulkWrite test.${collectionName}`,
126+
}
123127
)
124128

125129
it('should do automatic instrumentation', done => {

packages/dd-trace/test/setup/mocha.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function withNamingSchema (
188188
* @param {((callback: (error?: Error) => void) => unknown) | (() => Promise<unknown>)} spanGenerationFn
189189
* @param {string | (() => string)} service
190190
* @param {string} serviceSource
191-
* @param {{ component?: string, desc?: string }} [opts]
191+
* @param {{ component?: string, desc?: string, resource?: string | (() => string) }} [opts]
192192
*/
193193
function withPeerService (tracer, pluginName, spanGenerationFn, service, serviceSource, opts = {}) {
194194
describe('peer service computation' + (opts.desc ? ` ${opts.desc}` : ''), function () {
@@ -214,16 +214,18 @@ function withPeerService (tracer, pluginName, spanGenerationFn, service, service
214214
let traceAssertion
215215

216216
/**
217-
* @param {Array<Array<{ trace_id: bigint, meta: Record<string, string> }>>} traces
217+
* @param {Array<Array<{ trace_id: bigint, resource: string, meta: Record<string, string> }>>} traces
218218
*/
219219
function assertPeerServiceSpan (traces) {
220220
const expectedService = typeof service === 'function' ? service() : service
221+
const expectedResource = typeof opts.resource === 'function' ? opts.resource() : opts.resource
221222

222223
for (const trace of traces) {
223224
for (const span of trace) {
224225
if (
225226
span.trace_id === traceId &&
226227
span.meta.component === component &&
228+
(expectedResource === undefined || span.resource === expectedResource) &&
227229
span.meta['peer.service'] === expectedService &&
228230
span.meta['_dd.peer.service.source'] === serviceSource
229231
) {

0 commit comments

Comments
 (0)