diff --git a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts index 301b85e51d..97d7af9fc3 100644 --- a/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-mysql/src/instrumentation.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api'; +import { context, diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api'; import { InstrumentationBase, InstrumentationNodeModuleDefinition, @@ -203,6 +203,7 @@ export class MySQLInstrumentation extends InstrumentationBase< private _getConnectionCallbackPatchFn(cb: Function, format: formatType) { const thisPlugin = this; + const activeContext = context.active(); return function () { if (arguments[1]) { // this is the callback passed into a query @@ -216,7 +217,9 @@ export class MySQLInstrumentation extends InstrumentationBase< } } if (typeof cb === 'function') { - cb(...arguments); + context.with(activeContext, () => { + cb(...arguments); + }); } }; }