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 bc37bf7
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { diag, Span, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import { context, diag, Span, SpanKind, SpanStatusCode, trace } from '@opentelemetry/api';
import {
InstrumentationBase,
InstrumentationNodeModuleDefinition,
Expand Down Expand Up @@ -203,6 +203,13 @@ export class MySQLInstrumentation extends InstrumentationBase<

private _getConnectionCallbackPatchFn(cb: Function, format: formatType) {
const thisPlugin = this;
// If a parent span exists, bind the callback so that the parent span
// is still visible after we've gone through the MySQL pool code.
const activeContext = context.active();
const parentSpan = trace.getSpan(activeContext);
if (parentSpan && typeof cb === 'function') {
cb = context.bind(activeContext, cb);
}
return function () {
if (arguments[1]) {
// this is the callback passed into a query
Expand Down

0 comments on commit bc37bf7

Please sign in to comment.