UNPKG

@grafana/faro-web-tracing

Version:
45 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FaroUserActionSpanProcessor = void 0; var api_1 = require("@opentelemetry/api"); var faro_web_sdk_1 = require("@grafana/faro-web-sdk"); var FaroUserActionSpanProcessor = /** @class */ (function () { function FaroUserActionSpanProcessor(processor) { var _this = this; this.processor = processor; faro_web_sdk_1.apiMessageBus.subscribe(function (msg) { if (msg.type === faro_web_sdk_1.USER_ACTION_START) { _this.message = msg; return; } if ([faro_web_sdk_1.USER_ACTION_END, faro_web_sdk_1.USER_ACTION_HALT, faro_web_sdk_1.USER_ACTION_CANCEL].includes(msg.type)) { _this.message = undefined; } }); } FaroUserActionSpanProcessor.prototype.forceFlush = function () { return this.processor.forceFlush(); }; FaroUserActionSpanProcessor.prototype.onStart = function (span, parentContext) { var _a, _b; if (span.kind === api_1.SpanKind.CLIENT) { // If the span is created when the message object is available it is created before the user action timeout has been reached so it belongs to the user-action. // In this case we can add the user action name and parentId to the span attributes. // If the span is created after the user action timeout span, the message object will be undefined which means the action has been cancelled or is ended. if (this.message) { span.attributes['faro.action.user.name'] = (_a = this.message) === null || _a === void 0 ? void 0 : _a.name; span.attributes['faro.action.user.parentId'] = (_b = this.message) === null || _b === void 0 ? void 0 : _b.parentId; } } this.processor.onStart(span, parentContext); }; FaroUserActionSpanProcessor.prototype.onEnd = function (span) { this.processor.onEnd(span); }; FaroUserActionSpanProcessor.prototype.shutdown = function () { return this.processor.shutdown(); }; return FaroUserActionSpanProcessor; }()); exports.FaroUserActionSpanProcessor = FaroUserActionSpanProcessor; //# sourceMappingURL=faroUserActionSpanProcessor.js.map