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    
@supertenant/core / src / tracing / spanHandle.js
Size: Mime:
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const constants=require("./constants");function SpanHandle(_span){this.span=_span}function _annotateWithString(target,path,value){if("."===path.charAt(path.length-1))_annotateWithString(target,path.substring(0,path.length-1),value);else{var idx=path.indexOf(".");if(0===idx)_annotateWithString(target,path.substring(1),value);else if(1<=idx){var head=path.substring(0,idx),idx=path.substring(idx+1);let nestedTarget=target[head];null!=nestedTarget&&"object"==typeof nestedTarget||(target[head]=nestedTarget={}),_annotateWithString(nestedTarget,idx,value)}else target[path]=value}}function _annotateWithArray(target,path,value){if(0!==path.length)if(1===path.length)_annotateWithString(target,path[0],value);else{var head=path[0],path=path.slice(1);let nestedTarget=target[head];null!=nestedTarget&&"object"==typeof nestedTarget||(target[head]=nestedTarget={}),_annotateWithArray(nestedTarget,path,value)}}function NoopSpanHandle(){}SpanHandle.prototype.getTraceId=function(){return this.span.t},SpanHandle.prototype.getSpanId=function(){return this.span.s},SpanHandle.prototype.getParentSpanId=function(){return this.span.p},SpanHandle.prototype.getName=function(){return this.span.n},SpanHandle.prototype.isEntrySpan=function(){return constants.isEntrySpan(this.span)},SpanHandle.prototype.isExitSpan=function(){return constants.isExitSpan(this.span)},SpanHandle.prototype.isIntermediateSpan=function(){return constants.isIntermediateSpan(this.span)},SpanHandle.prototype.getTimestamp=function(){return this.span.ts},SpanHandle.prototype.getDuration=function(){return this.span.d},SpanHandle.prototype.getErrorCount=function(){return this.span.ec},SpanHandle.prototype.getCorrelationId=function(){return this.span.crid},SpanHandle.prototype.setCorrelationId=function(correlationId){this.isEntrySpan()&&!this.getParentSpanId()&&(this.span.crid=correlationId)},SpanHandle.prototype.getCorrelationType=function(){return this.span.crtp},SpanHandle.prototype.setCorrelationType=function(correlationType){this.isEntrySpan()&&!this.getParentSpanId()&&(this.span.crtp=correlationType)},SpanHandle.prototype.annotate=function(path,value){null!=path&&("string"==typeof path?(_annotateWithString(this.span.data,path,value),"http.path_tpl"===path&&this.span.freezePathTemplate()):Array.isArray(path)&&(_annotateWithArray(this.span.data,path,value),"http"===path[0])&&"path_tpl"===path[1]&&this.span.freezePathTemplate())},SpanHandle.prototype.disableAutoEnd=function(){this.span.disableAutoEnd()},SpanHandle.prototype.end=function(errorCount){this.span.ts&&(this.span.d=Date.now()-this.span.ts),"number"==typeof(errorCount=!0===errorCount?1:errorCount)&&(this.span.ec=errorCount),this.span.transmitManual()},SpanHandle.prototype.cancel=function(){this.span.cancel()},NoopSpanHandle.prototype.getTraceId=function(){return null},NoopSpanHandle.prototype.getSpanId=function(){return null},NoopSpanHandle.prototype.getParentSpanId=function(){return null},NoopSpanHandle.prototype.getName=function(){return null},NoopSpanHandle.prototype.isEntrySpan=function(){return!1},NoopSpanHandle.prototype.isExitSpan=function(){return!1},NoopSpanHandle.prototype.isIntermediateSpan=function(){return!1},NoopSpanHandle.prototype.getTimestamp=function(){return 0},NoopSpanHandle.prototype.getDuration=function(){return 0},NoopSpanHandle.prototype.getErrorCount=function(){return 0},NoopSpanHandle.prototype.getCorrelationId=function(){return null},NoopSpanHandle.prototype.setCorrelationId=function(){},NoopSpanHandle.prototype.getCorrelationType=function(){return null},NoopSpanHandle.prototype.setCorrelationType=function(){},NoopSpanHandle.prototype.annotate=function(){},NoopSpanHandle.prototype.disableAutoEnd=function(){},NoopSpanHandle.prototype.end=function(){},NoopSpanHandle.prototype.cancel=function(){},exports.getHandleForCurrentSpan=function(cls){return cls&&cls.isTracing()?new SpanHandle(cls.getCurrentSpan()):new NoopSpanHandle};