Skip to content

Commit

Permalink
Clean await detector data after each method and publication
Browse files Browse the repository at this point in the history
  • Loading branch information
zodern committed Oct 15, 2024
1 parent cfa25ae commit 70a7d5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/hijack/wrap_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export function wrapSession (sessionProto) {
Kadira.tracer.event(kadiraInfo.trace, EventType.Complete);
}

awaitDetector.clean(kadiraInfo.awaitDetectorStore);
kadiraInfo.awaitDetectorStore = undefined;

// processing the message
let trace = Kadira.tracer.buildTrace(kadiraInfo.trace);
Kadira.EventBus.emit('method', 'methodCompleted', trace, this);
Expand All @@ -182,7 +185,14 @@ Meteor.server.publish_handlers = new Proxy(Meteor.server.publish_handlers, {
}

return function (...args) {
return awaitDetector.detect(() => origMethod.apply(this, args));
return awaitDetector.detect(() => {
let info = Kadira._getInfo();
if (info) {
info.awaitDetectorStore = awaitDetector.getStore();
}

return origMethod.apply(this, args);
});
};
}
});
Expand All @@ -205,7 +215,14 @@ Meteor.methods = function (methodMap) {
function wrapMethodHandlerForErrors (name, originalHandler, methodMap) {
methodMap[name] = function () {
try {
return awaitDetector.detect(() => originalHandler.apply(this, arguments));
return awaitDetector.detect(() => {
let info = Kadira._getInfo();
if (info) {
info.awaitDetectorStore = awaitDetector.getStore();
}

return originalHandler.apply(this, arguments);
});
} catch (ex) {
if (ex && Kadira._getInfo()) {
// sometimes error may be just a string or a primitive
Expand Down
7 changes: 7 additions & 0 deletions lib/hijack/wrap_subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MeteorDebugIgnore } from './error';
import { _ } from 'meteor/underscore';
import { runWithEnvironment } from '../async/als';
import { EventType } from '../constants';
import { awaitDetector } from '../async/async-hook';

export function wrapSubscription (subscriptionProto) {
let originalRunHandler = subscriptionProto._runHandler;
Expand Down Expand Up @@ -40,6 +41,9 @@ export function wrapSubscription (subscriptionProto) {
Kadira.tracer.endLastEvent(kadiraInfo.trace);
Kadira.tracer.event(kadiraInfo.trace, EventType.Complete);
trace = Kadira.tracer.buildTrace(kadiraInfo.trace);

awaitDetector.clean(kadiraInfo.awaitDetectorStore);
kadiraInfo.awaitDetectorStore = undefined;
}

Kadira.EventBus.emit('pubsub', 'subCompleted', trace, this._session, this);
Expand Down Expand Up @@ -68,6 +72,9 @@ export function wrapSubscription (subscriptionProto) {
Kadira.tracer.event(kadiraInfo.trace, EventType.Error, {error: errorForApm});
let trace = Kadira.tracer.buildTrace(kadiraInfo.trace);

awaitDetector.clean(kadiraInfo.awaitDetectorStore);
kadiraInfo.awaitDetectorStore = undefined;

Kadira.models.pubsub._trackError(this._session, this, trace);

// error tracking can be disabled and if there is a trace
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Package.describe({

let npmModules = {
debug: '0.8.1',
'@monti-apm/core': '2.0.0-beta.5',
'@monti-apm/core': '2.0.0-beta.6',
'lru-cache': '5.1.1',
'json-stringify-safe': '5.0.1',
'monti-apm-sketches-js': '0.0.3',
Expand Down

0 comments on commit 70a7d5e

Please sign in to comment.