{"version":3,"file":"EmbraceNetworkSpanProcessor.cjs","names":["isNetworkSpan","KEY_EMB_TYPE","ATTR_URL_FULL","SEMATTRS_HTTP_URL","ATTR_HTTP_RESPONSE_STATUS_CODE","SEMATTRS_HTTP_STATUS_CODE","ATTR_HTTP_REQUEST_METHOD","SEMATTRS_HTTP_METHOD","ATTR_HTTP_RESPONSE_BODY_SIZE","SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH","ATTR_HTTP_REQUEST_BODY_SIZE","SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH"],"sources":["../../../src/processors/EmbraceNetworkSpanProcessor/EmbraceNetworkSpanProcessor.ts"],"sourcesContent":["import type { ReadableSpan, SpanProcessor } from '@opentelemetry/sdk-trace-web';\nimport {\n  ATTR_HTTP_REQUEST_METHOD,\n  ATTR_HTTP_RESPONSE_STATUS_CODE,\n  ATTR_URL_FULL,\n  SEMATTRS_HTTP_METHOD,\n  SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH,\n  SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH,\n  SEMATTRS_HTTP_STATUS_CODE,\n  SEMATTRS_HTTP_URL,\n} from '@opentelemetry/semantic-conventions';\n\nimport {\n  ATTR_HTTP_REQUEST_BODY_SIZE,\n  ATTR_HTTP_RESPONSE_BODY_SIZE,\n} from '@opentelemetry/semantic-conventions/incubating';\nimport { EMB_TYPES, KEY_EMB_TYPE } from '../../constants/index.ts';\nimport { isNetworkSpan } from './types.ts';\n\n/**\n * Embrace's API expects network spans to have some specific attributes.\n * This processor checks if a span is a network span and adds them.\n */\nexport class EmbraceNetworkSpanProcessor implements SpanProcessor {\n  public forceFlush(): Promise<void> {\n    return Promise.resolve(undefined);\n  }\n\n  // TODO `onEnd` is not supposed to modify the span. There is a new experimental onEnding api that allows modifying\n\n  //  the span before it is sent to the exporter. This processor should be updated to use that api once that is available\n  public onEnd(span: ReadableSpan): void {\n    if (isNetworkSpan(span)) {\n      span.attributes[KEY_EMB_TYPE] = EMB_TYPES.Network;\n\n      /*\n        Fallback on deprecated attribute names in case the span is using those instead of the latest ones\n\n        The current versions of @opentelemetry/instrumentation-xml-http-request and @opentelemetry/instrumentation-fetch\n        that we're getting from @opentelemetry/auto-instrumentations-web are using these, once we update we'll remove\n        this fallback and only support a single version of the semantic convention\n       */\n      span.attributes[ATTR_URL_FULL] ??= span.attributes[SEMATTRS_HTTP_URL];\n      span.attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] ??=\n        span.attributes[SEMATTRS_HTTP_STATUS_CODE];\n      span.attributes[ATTR_HTTP_REQUEST_METHOD] ??=\n        span.attributes[SEMATTRS_HTTP_METHOD];\n      span.attributes[ATTR_HTTP_RESPONSE_BODY_SIZE] ??=\n        span.attributes[SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH];\n      span.attributes[ATTR_HTTP_REQUEST_BODY_SIZE] ??=\n        span.attributes[SEMATTRS_HTTP_REQUEST_CONTENT_LENGTH];\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":";;;;;;;;;;;AAuBA,IAAa,8BAAb,MAAkE;CAChE,aAAmC;AACjC,SAAO,QAAQ,QAAQ,KAAA,EAAU;;CAMnC,MAAa,MAA0B;AACrC,MAAIA,qDAAAA,cAAc,KAAK,EAAE;AACvB,QAAK,WAAWC,6BAAAA,gBAAAA;AAShB,QAAK,WAAWC,oCAAAA,mBAAmB,KAAK,WAAWC,oCAAAA;AACnD,QAAK,WAAWC,oCAAAA,oCACd,KAAK,WAAWC,oCAAAA;AAClB,QAAK,WAAWC,oCAAAA,8BACd,KAAK,WAAWC,oCAAAA;AAClB,QAAK,WAAWC,+CAAAA,kCACd,KAAK,WAAWC,oCAAAA;AAClB,QAAK,WAAWC,+CAAAA,iCACd,KAAK,WAAWC,oCAAAA;;;CAItB,UAAiC;CAIjC,WAAiC;AAC/B,SAAO,QAAQ,QAAQ,KAAA,EAAU"}