[x] I checked the documentation and found no answer
[x] I checked to make sure that this issue has not already been filed
[x] I'm reporting the issue to the correct repository
Current Behavior
Using the approach documented in Datadog's docs for injecting trace and span IDs into JSON logs does not work. The logs do not contain a trace and span ID.
Expected Behavior
Because moleculer is using dd-trace, I expect to be able to use dd-trace's documented functionality and have moleculer-reported traces available for log injection.
Failure Information
Steps to Reproduce
Create a project with the moleculer.config.js below.
Datadog tracing exporter
Custom console log formatter that injects trace IDs into JSON logs.
I also tried getting this.broker.tracer.getCurrentTraceID() and this.broker.tracer.getActiveSpanID() to inject the logs manually instead of tracer.scope().active(), but that ultimately gets the same underlying data from dd-trace.
Context
Moleculer version: 0.14.4
NodeJS version: 12.16.1
Operating System: macOS 10.15.3
Notes
After looking through the moleculer and dd-trace code, I believe moleculer is not properly setting the active span in dd-trace. I'm currently experimenting with calling this.ddScope._before(asyncId) after this.ddScope._spans[asyncId] = ddSpan in DatadogTraceExporter.spanStarted and this.ddScope._after() after ddSpan.finish(span.finishTime) in DatadogTraceExporter.spanFinished.
This report uses manual trace ID injection with the moleculer logger. dd-trace also supports auto injection for bunyan, pino, and winston loggers. I have not tried using those loggers in moleculer.config.js, but I imagine the same issue will exist.
Prerequisites
Current Behavior
Using the approach documented in Datadog's docs for injecting trace and span IDs into JSON logs does not work. The logs do not contain a trace and span ID.
Expected Behavior
Because moleculer is using
dd-trace
, I expect to be able to use dd-trace's documented functionality and have moleculer-reported traces available for log injection.Failure Information
Steps to Reproduce
Reproduce code snippet
I also tried getting
this.broker.tracer.getCurrentTraceID()
andthis.broker.tracer.getActiveSpanID()
to inject the logs manually instead oftracer.scope().active()
, but that ultimately gets the same underlying data fromdd-trace
.Context
Notes
After looking through the moleculer and dd-trace code, I believe moleculer is not properly setting the active span in dd-trace. I'm currently experimenting with calling
this.ddScope._before(asyncId)
afterthis.ddScope._spans[asyncId] = ddSpan
inDatadogTraceExporter.spanStarted
andthis.ddScope._after()
afterddSpan.finish(span.finishTime)
inDatadogTraceExporter.spanFinished
.This report uses manual trace ID injection with the moleculer logger. dd-trace also supports auto injection for
bunyan
,pino
, andwinston
loggers. I have not tried using those loggers in moleculer.config.js, but I imagine the same issue will exist.