diff --git a/src/initializers/datadog/index.ts b/src/initializers/datadog/index.ts index 65951c36..139f9227 100644 --- a/src/initializers/datadog/index.ts +++ b/src/initializers/datadog/index.ts @@ -1,6 +1,5 @@ import requireInjected from '../../require-injected'; import { getLogger } from '../log4js'; -import { formats } from 'dd-trace/ext'; let tracer; export default config => { @@ -25,8 +24,10 @@ export const isDatadogEnabled = () => { return process.env.DD_SERVICE && process.env.DD_ENV; }; +let formats; export const injectTrace = (event: any) => { if (!isDatadogEnabled()) return; + formats = formats ?? requireInjected('dd-trace/ext').formats; const span = tracer?.scope()?.active(); if (span) { tracer.inject(span.context(), formats.LOG, event);