{"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 { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-web';\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 onEnd(span: ReadableSpan): 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 shutdown(): Promise<void> {\n    return Promise.resolve(undefined);\n  }\n}\n"],"mappings":";;;AASA,IAAa,oBAAb,MAAwD;CACtD;CAEA,YAAmB,EAAE,eAAsC;AACzD,OAAK,eAAe;;CAGtB,aAAmC;AACjC,SAAO,QAAQ,QAAQ,KAAA,EAAU;;CAInC,MAAa,MAA0B;AAErC,MACE,CAAC,KAAK,WAAA,uBACN,CAAC,KAAK,WAAA,mBACN;GACA,MAAM,eAAe,KAAK,aAAa,iBAAiB;GACxD,MAAM,gBAAgB,KAAK,aAAa,kBAAkB;AAE1D,OAAI,gBAAgB,eAAe;AACjC,SAAK,WAAWA,6BAAAA,qBAAqB,aAAa;AAClD,SAAK,WAAWC,6BAAAA,mBAAmB;;;EAIvC,MAAM,kBAAkB,KAAK,aAAa,cAAc;AACxD,MAAI,mBAAmB,CAAC,KAAK,WAAA,qBAC3B,MAAK,WAAWC,6BAAAA,yBAAyB;;CAI7C,UAAiC;CAIjC,WAAiC;AAC/B,SAAO,QAAQ,QAAQ,KAAA,EAAU"}