Closed JohnDaly closed 1 year ago
After some more investigation, the problem seems to occur when Mocha is loaded after the tracer is initialized.
Here's a minimal repro:
// Initialize dd-trace
const { tracer } = require('dd-trace');
tracer.init();
// Simulate 'mocha' being loaded in another module
require('mocha');
// Tests
const assert = require('assert');
describe('Sample', function () {
it('should pass', function () {
assert.equal(1 + 1, 2);
});
});
hi @JohnDaly ! Thanks for the detailed description and the reproducible case.
As a note, keep in mind that the way to initialise dd-trace
to use CI Visibility (where the mocha
plugin reports) is through dd-trace/ci/init
: https://docs.datadoghq.com/continuous_integration/tests/javascript/?tab=onpremisesciproviderdatadogagent#instrument-your-tests. The ci
prefix in the init
makes sure that the correct exporter is used.
Whatever the case, this error should not happen with any exporter so I'll get to fixing this.
https://github.com/DataDog/dd-trace-js/pull/2711 should do the trick 😄
Expected behaviour
dd-trace
should allow a Mocha test suite to run when using the standardAgentExporter
Actual behaviour When trying to run a Mocha test suite, I get the following error:
Steps to reproduce
As far as I can tell, here is what seems to be happening:
The Exporter for the
tracer
is being set toAgentExporter
whenconfig.experimental.exporter
is not provided: https://github.com/DataDog/dd-trace-js/blob/a96389bc5de239da74769f6fb8cfdfbcefb8e386/packages/dd-trace/src/opentracing/tracer.js#L23https://github.com/DataDog/dd-trace-js/blob/a96389bc5de239da74769f6fb8cfdfbcefb8e386/packages/dd-trace/src/exporter.js#L25
ITR Configuration Channel is set up here: https://github.com/DataDog/dd-trace-js/blob/a96389bc5de239da74769f6fb8cfdfbcefb8e386/packages/datadog-instrumentations/src/mocha.js#L20
Event is published to that channel here, when Mocha starts: https://github.com/DataDog/dd-trace-js/blob/a96389bc5de239da74769f6fb8cfdfbcefb8e386/packages/datadog-instrumentations/src/mocha.js#L358
Published event is handled is called here: https://github.com/DataDog/dd-trace-js/blob/a96389bc5de239da74769f6fb8cfdfbcefb8e386/packages/dd-trace/src/plugins/ci_plugin.js#L19
Handler fails because the
_exporter
(AgentExporter
) on the tracer was never set up with agetItrConfiguration
function.Environment