Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@instana/core

Package Overview
Dependencies
Maintainers
3
Versions
258
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@instana/core - npm Package Compare versions

Comparing version 1.69.0 to 1.69.1

src/tracing/clsHooked/unset.js

4

package.json
{
"name": "@instana/core",
"version": "1.69.0",
"version": "1.69.1",
"description": "Core library for Instana's Node.js packages",

@@ -128,3 +128,3 @@ "main": "src/index.js",

},
"gitHead": "af167706d3a739a3ec3b69af8d3a7db3b8b48179"
"gitHead": "7c8a6eaf7263dc7f0f1ea410a279b686b24b11a5"
}

@@ -14,2 +14,4 @@ 'use strict';

var currentSpanKey = (exports.currentSpanKey = 'com.instana.span');
var reducedSpanKey = (exports.reducedSpanKey = 'com.instana.reduced');
var tracingLevelKey = (exports.tracingLevelKey = 'com.instana.tl');

@@ -95,4 +97,10 @@ var processIdentityProvider = null;

/*
* Get the reduced backup of the last active span in this cls context.
*/
exports.getReducedSpan = function getReducedSpan() {
return exports.ns.get(reducedSpanKey);
};
/*
* Determine if we're currently tracing or not.
*
*/

@@ -99,0 +107,0 @@ exports.isTracing = function isTracing() {

@@ -14,2 +14,3 @@ /* eslint-env es6 */

const asyncHook = require('async-hook-jl');
const unset = require('./unset');

@@ -57,7 +58,3 @@ const CONTEXTS_SYMBOL = 'instanaClsHooked@contexts';

context[key] = value;
return function unset() {
if (context[key] === value) {
delete context[key];
}
};
return unset.bind(null, context, key, value);
};

@@ -64,0 +61,0 @@

@@ -14,2 +14,3 @@ /* eslint-env es6 */

const async_hooks = require('async_hooks');
const unset = require('./unset');

@@ -52,7 +53,3 @@ const CONTEXTS_SYMBOL = 'instanaClsHooked@contexts';

return function unset() {
if (context[key] === value) {
delete context[key];
}
};
return unset.bind(null, context, key, value);
};

@@ -59,0 +56,0 @@

@@ -24,3 +24,3 @@ 'use strict';

exports.isEntrySpan = function isEntrySpan(span) {
return span.k === exports.ENTRY;
return span && span.k === exports.ENTRY;
};

@@ -33,3 +33,3 @@

exports.isExitSpan = function isExitSpan(span) {
return span.k === exports.EXIT;
return span && span.k === exports.EXIT;
};

@@ -41,3 +41,3 @@

exports.isIntermediateSpan = function isIntermediateSpan(span) {
return span.k === exports.INTERMEDIATE;
return span && span.k === exports.INTERMEDIATE;
};

@@ -0,1 +1,3 @@

/* global Symbol */
'use strict';

@@ -10,7 +12,10 @@

