Skip to content

Commit

Permalink
fix(mysql): bind get connection callback to active context
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Stone <simonstone1@gmail.com>
  • Loading branch information
sstone1 authored and Simon Stone committed Jul 5, 2021
1 parent 52b46aa commit 3454156
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -14,7 +14,13 @@
* limitations under the License.
*/

import { diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import {
context,
diag,
Span,
SpanKind,
SpanStatusCode,
} from '@opentelemetry/api';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
Expand Down Expand Up @@ -203,6 +209,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
Expand All @@ -216,7 +223,9 @@ export class MySQLInstrumentation extends InstrumentationBase<
}
}
if (typeof cb === 'function') {
cb(...arguments);
context.with(activeContext, () => {
cb(...arguments);
});
}
};
}
Expand Down

0 comments on commit 3454156

Please sign in to comment.