Outlook_Addin_LLM/node_modules/applicationinsights/out/AutoCollection/AsyncHooksScopeManager.js

95 lines
4.4 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var CorrelationContextManager_1 = require("./CorrelationContextManager");
var events_1 = require("events");
/**
* Type of span. Can be used to specify additional relationships between spans
* in addition to a parent/child relationship.
*/
var SpanKind;
(function (SpanKind) {
/** Default value. Indicates that the span is used internally. */
SpanKind[SpanKind["INTERNAL"] = 0] = "INTERNAL";
/**
* Indicates that the span covers server-side handling of an RPC or other
* remote request.
*/
SpanKind[SpanKind["SERVER"] = 1] = "SERVER";
/**
* Indicates that the span covers the client-side wrapper around an RPC or
* other remote request.
*/
SpanKind[SpanKind["CLIENT"] = 2] = "CLIENT";
/**
* Indicates that the span describes producer sending a message to a
* broker. Unlike client and server, there is no direct critical path latency
* relationship between producer and consumer spans.
*/
SpanKind[SpanKind["PRODUCER"] = 3] = "PRODUCER";
/**
* Indicates that the span describes consumer receiving a message from a
* broker. Unlike client and server, there is no direct critical path latency
* relationship between producer and consumer spans.
*/
SpanKind[SpanKind["CONSUMER"] = 4] = "CONSUMER";
})(SpanKind = exports.SpanKind || (exports.SpanKind = {}));
var OpenTelemetryScopeManagerWrapper = (function () {
function OpenTelemetryScopeManagerWrapper() {
}
OpenTelemetryScopeManagerWrapper.prototype.active = function () {
var _this = this;
var context = CorrelationContextManager_1.CorrelationContextManager.getCurrentContext();
return __assign({}, context, { getValue: function (key) {
// todo: lazy import activeSymbol from opentelemetry/api
if (!_this._activeSymbol) {
_this._activeSymbol = key;
return context;
}
if (key === _this._activeSymbol) {
return context;
}
return false;
}, setValue: function () { } });
};
OpenTelemetryScopeManagerWrapper.prototype.with = function (span, fn) {
var parentSpanId = span.parentSpanId;
var name = span.name;
var correlationContext = OpenTelemetryScopeManagerWrapper._spanToContext(span, parentSpanId, name);
return CorrelationContextManager_1.CorrelationContextManager.runWithContext(correlationContext, fn)();
};
OpenTelemetryScopeManagerWrapper.prototype.bind = function (target) {
if (typeof target === "function") {
return CorrelationContextManager_1.CorrelationContextManager.wrapCallback(target);
}
else if (target instanceof events_1.EventEmitter) {
CorrelationContextManager_1.CorrelationContextManager.wrapEmitter(target);
}
return target;
};
OpenTelemetryScopeManagerWrapper.prototype.enable = function () {
CorrelationContextManager_1.CorrelationContextManager.enable();
return this;
};
OpenTelemetryScopeManagerWrapper.prototype.disable = function () {
CorrelationContextManager_1.CorrelationContextManager.disable();
return this;
};
OpenTelemetryScopeManagerWrapper._spanToContext = function (span, parentSpanId, name) {
var _parentId = parentSpanId ? "|" + span.context().traceId + "." + parentSpanId + "." : span.context().traceId;
var context = __assign({}, span.context(), { traceFlags: span.context().traceFlags.toString() });
var correlationContext = CorrelationContextManager_1.CorrelationContextManager.spanToContextObject(context, _parentId, name);
return correlationContext;
};
return OpenTelemetryScopeManagerWrapper;
}());
exports.OpenTelemetryScopeManagerWrapper = OpenTelemetryScopeManagerWrapper;
exports.AsyncScopeManager = new OpenTelemetryScopeManagerWrapper();
//# sourceMappingURL=AsyncHooksScopeManager.js.map