UNPKG

@grafana/faro-web-tracing

Version:
47 lines 2.37 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"); // There is very rare race condition that would result in span being attached to different user action. As shown in the diagram below. // The scenario is the following // // 1. User action (id = 1) starts // 2. Things happen for a given amount of time // 3. User action ends // 4. Span processor starts // 5. A new user action (id = 2) starts // 6. Span processor tries to attach the `faro.user.action` attributes based on the state of the current user action which is id = 2. // // This ultimately depends on the processing delay of the span processor which deems this race condition highly unlikely. var FaroUserActionSpanProcessor = /** @class */ (function () { function FaroUserActionSpanProcessor(processor) { this.processor = processor; } FaroUserActionSpanProcessor.prototype.forceFlush = function () { return this.processor.forceFlush(); }; FaroUserActionSpanProcessor.prototype.onStart = function (span, parentContext) { var userAction = faro_web_sdk_1.faro.api.getActiveUserAction(); if (userAction && (userAction === null || userAction === void 0 ? void 0 : userAction.getState()) === faro_web_sdk_1.UserActionState.Started && span.kind === api_1.SpanKind.CLIENT) { if (!span.attributes['faro.action.user.name']) { span.attributes['faro.action.user.name'] = userAction === null || userAction === void 0 ? void 0 : userAction.name; } if (!span.attributes['faro.action.user.parentId']) { span.attributes['faro.action.user.parentId'] = userAction === null || userAction === void 0 ? void 0 : userAction.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