@embrace-io/web-sdk
Version:
1 lines • 2.44 kB
Source Map (JSON)
{"version":3,"file":"PageSpanProcessor.cjs","names":["KEY_EMB_PAGE_PATH","KEY_EMB_PAGE_ID","KEY_APP_SURFACE_LABEL"],"sources":["../../../src/processors/PageSpanProcessor/PageSpanProcessor.ts"],"sourcesContent":["import type { Span, SpanProcessor } from '@opentelemetry/sdk-trace';\nimport type { PageManager } from '../../api-page/index.ts';\nimport {\n KEY_APP_SURFACE_LABEL,\n KEY_EMB_PAGE_ID,\n KEY_EMB_PAGE_PATH,\n} from '../../constants/index.ts';\nimport type { PageSpanProcessorArgs } from './types.ts';\n\nexport class PageSpanProcessor implements SpanProcessor {\n private readonly _pageManager: PageManager;\n\n public constructor({ pageManager }: PageSpanProcessorArgs) {\n this._pageManager = pageManager;\n }\n\n public forceFlush(): Promise<void> {\n return Promise.resolve(undefined);\n }\n\n // Attach page attributes at span end to capture the page where the span completed\n public onEnding(span: Span): void {\n // If the span already has page attributes, do not override them\n if (\n !span.attributes[KEY_EMB_PAGE_PATH] ||\n !span.attributes[KEY_EMB_PAGE_ID]\n ) {\n const currentRoute = this._pageManager.getCurrentRoute();\n const currentPageId = this._pageManager.getCurrentPageId();\n\n if (currentRoute && currentPageId) {\n span.attributes[KEY_EMB_PAGE_PATH] = currentRoute.path;\n span.attributes[KEY_EMB_PAGE_ID] = currentPageId;\n }\n }\n\n const appSurfaceLabel = this._pageManager.getPageLabel();\n if (appSurfaceLabel && !span.attributes[KEY_APP_SURFACE_LABEL]) {\n span.attributes[KEY_APP_SURFACE_LABEL] = appSurfaceLabel;\n }\n }\n\n public onStart(this: void): void {\n // do nothing.\n }\n\n public onEnd(this: void): void {\n // do nothing.\n }\n\n public shutdown(): Promise<void> {\n return Promise.resolve(undefined);\n }\n}\n"],"mappings":";;;AASA,IAAa,oBAAb,MAAwD;CACtD;CAEA,YAAmB,EAAE,eAAsC;EACzD,KAAK,eAAe;CACtB;CAEA,aAAmC;EACjC,OAAO,QAAQ,QAAQ,KAAA,CAAS;CAClC;CAGA,SAAgB,MAAkB;EAEhC,IACE,CAAC,KAAK,WAAA,uBACN,CAAC,KAAK,WAAA,mBACN;GACA,MAAM,eAAe,KAAK,aAAa,gBAAgB;GACvD,MAAM,gBAAgB,KAAK,aAAa,iBAAiB;GAEzD,IAAI,gBAAgB,eAAe;IACjC,KAAK,WAAWA,6BAAAA,qBAAqB,aAAa;IAClD,KAAK,WAAWC,6BAAAA,mBAAmB;GACrC;EACF;EAEA,MAAM,kBAAkB,KAAK,aAAa,aAAa;EACvD,IAAI,mBAAmB,CAAC,KAAK,WAAA,sBAC3B,KAAK,WAAWC,6BAAAA,yBAAyB;CAE7C;CAEA,UAAiC,CAEjC;CAEA,QAA+B,CAE/B;CAEA,WAAiC;EAC/B,OAAO,QAAQ,QAAQ,KAAA,CAAS;CAClC;AACF"}