-
Notifications
You must be signed in to change notification settings - Fork 381
Closed
Labels
Description
Expected behaviour
Mocha hooks should be traced (have active span). Test level hooks belong to appropriate test span.
Actual behaviour
BeforeAll and first beforeEach hooks doesn't have active span. BeforeEach hooks starting from the 2nd one belong to span of the previous test.
Steps to reproduce
Short test to illustrate this behaviour:
const {createLogger, transports, format} = require("winston");
const tracer = require('dd-trace');
const loggerWinston = createLogger({
level: 'info',
format: format.json(),
transports: [new transports.Console(), new transports.File({
filename: `./my.log`,
})],
});
describe('DD Logs Suit', function () {
before(async () =>{
const span = tracer.scope().active();
console.log(`Before all span: ${span?.context().toTraceId()}`)
loggerWinston.info("Before all")
})
after(async () =>{
const span = tracer.scope().active();
console.log(`After all span: ${span?.context().toTraceId()}`)
loggerWinston.info("After all")
})
beforeEach(async () =>{
const span = tracer.scope().active();
console.log(`Before each span: ${span?.context().toTraceId()}`)
loggerWinston.info("Before each")
})
afterEach(async () =>{
const span = tracer.scope().active();
console.log(`After each span: ${span?.context().toTraceId()}`)
loggerWinston.info("After each")
})
it('Test 1', async function () {
const span = tracer.scope().active();
console.log(`Test span: ${span?.context().toTraceId()}`)
loggerWinston.info({message: "Winston Logger"})
})
it('Test 2', async function () {
const span = tracer.scope().active();
console.log(`Test span: ${span?.context().toTraceId()}`)
loggerWinston.info({message: "Winston Logger"})
})
})
Output would be something like this:
DD Logs Suit
Before all span: undefined
...
Before each span: undefined
...
Test span: 7007257701732416091
...
✔ Test 1
After each span: 7007257701732416091
...
Before each span: 7007257701732416091 //Wrong span!! should belong to the span of the next test, but is assigned to the already finished test
...
Test span: 298910298997552109
...
✔ Test 2
After each span: 298910298997552109
...
After all span: 298910298997552109
Environment
- Operation system: mac os Big sure 11.2.3
- Node.js version: v14.16.0
- Tracer version: 2.7.1
- Agent version: 7
- Relevant library versions: winston 3.3.3, mocha 10.0.0 (same with 8.4.0)
Reactions are currently unavailable