var CLS_CONTEXT_SYMBOL = Symbol('_instana_cls_context');
exports.init = function() {
requireHook.onModuleLoad('graphql-subscriptions', instrument);
requireHook.onModuleLoad('graphql-subscriptions', instrumentModule);
requireHook.onFileLoad(/\/graphql-subscriptions\/dist\/pubsub-async-iterator\.js/, instrumentAsyncIterator);
};
function instrument(graphQlSubscriptions) {
function instrumentModule(graphQlSubscriptions) {
shimmer.wrap(graphQlSubscriptions.PubSub.prototype, 'publish', shimPublish);

@@ -20,3 +25,3 @@ }

function shimPublish(originalPublish) {
return function(triggerName, payload) {
return function() {
if (isActive && cls.isTracing()) {

@@ -27,13 +32,2 @@ // Keep cls context in GraphQL subscriptions by binding the associated event emitters.

}
var activeSpan = cls.getCurrentSpan();
if (activeSpan && payload && typeof payload === 'object') {
// Attach tracing context to payload to be able to retrieve it later in
// src/tracing/instrumentation/protocols/graphql - even though the event emitter is bound,
// cls context gets lost.
payload.__in = {
t: activeSpan.t,
s: activeSpan.s
};
}
}

@@ -44,2 +38,34 @@ return originalPublish.apply(this, arguments);

function instrumentAsyncIterator(pubSubAsyncIterator) {
shimmer.wrap(pubSubAsyncIterator.PubSubAsyncIterator.prototype, 'pushValue', shimPushValue);
shimmer.wrap(pubSubAsyncIterator.PubSubAsyncIterator.prototype, 'pullValue', shimPullValue);
}
function shimPushValue(originalFunction) {
return function(event) {
if (isActive && event && typeof event === 'object' && cls.ns.active) {
event[CLS_CONTEXT_SYMBOL] = cls.ns.active;
}
return originalFunction.apply(this, arguments);
};
}
function shimPullValue(originalFunction) {
return function() {
var pullPromise = originalFunction.apply(this, arguments);
return pullPromise.then(function(result) {
if (result && result.value && result.value[CLS_CONTEXT_SYMBOL]) {
var clsContext = result.value[CLS_CONTEXT_SYMBOL];
if (isActive && clsContext) {
cls.ns.enter(clsContext);
setImmediate(function() {
cls.ns.exit(clsContext);
});
}
}
return result;
});
};
}
exports.activate = function() {

@@ -46,0 +72,0 @@ isActive = true;

@@ -80,3 +80,3 @@ 'use strict';

var parentSpan = cls.getCurrentSpan();
if (parentSpan && constants.isExitSpan(parentSpan)) {
if (!parentSpan || constants.isExitSpan(parentSpan)) {
return;

@@ -94,3 +94,3 @@ }

if (parentSpan && (traceId == null || parentSpanId == null)) {
if (traceId == null || parentSpanId == null) {
// either event.operationId has not been present or event.operationId did not have a traceId/parentSpanId set.

@@ -103,43 +103,46 @@ traceId = parentSpan.t;

// We could not find the trace ID/parent span ID, neither via the operation ID mechanism nor the getCurrentSpan()
// way - give up finally.
// way - give up.
return;
}
var span = cls.startSpan('mongo', constants.EXIT, traceId, parentSpanId, false);
cls.ns.run(function(clsContext) {
var span = cls.startSpan('mongo', constants.EXIT, traceId, parentSpanId, false);
var peer = null;
var service = null;
if (event.connectionId && (event.connectionId.host || event.connectionId.port)) {
peer = {
hostname: event.connectionId.host,
port: event.connectionId.port
var peer = null;
var service = null;
if (event.connectionId && (event.connectionId.host || event.connectionId.port)) {
peer = {
hostname: event.connectionId.host,
port: event.connectionId.port
};
service = event.connectionId.host + ':' + event.connectionId.port;
} else if (typeof event.connectionId === 'string') {
peer = parseConnectionToPeer(event.connectionId);
service = event.connectionId;
}
var database = event.databaseName;
var collection = event.command.collection || event.command[event.commandName];
// using the Mongodb instrumentation API, it is not possible to gather stack traces.
span.stack = [];
span.data = {
peer: peer,
mongo: {
command: event.commandName,
service: service,
namespace: database + '.' + collection,
filter: stringifyWhenNecessary(event.command.filter),
query: stringifyWhenNecessary(event.command.query)
}
};
service = event.connectionId.host + ':' + event.connectionId.port;
} else if (typeof event.connectionId === 'string') {
peer = parseConnectionToPeer(event.connectionId);
service = event.connectionId;
}
var database = event.databaseName;
var collection = event.command.collection || event.command[event.commandName];
// using the Mongodb instrumentation API, it is not possible to gather stack traces.
span.stack = [];
span.data = {
peer: peer,
mongo: {
command: event.commandName,
service: service,
namespace: database + '.' + collection,
filter: stringifyWhenNecessary(event.command.filter),
query: stringifyWhenNecessary(event.command.query)
if (event.operationId) {
event.operationId.traceId = span.t;
event.operationId.parentSpanId = span.p;
}
};
if (event.operationId) {
event.operationId.traceId = span.t;
event.operationId.parentSpanId = span.p;
}
var requestId = getUniqueRequestId(event);
clsContextMap[requestId] = cls.ns.active;
mongoDbSpansInProgress[requestId] = span;
var requestId = getUniqueRequestId(event);
clsContextMap[requestId] = clsContext;
mongoDbSpansInProgress[requestId] = span;
});
}

@@ -183,2 +186,5 @@

cleanup(event);
setImmediate(function() {
cls.ns.exit(clsContext);
});
}

@@ -215,2 +221,5 @@ }

cleanup(event);
setImmediate(function() {
cls.ns.exit(clsContext);
});
}

@@ -217,0 +226,0 @@ }

@@ -44,11 +44,8 @@ 'use strict';

var operationName;
var rootValue;
if (originalArgs.length === 1 && typeof originalArgs[0] === 'object') {
doc = originalArgs[0].document;
rootValue = originalArgs[0].rootValue;
operationName = originalArgs[0].operationName;
} else {
doc = originalArgs[1];
rootValue = originalArgs[2];
operationName = originalArgs[5];

@@ -76,4 +73,3 @@ }

operationDefinition,
operationName,
rootValue
operationName
);

@@ -164,27 +160,11 @@ } else {

operationDefinition,
operationName,
rootValue
operationName
) {
var traceId;
var parentSpanId;
if (rootValue && rootValue.__in) {
// Case 1: We saw the call to graphql-subscriptions/PubSub.publish
// (see src/tracing/instrumentation/control_flow/graphqlSubscriptions.js) and have attached the then active trace ID
// and span ID to the payload.
traceId = rootValue.__in.t;
parentSpanId = rootValue.__in.s;
} else {
// Case 2: We did not see the call to graphql-subscriptions/PubSub.publish.
// Try to find a parent span via CLS (very unreliable with graphql-subscriptions).
var parentSpan = cls.getCurrentSpan();
if (!constants.isExitSpan(parentSpan)) {
traceId = parentSpan.t;
parentSpanId = parentSpan.s;
}
if (!isActive) {
return originalFunction.apply(originalThis, originalArgs);
}
if (isActive && traceId && parentSpanId) {
var parentSpan = cls.getCurrentSpan() || cls.getReducedSpan();
if (parentSpan && !constants.isExitSpan(parentSpan) && parentSpan.t && parentSpan.s) {
return cls.ns.runAndReturn(function() {
var span = cls.startSpan('graphql.client', constants.EXIT, traceId, parentSpanId);
var span = cls.startSpan('graphql.client', constants.EXIT, parentSpan.t, parentSpan.s);
span.ts = Date.now();

@@ -201,3 +181,2 @@ span.stack = tracingUtil.getStackTrace(stackTraceRef);

addFieldsAndArguments(span, operationDefinition);
return runOriginalAndFinish(originalFunction, originalThis, originalArgs, span);

@@ -204,0 +183,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc