@@ -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 */
193193function 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