Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const spanBuffer=require("./spanBuffer"),tracingUtil=require("./tracingUtil"),{ENTRY,EXIT,INTERMEDIATE,isExitSpan}=require("./constants"),hooked=require("./clsHooked"),tracingMetrics=require("./metrics");let logger;logger=require("../logger").getLogger("tracing/cls",newLogger=>{logger=newLogger});const currentEntrySpanKey="com.supertenant.entry",currentSpanKey="com.supertenant.span",reducedSpanKey="com.supertenant.reduced",tracingLevelKey="com.supertenant.tl",w3cTraceContextKey="com.supertenant.w3ctc";let serviceName,processIdentityProvider=null;const ns=hooked.createNamespace("supertenant.supermeter");function init(config,_processIdentityProvider){config&&config.serviceName&&(serviceName=config.serviceName),processIdentityProvider=_processIdentityProvider}class InstanaSpan{constructor(name){this.t=void 0,this.s=void 0,this.p=void 0,this.n=name,this.k=void 0,processIdentityProvider&&"function"==typeof processIdentityProvider.getFrom&&(this.f=processIdentityProvider.getFrom()),this.ec=0,this.ts=Date.now(),this.d=0,this.stack=[],this.data={},Object.defineProperty(this,"cleanupFunctions",{value:[],writable:!1,enumerable:!1}),Object.defineProperty(this,"transmitted",{value:!1,writable:!0,enumerable:!1}),Object.defineProperty(this,"pathTplFrozen",{value:!1,writable:!0,enumerable:!1}),Object.defineProperty(this,"manualEndMode",{value:!1,writable:!0,enumerable:!1}),Object.defineProperty(this,"postponeTransmit",{value:!1,configurable:!0,writable:!0,enumerable:!1}),Object.defineProperty(this,"postponeTransmitApolloGateway",{value:!1,configurable:!0,writable:!0,enumerable:!1}),this.b=void 0,this.postponeTransmit=void 0}addCleanup(fn){this.cleanupFunctions.push(fn)}transmit(){this.transmitted||this.manualEndMode||(spanBuffer.addSpan(this),this.cleanup(),tracingMetrics.incrementClosed(),this.transmitted=!0)}transmitManual(){this.transmitted||(spanBuffer.addSpan(this),this.cleanup(),tracingMetrics.incrementClosed(),this.transmitted=!0)}cancel(){this.transmitted||(this.cleanup(),tracingMetrics.incrementClosed(),this.transmitted=!0)}cleanup(){this.cleanupFunctions.forEach(call),this.cleanupFunctions.length=0}freezePathTemplate(){this.pathTplFrozen=!0}disableAutoEnd(){this.manualEndMode=!0}}class InstanaPseudoSpan extends InstanaSpan{transmit(){this.transmitted||this.manualEndMode||(this.cleanup(),this.transmitted=!0)}transmitManual(){this.transmitted||(this.cleanup(),this.transmitted=!0)}cancel(){this.transmitted||(this.cleanup(),this.transmitted=!0)}}function startSpan(spanName,kind,traceId,parentSpanId,w3cTraceContext){tracingMetrics.incrementOpened(),kind&&(kind===ENTRY||kind===EXIT||kind===INTERMEDIATE)||(logger.warn("Invalid span (%s) without kind/with invalid kind: %s, assuming EXIT.",spanName,kind),kind=EXIT);var spanName=new InstanaSpan(spanName),kind=(spanName.k=kind,getCurrentSpan()),parentW3cTraceContext=getW3cTraceContext();return null!=serviceName&&(spanName.data.service=serviceName),traceId?(spanName.t=traceId,parentSpanId&&(spanName.p=parentSpanId)):kind?(spanName.t=kind.t,spanName.p=kind.s):spanName.t=tracingUtil.generateRandomTraceId(),spanName.s=tracingUtil.generateRandomSpanId(),(w3cTraceContext=!w3cTraceContext&&parentW3cTraceContext?parentW3cTraceContext.clone():w3cTraceContext)&&(w3cTraceContext.updateParent(spanName.t,spanName.s),spanName.addCleanup(ns.set(w3cTraceContextKey,w3cTraceContext))),spanName.k===ENTRY&&spanName.addCleanup(ns.set(currentEntrySpanKey,spanName)),spanName.addCleanup(ns.set(currentSpanKey,spanName)),spanName}function putPseudoSpan(spanName,kind,traceId,spanId){kind&&(kind===ENTRY||kind===EXIT||kind===INTERMEDIATE)||(logger.warn("Invalid pseudo span (%s) without kind/with invalid kind: %s, assuming EXIT.",spanName,kind),kind=EXIT);var span=new InstanaPseudoSpan(spanName);if(span.k=kind,traceId){if(spanId)return span.t=traceId,span.s=spanId,span.k===ENTRY&&span.addCleanup(ns.set(currentEntrySpanKey,span)),span.addCleanup(ns.set(currentSpanKey,span)),span;logger.warn("Cannot start a pseudo span without a span ID",spanName,kind)}else logger.warn("Cannot start a pseudo span without a trace ID",spanName,kind)}function getCurrentEntrySpan(){return ns.get(currentEntrySpanKey)}function setCurrentSpan(span){ns.set(currentSpanKey,span)}function getCurrentSpan(fallbackToSharedContext=!1){return ns.get(currentSpanKey,fallbackToSharedContext)}function getReducedSpan(fallbackToSharedContext=!1){return ns.get(reducedSpanKey,fallbackToSharedContext)}function setW3cTraceContext(traceContext){ns.set(w3cTraceContextKey,traceContext)}function getW3cTraceContext(){return ns.get(w3cTraceContextKey)}function isTracing(){return!!ns.get(currentSpanKey)}function setTracingLevel(level){ns.set(tracingLevelKey,level)}function tracingLevel(){return ns.get(tracingLevelKey)}function tracingSuppressed(){var tl=tracingLevel();return"string"==typeof tl&&0===tl.indexOf("0")}function getAsyncContext(){return ns?ns.active:null}function enterAsyncContext(context){ns&&(null==context?logger.warn("Ignoring enterAsyncContext call because passed context was null or undefined."):ns.enter(context))}function leaveAsyncContext(context){ns&&(null==context?logger.warn("Ignoring leaveAsyncContext call because passed context was null or undefined."):ns.exit(context))}function runInAsyncContext(context,fn){return ns?null==context?(logger.warn("Ignoring runInAsyncContext call because passed context was null or undefined."),fn()):ns.runAndReturn(fn,context):fn()}function runPromiseInAsyncContext(context,fn){return ns?null==context?(logger.warn("Ignoring runPromiseInAsyncContext call because passed context was null or undefined."),fn()):ns.runPromise(fn,context):fn()}function call(fn){fn()}function _skipExitTracing(options={isActive:!0,extendedResponse:!1,skipParentSpanCheck:!1,log:!0,skipIsTracing:!1}){var skipIsTracing,skipIsActive,parentSpan=getCurrentSpan(),suppressed=tracingSuppressed(),isExitSpanResult=isExitSpan(parentSpan);return options.skipParentSpanCheck||parentSpan&&!isExitSpanResult?(skipIsActive=!1===options.isActive,skipIsTracing=!options.skipIsTracing&&!isTracing(),skipIsActive=skipIsActive||skipIsTracing||suppressed,options.extendedResponse?{skip:skipIsActive,suppressed:suppressed,isExitSpan:isExitSpanResult}:skipIsActive):(options.log&&logger.warn("Cannot start an exit span as this requires an active entry (or intermediate) span as parent. "+(parentSpan?"But the currently active span is itself an exit span: "+JSON.stringify(parentSpan):"Currently there is no span active at all")),!options.extendedResponse||{skip:!0,suppressed:suppressed,isExitSpan:isExitSpanResult})}function _neverSkipExitTracing(options={isActive:!0,extendedResponse:!1,skipParentSpanCheck:!1,log:!0,skipIsTracing:!1}){var suppressed=tracingSuppressed();return!!options.extendedResponse&&{skip:suppressed,suppressed:suppressed}}const skipExitTracing="true"===process.env.ST_INSTANA_ENABLED?_skipExitTracing:_neverSkipExitTracing;module.exports={skipExitTracing:skipExitTracing,currentEntrySpanKey:currentEntrySpanKey,currentSpanKey:currentSpanKey,reducedSpanKey:reducedSpanKey,tracingLevelKey:tracingLevelKey,w3cTraceContextKey:w3cTraceContextKey,ns:ns,init:init,startSpan:startSpan,putPseudoSpan:putPseudoSpan,getCurrentEntrySpan:getCurrentEntrySpan,setCurrentSpan:setCurrentSpan,getCurrentSpan:getCurrentSpan,getReducedSpan:getReducedSpan,setW3cTraceContext:setW3cTraceContext,getW3cTraceContext:getW3cTraceContext,isTracing:isTracing,setTracingLevel:setTracingLevel,tracingLevel:tracingLevel,tracingSuppressed:tracingSuppressed,getAsyncContext:getAsyncContext,enterAsyncContext:enterAsyncContext,leaveAsyncContext:leaveAsyncContext,runInAsyncContext:runInAsyncContext,runPromiseInAsyncContext:runPromiseInAsyncContext};