Skip to content

Commit d29bfaa

Browse files
chore: updated more libs
1 parent 06bc97f commit d29bfaa

File tree

3 files changed

+70
-47
lines changed

3 files changed

+70
-47
lines changed

packages/core/src/tracing/instrumentation/cloud/aws-sdk/v3/sqs-consumer.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@ function instrument(SQSConsumer) {
2424
span.disableAutoEnd();
2525
const res = orig.apply(this, arguments);
2626

27-
res
28-
.then(() => {
29-
span.d = Date.now() - span.ts;
30-
span.transmitManual();
31-
})
32-
.catch(err => {
33-
span.ec = 1;
34-
tracingUtil.setErrorDetails(span, err, 'sqs');
35-
span.d = Date.now() - span.ts;
36-
span.transmitManual();
37-
});
27+
if (res && typeof res.then === 'function') {
28+
res
29+
.then(() => {
30+
span.d = Date.now() - span.ts;
31+
span.transmitManual();
32+
})
33+
.catch(err => {
34+
span.ec = 1;
35+
tracingUtil.setErrorDetails(span, err, 'sqs');
36+
span.d = Date.now() - span.ts;
37+
span.transmitManual();
38+
});
39+
} else {
40+
span.d = Date.now() - span.ts;
41+
span.transmitManual();
42+
}
3843

3944
return res;
4045
});
@@ -56,17 +61,22 @@ function instrument(SQSConsumer) {
5661
span.disableAutoEnd();
5762
const res = orig.apply(this, arguments);
5863

59-
res
60-
.then(() => {
61-
span.d = Date.now() - span.ts;
62-
span.transmitManual();
63-
})
64-
.catch(err => {
65-
span.ec = 1;
66-
tracingUtil.setErrorDetails(span, err, 'sqs');
67-
span.d = Date.now() - span.ts;
68-
span.transmitManual();
69-
});
64+
if (res && typeof res.then === 'function') {
65+
res
66+
.then(() => {
67+
span.d = Date.now() - span.ts;
68+
span.transmitManual();
69+
})
70+
.catch(err => {
71+
span.ec = 1;
72+
tracingUtil.setErrorDetails(span, err, 'sqs');
73+
span.d = Date.now() - span.ts;
74+
span.transmitManual();
75+
});
76+
} else {
77+
span.d = Date.now() - span.ts;
78+
span.transmitManual();
79+
}
7080

7181
return res;
7282
});

packages/core/src/tracing/instrumentation/control_flow/graphqlSubscriptions.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,23 @@ function shimPushValue(originalFunction) {
6262
function shimPullValue(originalFunction) {
6363
return function () {
6464
const pullPromise = originalFunction.apply(this, arguments);
65-
return pullPromise.then(result => {
66-
if (result && result.value && result.value[CLS_CONTEXT_SYMBOL]) {
67-
const clsContext = result.value[CLS_CONTEXT_SYMBOL];
68-
if (isActive && clsContext) {
69-
cls.ns.enter(clsContext);
70-
setImmediate(() => {
71-
cls.ns.exit(clsContext);
72-
});
65+
66+
if (pullPromise && typeof pullPromise.then === 'function') {
67+
return pullPromise.then(result => {
68+
if (result && result.value && result.value[CLS_CONTEXT_SYMBOL]) {
69+
const clsContext = result.value[CLS_CONTEXT_SYMBOL];
70+
if (isActive && clsContext) {
71+
cls.ns.enter(clsContext);
72+
setImmediate(() => {
73+
cls.ns.exit(clsContext);
74+
});
75+
}
7376
}
74-
}
75-
return result;
76-
});
77+
return result;
78+
});
79+
}
80+
81+
return pullPromise;
7782
};
7883
}
7984

packages/core/src/tracing/instrumentation/messaging/bull.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ function instrumentedJobCreate(ctx, originalJobCreate, originalArgs, options) {
111111
return err;
112112
});
113113
}
114+
115+
finishSpan(null, null, span);
114116
return promise;
115117
});
116118
}
@@ -261,20 +263,26 @@ function instrumentedProcessJob(ctx, originalProcessJob, originalArgs) {
261263

262264
const promise = originalProcessJob.apply(ctx, originalArgs);
263265

264-
return promise
265-
.then(data => {
266-
finishSpan(job.failedReason, data, span);
267-
// Make sure the instana foreigner data is removed.
268-
delete options.X_INSTANA_L;
269-
return data;
270-
})
271-
.catch(err => {
272-
addErrorToSpan(err, span);
273-
finishSpan(null, null, span);
274-
// Make sure the instana foreigner data is removed.
275-
delete options.X_INSTANA_L;
276-
throw err;
277-
});
266+
if (promise && typeof promise.then === 'function') {
267+
return promise
268+
.then(data => {
269+
finishSpan(job.failedReason, data, span);
270+
// Make sure the instana foreigner data is removed.
271+
delete options.X_INSTANA_L;
272+
return data;
273+
})
274+
.catch(err => {
275+
addErrorToSpan(err, span);
276+
finishSpan(null, null, span);
277+
// Make sure the instana foreigner data is removed.
278+
delete options.X_INSTANA_L;
279+
throw err;
280+
});
281+
}
282+
283+
finishSpan(null, null, span);
284+
delete options.X_INSTANA_L;
285+
return promise;
278286
});
279287
}
280288

0 commit comments

Comments
 (0)