|
9 | 9 | callback | 1 | 2 |
10 | 10 | */ |
11 | 11 | import { BasePlugin } from '@opentelemetry/core'; |
12 | | -import { Span, StatusCode, Attributes, SpanKind, context, suppressInstrumentation } from '@opentelemetry/api'; |
| 12 | +import { Span, StatusCode, Attributes, SpanKind, context, setSpan, suppressInstrumentation } from '@opentelemetry/api'; |
13 | 13 | import * as shimmer from 'shimmer'; |
14 | 14 | import AWS from 'aws-sdk'; |
15 | 15 | import { AttributeNames } from './enums'; |
@@ -48,8 +48,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> { |
48 | 48 |
|
49 | 49 | const origThen = target.then; |
50 | 50 | target.then = function (onFulfilled, onRejected) { |
51 | | - const newOnFulfilled = thisPlugin._tracer.bind(onFulfilled, span); |
52 | | - const newOnRejected = thisPlugin._tracer.bind(onRejected, span); |
| 51 | + const newOnFulfilled = context.bind(onFulfilled, setSpan(context.active(), span)); |
| 52 | + const newOnRejected = context.bind(onRejected, setSpan(context.active(), span)); |
53 | 53 | return origThen.call(this, newOnFulfilled, newOnRejected); |
54 | 54 | }; |
55 | 55 |
|
@@ -140,8 +140,8 @@ class AwsPlugin extends BasePlugin<typeof AWS> { |
140 | 140 | thisPlugin._callUserPreRequestHook(span, awsRequest); |
141 | 141 | thisPlugin._registerCompletedEvent(span, awsRequest); |
142 | 142 |
|
143 | | - const callbackWithContext = thisPlugin._tracer.bind(callback, span); |
144 | | - return thisPlugin._tracer.withSpan(span, () => { |
| 143 | + const callbackWithContext = context.bind(callback, setSpan(context.active(), span)); |
| 144 | + return context.with(setSpan(context.active(), span), () => { |
145 | 145 | thisPlugin.servicesExtensions.requestPostSpanHook(awsRequest); |
146 | 146 | return thisPlugin._callOriginalFunction(() => original.call(awsRequest, callbackWithContext)); |
147 | 147 | }); |
@@ -170,7 +170,7 @@ class AwsPlugin extends BasePlugin<typeof AWS> { |
170 | 170 | thisPlugin._callUserPreRequestHook(span, awsRequest); |
171 | 171 | thisPlugin._registerCompletedEvent(span, awsRequest); |
172 | 172 |
|
173 | | - const origPromise: Promise<any> = thisPlugin._tracer.withSpan(span, () => { |
| 173 | + const origPromise: Promise<any> = context.with(setSpan(context.active(), span), () => { |
174 | 174 | thisPlugin.servicesExtensions.requestPostSpanHook(awsRequest); |
175 | 175 | return thisPlugin._callOriginalFunction(() => original.call(awsRequest, arguments)); |
176 | 176 | }); |
|
0 commit comments