Skip to content

Commit

Permalink
Fixes #16 - Promise.all structures produce unlinked spans
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Apr 7, 2020
1 parent d6b4243 commit cd4de5d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions spec/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,38 @@ describe("mongoose opentelemetry plugin", () => {
})
})
})

it("instrumenting combined operation with Promise.all", async (done) => {
const span = provider.getTracer('default').startSpan('test span');
provider.getTracer('default').withSpan(span, () => {
Promise.all([
User
.find({id: "_test"})
.skip(1)
.limit(2)
.sort({email: 'asc'}),
User.countDocuments()
])
.then((users) => {
const spans: ReadableSpan[] = memoryExporter.getFinishedSpans();

expect(spans.length).toBe(2)

// same spanId
expect([...new Set(spans.map((span: ReadableSpan) => span.spanContext.traceId))].length).toBe(1)

assertSpan(spans[0])
assertSpan(spans[1])

expect(spans[0].attributes[AttributeNames.DB_MODEL_NAME]).toEqual('User')
expect(spans[0].attributes[AttributeNames.DB_QUERY_TYPE]).toMatch(/^(find|countDocuments)$/g)

expect(spans[1].attributes[AttributeNames.DB_MODEL_NAME]).toEqual('User')
expect(spans[1].attributes[AttributeNames.DB_QUERY_TYPE]).toMatch(/^(find|countDocuments)$/g)

done()
})
})
})
})
});

0 comments on commit cd4de5d

Please sign in to comment.