@opentelemetry/instrumentation-xml-http-request 0.219.0 → 0.221.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +9 -25
  2. package/build/esm/semconv.d.ts +0 -84
  3. package/build/esm/semconv.js +0 -84
  4. package/build/esm/semconv.js.map +1 -1
  5. package/build/esm/version.d.ts +1 -1
  6. package/build/esm/version.js +1 -1
  7. package/build/esm/version.js.map +1 -1
  8. package/build/esm/xhr.d.ts +1 -5
  9. package/build/esm/xhr.js +34 -77
  10. package/build/esm/xhr.js.map +1 -1
  11. package/build/esnext/semconv.d.ts +0 -84
  12. package/build/esnext/semconv.js +0 -84
  13. package/build/esnext/semconv.js.map +1 -1
  14. package/build/esnext/version.d.ts +1 -1
  15. package/build/esnext/version.js +1 -1
  16. package/build/esnext/version.js.map +1 -1
  17. package/build/esnext/xhr.d.ts +1 -5
  18. package/build/esnext/xhr.js +34 -77
  19. package/build/esnext/xhr.js.map +1 -1
  20. package/build/src/enums/EventNames.js +1 -1
  21. package/build/src/enums/EventNames.js.map +1 -1
  22. package/build/src/semconv.d.ts +0 -84
  23. package/build/src/semconv.js +1 -85
  24. package/build/src/semconv.js.map +1 -1
  25. package/build/src/version.d.ts +1 -1
  26. package/build/src/version.js +1 -1
  27. package/build/src/version.js.map +1 -1
  28. package/build/src/xhr.d.ts +1 -5
  29. package/build/src/xhr.js +32 -75
  30. package/build/src/xhr.js.map +1 -1
  31. package/package.json +16 -16
  32. package/build/esm/enums/AttributeNames.d.ts +0 -7
  33. package/build/esm/enums/AttributeNames.js +0 -12
  34. package/build/esm/enums/AttributeNames.js.map +0 -1
  35. package/build/esnext/enums/AttributeNames.d.ts +0 -7
  36. package/build/esnext/enums/AttributeNames.js +0 -12
  37. package/build/esnext/enums/AttributeNames.js.map +0 -1
  38. package/build/src/enums/AttributeNames.d.ts +0 -7
  39. package/build/src/enums/AttributeNames.js +0 -15
  40. package/build/src/enums/AttributeNames.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,sBAAsB,IAAI,GAAG,EAC7B,2BAA2B,EAC3B,QAAQ,GACT,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,iCAAiC,EACjC,8BAA8B,EAC9B,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,GACd,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,2BAA2B,EAC3B,6CAA6C,GAC9C,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAOhD,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,uEAAuE;AACvE,2DAA2D;AAC3D,kEAAkE;AAClE,cAAc;AACd,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAsClC;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,mBAAwD;IAChG,SAAS,GAAW,kBAAkB,CAAC;IACvC,OAAO,GAAW,OAAO,CAAC;IACnC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;IAEpB,WAAW,G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ACpB,OAAO;SACR;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n SemconvStability,\n semconvStabilityFromStr,\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport {\n ATTR_HTTP_HOST,\n ATTR_HTTP_METHOD,\n ATTR_HTTP_SCHEME,\n ATTR_HTTP_STATUS_CODE,\n ATTR_HTTP_URL,\n ATTR_HTTP_USER_AGENT,\n ATTR_HTTP_REQUEST_BODY_SIZE,\n ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED,\n} from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\nimport { AttributeNames } from './enums/AttributeNames';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n /** Select the HTTP semantic conventions version(s) used. */\n semconvStabilityOptIn?: string;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n private _semconvStability: SemconvStability;\n\n // Note: Intentionally *not* using `_enabled` as the field name to avoid\n // any possible confusion with the `_enabled` field used on the *Node.js*\n // InstrumentationBase class.\n // Also not initializing the fields to `false` because the base class\n // constructor already calls `enable` modifying their values and it will\n // set the instrumentations in a bad state (enabled, patched but with flags set to false)\n declare private _isEnabled: boolean;\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n this._semconvStability = semconvStabilityFromStr(\n 'http',\n config?.semconvStabilityOptIn\n );\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n const skipOldSemconvContentLengthAttrs = !(\n this._semconvStability & SemconvStability.OLD\n );\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined,\n skipOldSemconvContentLengthAttrs\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @param spanUrl\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string) {\n if (this._semconvStability & SemconvStability.OLD) {\n if (xhrMem.status !== undefined) {\n span.setAttribute(ATTR_HTTP_STATUS_CODE, xhrMem.status);\n }\n if (xhrMem.statusText !== undefined) {\n span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);\n }\n if (typeof spanUrl === 'string') {\n const parsedUrl = parseUrl(spanUrl);\n span.setAttribute(ATTR_HTTP_HOST, parsedUrl.host);\n span.setAttribute(\n ATTR_HTTP_SCHEME,\n parsedUrl.protocol.replace(':', '')\n );\n }\n\n // @TODO do we want to collect this or it will be collected earlier once only or\n // maybe when parent span is not available ?\n span.setAttribute(ATTR_HTTP_USER_AGENT, navigator.userAgent);\n }\n if (this._semconvStability & SemconvStability.STABLE) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n (otperformance as unknown as Performance).clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = (otperformance as unknown as Performance).getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n const skipOldSemconvContentLengthAttrs = !(\n this._semconvStability & SemconvStability.OLD\n );\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined,\n skipOldSemconvContentLengthAttrs\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n let name = '';\n const attributes = {} as api.Attributes;\n if (this._semconvStability & SemconvStability.OLD) {\n name = method.toUpperCase();\n attributes[ATTR_HTTP_METHOD] = method;\n attributes[ATTR_HTTP_URL] = parsedUrl.toString();\n }\n if (this._semconvStability & SemconvStability.STABLE) {\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n if (!name) {\n // The \"old\" span name wins if emitting both old and stable semconv\n // ('http/dup').\n name = normMethod;\n }\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem, spanUrl);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (plugin._semconvStability & SemconvStability.STABLE) {\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n if (plugin._semconvStability & SemconvStability.OLD) {\n currentSpan.setAttribute(\n ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED,\n bodyLength\n );\n }\n if (plugin._semconvStability & SemconvStability.STABLE) {\n currentSpan.setAttribute(\n ATTR_HTTP_REQUEST_BODY_SIZE,\n bodyLength\n );\n }\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._isEnabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._isEnabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._isEnabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._isEnabled) {\n return;\n }\n this._isEnabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
1
+ {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/xhr.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAE1C,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C,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/C,IAAI,CAAC,KAAK,CAAC,IAAI,CACb,kFAAkF;gBAChF,qFAAqF,EACvF,GAAG,CACJ,CAAC;SACH;IACH,CAAC;IAED;;OAEG;IACM,OAAO;QACd,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,OAAO;SACR;QACD,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,EAA0B,CAAC;QACrD,IAAI,CAAC,cAAc,GAAG,IAAI,OAAO,EAA6B,CAAC;IACjE,CAAC;CACF","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as api from '@opentelemetry/api';\nimport type { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport {\n InstrumentationBase,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';\nimport {\n addSpanNetworkEvents,\n getResource,\n PerformanceTimingNames as PTN,\n shouldPropagateTraceHeaders,\n parseUrl,\n} from '@opentelemetry/sdk-trace-web';\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_REQUEST_METHOD_ORIGINAL,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from '@opentelemetry/semantic-conventions';\nimport { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';\nimport { EventNames } from './enums/EventNames';\nimport type {\n OpenFunction,\n PropagateTraceHeaderCorsUrls,\n SendFunction,\n XhrMem,\n} from './types';\nimport {\n normalizeHttpRequestMethod,\n serverPortFromUrl,\n getXHRBodyLength,\n} from './utils';\nimport { VERSION } from './version';\n\n// how long to wait for observer to collect information about resources\n// this is needed as event \"load\" is called before observer\n// hard to say how long it should really wait, seems like 300ms is\n// safe enough\nconst OBSERVER_WAIT_TIME_MS = 300;\n\nexport type XHRCustomAttributeFunction = (\n span: api.Span,\n xhr: XMLHttpRequest\n) => void;\n\n/**\n * XMLHttpRequest config\n */\nexport interface XMLHttpRequestInstrumentationConfig\n extends InstrumentationConfig {\n /**\n * The number of timing resources is limited, after the limit\n * (chrome 250, safari 150) the information is not collected anymore.\n * The only way to prevent that is to regularly clean the resources\n * whenever it is possible. This is needed only when PerformanceObserver\n * is not available\n */\n clearTimingResources?: boolean;\n /** URLs which should include trace headers when origin doesn't match */\n propagateTraceHeaderCorsUrls?: PropagateTraceHeaderCorsUrls;\n /**\n * URLs that partially match any regex in ignoreUrls will not be traced.\n * In addition, URLs that are _exact matches_ of strings in ignoreUrls will\n * also not be traced.\n */\n ignoreUrls?: Array<string | RegExp>;\n /** Function for adding custom attributes on the span */\n applyCustomAttributesOnSpan?: XHRCustomAttributeFunction;\n /** Ignore adding network events as span events */\n ignoreNetworkEvents?: boolean;\n /** Measure outgoing request size */\n measureRequestSize?: boolean;\n}\n\n/**\n * This class represents a XMLHttpRequest plugin for auto instrumentation\n */\nexport class XMLHttpRequestInstrumentation extends InstrumentationBase<XMLHttpRequestInstrumentationConfig> {\n readonly component: string = 'xml-http-request';\n readonly version: string = VERSION;\n moduleName = this.component;\n\n private _tasksCount = 0;\n private _xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n private _usedResources = new WeakSet<PerformanceResourceTiming>();\n\n // Note: Intentionally *not* using `_enabled` as the field name to avoid\n // any possible confusion with the `_enabled` field used on the *Node.js*\n // InstrumentationBase class.\n // Also not initializing the fields to `false` because the base class\n // constructor already calls `enable` modifying their values and it will\n // set the instrumentations in a bad state (enabled, patched but with flags set to false)\n declare private _isEnabled: boolean;\n declare private _isXhrPatched: boolean;\n\n constructor(config: XMLHttpRequestInstrumentationConfig = {}) {\n super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);\n }\n\n init() {}\n\n /**\n * Adds custom headers to XMLHttpRequest\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addHeaders(xhr: XMLHttpRequest, spanUrl: string) {\n const url = parseUrl(spanUrl).href;\n if (\n !shouldPropagateTraceHeaders(\n url,\n this.getConfig().propagateTraceHeaderCorsUrls\n )\n ) {\n const headers: Partial<Record<string, unknown>> = {};\n api.propagation.inject(api.context.active(), headers);\n if (Object.keys(headers).length > 0) {\n this._diag.debug('headers inject skipped due to CORS policy');\n }\n return;\n }\n const headers: { [key: string]: unknown } = {};\n api.propagation.inject(api.context.active(), headers);\n Object.keys(headers).forEach(key => {\n xhr.setRequestHeader(key, String(headers[key]));\n });\n }\n\n /**\n * Add cors pre flight child span\n * @param span\n * @param corsPreFlightRequest\n * @private\n */\n private _addChildSpan(\n span: api.Span,\n corsPreFlightRequest: PerformanceResourceTiming\n ): void {\n api.context.with(api.trace.setSpan(api.context.active(), span), () => {\n const childSpan = this.tracer.startSpan('CORS Preflight', {\n startTime: corsPreFlightRequest[PTN.FETCH_START],\n });\n addSpanNetworkEvents(\n childSpan,\n corsPreFlightRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined,\n true\n );\n childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);\n });\n }\n\n /**\n * Add attributes when span is going to end\n * @param span\n * @param xhr\n * @private\n */\n _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem) {\n if (xhrMem.status) {\n // Intentionally exclude status=0, because XHR uses 0 for before a\n // response is received and semconv says to only add the attribute if\n // received a response.\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);\n }\n }\n\n private _applyAttributesAfterXHR(span: api.Span, xhr: XMLHttpRequest) {\n const applyCustomAttributesOnSpan =\n this.getConfig().applyCustomAttributesOnSpan;\n if (typeof applyCustomAttributesOnSpan === 'function') {\n safeExecuteInTheMiddle(\n () => applyCustomAttributesOnSpan(span, xhr),\n error => {\n if (!error) {\n return;\n }\n\n this._diag.error('applyCustomAttributesOnSpan', error);\n },\n true\n );\n }\n }\n\n /**\n * will collect information about all resources created\n * between \"send\" and \"end\" with additional waiting for main resource\n * @param xhr\n * @param spanUrl\n * @private\n */\n private _addResourceObserver(xhr: XMLHttpRequest, spanUrl: string) {\n const xhrMem = this._xhrMem.get(xhr);\n if (\n !xhrMem ||\n typeof PerformanceObserver !== 'function' ||\n typeof PerformanceResourceTiming !== 'function'\n ) {\n return;\n }\n xhrMem.createdResources = {\n observer: new PerformanceObserver(list => {\n const entries = list.getEntries() as PerformanceResourceTiming[];\n const parsedUrl = parseUrl(spanUrl);\n\n entries.forEach(entry => {\n if (\n entry.initiatorType === 'xmlhttprequest' &&\n entry.name === parsedUrl.href\n ) {\n if (xhrMem.createdResources) {\n xhrMem.createdResources.entries.push(entry);\n }\n }\n });\n }),\n entries: [],\n };\n xhrMem.createdResources.observer.observe({\n entryTypes: ['resource'],\n });\n }\n\n /**\n * Clears the resource timings and all resources assigned with spans\n * when {@link XMLHttpRequestInstrumentationConfig.clearTimingResources} is\n * set to true (default false)\n * @private\n */\n private _clearResources() {\n if (this._tasksCount === 0 && this.getConfig().clearTimingResources) {\n (otperformance as unknown as Performance).clearResourceTimings();\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n }\n\n /**\n * Finds appropriate resource and add network events to the span\n * @param span\n */\n private _findResourceAndAddNetworkEvents(\n xhrMem: XhrMem,\n span: api.Span,\n spanUrl?: string,\n startTime?: api.HrTime,\n endTime?: api.HrTime\n ): void {\n if (!spanUrl || !startTime || !endTime || !xhrMem.createdResources) {\n return;\n }\n let resources: PerformanceResourceTiming[] =\n xhrMem.createdResources.entries;\n\n if (!resources || !resources.length) {\n // fallback - either Observer is not available or it took longer\n // then OBSERVER_WAIT_TIME_MS and observer didn't collect enough\n // information\n // ts thinks this is the perf_hooks module, but it is the browser performance api\n resources = (otperformance as unknown as Performance).getEntriesByType(\n 'resource'\n ) as PerformanceResourceTiming[];\n }\n\n const resource = getResource(\n parseUrl(spanUrl).href,\n startTime,\n endTime,\n resources,\n this._usedResources\n );\n\n if (resource.mainRequest) {\n const mainRequest = resource.mainRequest;\n this._markResourceAsUsed(mainRequest);\n\n const corsPreFlightRequest = resource.corsPreFlightRequest;\n if (corsPreFlightRequest) {\n this._addChildSpan(span, corsPreFlightRequest);\n this._markResourceAsUsed(corsPreFlightRequest);\n }\n addSpanNetworkEvents(\n span,\n mainRequest,\n this.getConfig().ignoreNetworkEvents,\n undefined,\n true\n );\n }\n }\n\n /**\n * Removes the previous information about span.\n * This might happened when the same xhr is used again.\n * @param xhr\n * @private\n */\n private _cleanPreviousSpanInformation(xhr: XMLHttpRequest) {\n const xhrMem = this._xhrMem.get(xhr);\n if (xhrMem) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n if (callbackToRemoveEvents) {\n callbackToRemoveEvents();\n }\n this._xhrMem.delete(xhr);\n }\n }\n\n /**\n * Creates a new span when method \"open\" is called\n * @param xhr\n * @param url\n * @param method\n * @private\n */\n private _createSpan(\n xhr: XMLHttpRequest,\n url: string,\n method: string\n ): api.Span | undefined {\n const parsedUrl = parseUrl(url);\n if (isUrlIgnored(parsedUrl.href, this.getConfig().ignoreUrls)) {\n this._diag.debug('ignoring span as url matches ignored url');\n return;\n }\n const attributes = {} as api.Attributes;\n const origMethod = method;\n const normMethod = normalizeHttpRequestMethod(method);\n const name = normMethod;\n\n attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;\n if (normMethod !== origMethod) {\n attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;\n }\n attributes[ATTR_URL_FULL] = parsedUrl.toString();\n attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;\n const serverPort = serverPortFromUrl(parsedUrl);\n if (serverPort) {\n attributes[ATTR_SERVER_PORT] = serverPort;\n }\n\n const currentSpan = this.tracer.startSpan(name, {\n kind: api.SpanKind.CLIENT,\n attributes,\n });\n\n currentSpan.addEvent(EventNames.METHOD_OPEN);\n\n this._cleanPreviousSpanInformation(xhr);\n\n this._xhrMem.set(xhr, {\n span: currentSpan,\n spanUrl: url,\n });\n\n return currentSpan;\n }\n\n /**\n * Marks certain [resource]{@link PerformanceResourceTiming} when information\n * from this is used to add events to span.\n * This is done to avoid reusing the same resource again for next span\n * @param resource\n * @private\n */\n private _markResourceAsUsed(resource: PerformanceResourceTiming) {\n this._usedResources.add(resource);\n }\n\n /**\n * Patches the method open\n * @private\n */\n protected _patchOpen() {\n return (original: OpenFunction): OpenFunction => {\n const plugin = this;\n return function patchOpen(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const method: string = args[0];\n const url: string = args[1];\n plugin._createSpan(this, url, method);\n\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * Patches the method send\n * @private\n */\n protected _patchSend() {\n const plugin = this;\n\n function endSpanTimeout(\n eventName: string,\n xhrMem: XhrMem,\n performanceEndTime: api.HrTime,\n endTime: number\n ) {\n const callbackToRemoveEvents = xhrMem.callbackToRemoveEvents;\n\n if (typeof callbackToRemoveEvents === 'function') {\n callbackToRemoveEvents();\n }\n\n const { span, spanUrl, sendStartTime } = xhrMem;\n\n if (span) {\n plugin._findResourceAndAddNetworkEvents(\n xhrMem,\n span,\n spanUrl,\n sendStartTime,\n performanceEndTime\n );\n span.addEvent(eventName, endTime);\n plugin._addFinalSpanAttributes(span, xhrMem);\n span.end(endTime);\n plugin._tasksCount--;\n }\n plugin._clearResources();\n }\n\n function endSpan(\n eventName: string,\n xhr: XMLHttpRequest,\n isError: boolean,\n errorType?: string\n ) {\n const xhrMem = plugin._xhrMem.get(xhr);\n if (!xhrMem) {\n return;\n }\n xhrMem.status = xhr.status;\n xhrMem.statusText = xhr.statusText;\n plugin._xhrMem.delete(xhr);\n\n if (xhrMem.span) {\n const span = xhrMem.span;\n plugin._applyAttributesAfterXHR(span, xhr);\n\n if (isError) {\n if (errorType) {\n span.setStatus({\n code: api.SpanStatusCode.ERROR,\n message: errorType,\n });\n span.setAttribute(ATTR_ERROR_TYPE, errorType);\n }\n } else if (xhrMem.status && xhrMem.status >= 400) {\n span.setStatus({ code: api.SpanStatusCode.ERROR });\n span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));\n }\n }\n\n const performanceEndTime = hrTime();\n const endTime = Date.now();\n\n // the timeout is needed as observer doesn't have yet information\n // when event \"load\" is called. Also the time may differ depends on\n // browser and speed of computer\n setTimeout(() => {\n endSpanTimeout(eventName, xhrMem, performanceEndTime, endTime);\n }, OBSERVER_WAIT_TIME_MS);\n }\n\n function onError(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ERROR, this, true, 'error');\n }\n\n function onAbort(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_ABORT, this, false);\n }\n\n function onTimeout(this: XMLHttpRequest) {\n endSpan(EventNames.EVENT_TIMEOUT, this, true, 'timeout');\n }\n\n function onLoad(this: XMLHttpRequest) {\n if (this.status < 299) {\n endSpan(EventNames.EVENT_LOAD, this, false);\n } else {\n endSpan(EventNames.EVENT_ERROR, this, false);\n }\n }\n\n function unregister(xhr: XMLHttpRequest) {\n xhr.removeEventListener('abort', onAbort);\n xhr.removeEventListener('error', onError);\n xhr.removeEventListener('load', onLoad);\n xhr.removeEventListener('timeout', onTimeout);\n const xhrMem = plugin._xhrMem.get(xhr);\n if (xhrMem) {\n xhrMem.callbackToRemoveEvents = undefined;\n }\n }\n\n return (original: SendFunction): SendFunction => {\n return function patchSend(this: XMLHttpRequest, ...args): void {\n if (!plugin._isEnabled) {\n return original.apply(this, args);\n }\n const xhrMem = plugin._xhrMem.get(this);\n if (!xhrMem) {\n return original.apply(this, args);\n }\n const currentSpan = xhrMem.span;\n const spanUrl = xhrMem.spanUrl;\n\n if (currentSpan && spanUrl) {\n if (plugin.getConfig().measureRequestSize && args?.[0]) {\n const body = args[0];\n const bodyLength = getXHRBodyLength(body);\n if (bodyLength !== undefined) {\n currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);\n }\n }\n\n api.context.with(\n api.trace.setSpan(api.context.active(), currentSpan),\n () => {\n plugin._tasksCount++;\n xhrMem.sendStartTime = hrTime();\n currentSpan.addEvent(EventNames.METHOD_SEND);\n\n this.addEventListener('abort', onAbort);\n this.addEventListener('error', onError);\n this.addEventListener('load', onLoad);\n this.addEventListener('timeout', onTimeout);\n\n xhrMem.callbackToRemoveEvents = () => {\n unregister(this);\n if (xhrMem.createdResources) {\n xhrMem.createdResources.observer.disconnect();\n }\n };\n plugin._addHeaders(this, spanUrl);\n plugin._addResourceObserver(this, spanUrl);\n }\n );\n }\n return original.apply(this, args);\n };\n };\n }\n\n /**\n * implements enable function\n */\n override enable() {\n if (this._isEnabled) {\n return;\n }\n if (this._isXhrPatched) {\n this._diag.debug(\n 'reactivating existing patch on',\n this.moduleName,\n this.version\n );\n this._isEnabled = true;\n return;\n }\n\n try {\n this._diag.debug('applying patch to', this.moduleName, this.version);\n this._wrap(XMLHttpRequest.prototype, 'open', this._patchOpen());\n this._wrap(XMLHttpRequest.prototype, 'send', this._patchSend());\n this._isXhrPatched = true;\n this._isEnabled = true;\n } catch (err) {\n // make sure there is no wrapped functions\n this._unwrap(XMLHttpRequest.prototype, 'open');\n this._unwrap(XMLHttpRequest.prototype, 'send');\n this._diag.warn(\n 'Failed to patch globalThis.XMLHttpRequest; instrumentation will not be enabled. ' +\n 'Another script may have locked globalThis.XMLHttpRequest via Object.defineProperty.',\n err\n );\n }\n }\n\n /**\n * implements disable function\n */\n override disable() {\n if (!this._isEnabled) {\n return;\n }\n this._isEnabled = false;\n this._tasksCount = 0;\n this._xhrMem = new WeakMap<XMLHttpRequest, XhrMem>();\n this._usedResources = new WeakSet<PerformanceResourceTiming>();\n }\n}\n"]}
@@ -1,25 +1,3 @@
1
- /**
2
- * Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
3
- *
4
- * @example www.example.org
5
- *
6
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
7
- *
8
- * @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
9
- */
10
- export declare const ATTR_HTTP_HOST: "http.host";
11
- /**
12
- * Deprecated, use `http.request.method` instead.
13
- *
14
- * @example GET
15
- * @example POST
16
- * @example HEAD
17
- *
18
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
19
- *
20
- * @deprecated Replaced by `http.request.method`.
21
- */
22
- export declare const ATTR_HTTP_METHOD: "http.method";
23
1
  /**
24
2
  * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
25
3
  *
@@ -28,66 +6,4 @@ export declare const ATTR_HTTP_METHOD: "http.method";
28
6
  * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
29
7
  */
30
8
  export declare const ATTR_HTTP_REQUEST_BODY_SIZE: "http.request.body.size";
31
- /**
32
- * Deprecated, use `http.request.body.size` instead.
33
- *
34
- * @example 5493
35
- *
36
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
37
- *
38
- * @deprecated Replaced by `http.request.body.size`.
39
- */
40
- export declare const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED: "http.request_content_length_uncompressed";
41
- /**
42
- * Deprecated, use `http.response.header.<key>` instead.
43
- *
44
- * @example 3495
45
- *
46
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
47
- *
48
- * @deprecated Replaced by `http.response.header.<key>`.
49
- */
50
- export declare const ATTR_HTTP_RESPONSE_CONTENT_LENGTH: "http.response_content_length";
51
- /**
52
- * Deprecated, use `url.scheme` instead.
53
- *
54
- * @example http
55
- * @example https
56
- *
57
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
58
- *
59
- * @deprecated Replaced by `url.scheme` instead.
60
- */
61
- export declare const ATTR_HTTP_SCHEME: "http.scheme";
62
- /**
63
- * Deprecated, use `http.response.status_code` instead.
64
- *
65
- * @example 200
66
- *
67
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
68
- *
69
- * @deprecated Replaced by `http.response.status_code`.
70
- */
71
- export declare const ATTR_HTTP_STATUS_CODE: "http.status_code";
72
- /**
73
- * Deprecated, use `url.full` instead.
74
- *
75
- * @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
76
- *
77
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
78
- *
79
- * @deprecated Replaced by `url.full`.
80
- */
81
- export declare const ATTR_HTTP_URL: "http.url";
82
- /**
83
- * Deprecated, use `user_agent.original` instead.
84
- *
85
- * @example CERN-LineMode/2.15 libwww/2.17b3
86
- * @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
87
- *
88
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
89
- *
90
- * @deprecated Replaced by `user_agent.original`.
91
- */
92
- export declare const ATTR_HTTP_USER_AGENT: "http.user_agent";
93
9
  //# sourceMappingURL=semconv.d.ts.map
@@ -7,28 +7,6 @@
7
7
  * used by this package.
8
8
  * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
9
9
  */
10
- /**
11
- * Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.
12
- *
13
- * @example www.example.org
14
- *
15
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
16
- *
17
- * @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.
18
- */
19
- export const ATTR_HTTP_HOST = 'http.host';
20
- /**
21
- * Deprecated, use `http.request.method` instead.
22
- *
23
- * @example GET
24
- * @example POST
25
- * @example HEAD
26
- *
27
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
28
- *
29
- * @deprecated Replaced by `http.request.method`.
30
- */
31
- export const ATTR_HTTP_METHOD = 'http.method';
32
10
  /**
33
11
  * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.
34
12
  *
@@ -37,66 +15,4 @@ export const ATTR_HTTP_METHOD = 'http.method';
37
15
  * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
38
16
  */
39
17
  export const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size';
40
- /**
41
- * Deprecated, use `http.request.body.size` instead.
42
- *
43
- * @example 5493
44
- *
45
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
46
- *
47
- * @deprecated Replaced by `http.request.body.size`.
48
- */
49
- export const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = 'http.request_content_length_uncompressed';
50
- /**
51
- * Deprecated, use `http.response.header.<key>` instead.
52
- *
53
- * @example 3495
54
- *
55
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
56
- *
57
- * @deprecated Replaced by `http.response.header.<key>`.
58
- */
59
- export const ATTR_HTTP_RESPONSE_CONTENT_LENGTH = 'http.response_content_length';
60
- /**
61
- * Deprecated, use `url.scheme` instead.
62
- *
63
- * @example http
64
- * @example https
65
- *
66
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
67
- *
68
- * @deprecated Replaced by `url.scheme` instead.
69
- */
70
- export const ATTR_HTTP_SCHEME = 'http.scheme';
71
- /**
72
- * Deprecated, use `http.response.status_code` instead.
73
- *
74
- * @example 200
75
- *
76
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
77
- *
78
- * @deprecated Replaced by `http.response.status_code`.
79
- */
80
- export const ATTR_HTTP_STATUS_CODE = 'http.status_code';
81
- /**
82
- * Deprecated, use `url.full` instead.
83
- *
84
- * @example https://www.foo.bar/search?q=OpenTelemetry#SemConv
85
- *
86
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
87
- *
88
- * @deprecated Replaced by `url.full`.
89
- */
90
- export const ATTR_HTTP_URL = 'http.url';
91
- /**
92
- * Deprecated, use `user_agent.original` instead.
93
- *
94
- * @example CERN-LineMode/2.15 libwww/2.17b3
95
- * @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1
96
- *
97
- * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
98
- *
99
- * @deprecated Replaced by `user_agent.original`.
100
- */
101
- export const ATTR_HTTP_USER_AGENT = 'http.user_agent';
102
18
  //# sourceMappingURL=semconv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAoB,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAiC,CAAC;AAE7E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,6CAA6C,GACxD,0CAAmD,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAC5C,8BAAuC,CAAC;AAE1C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAA2B,CAAC;AAEjE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,UAAmB,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,iBAA0B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage.\n *\n * @example www.example.org\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage.\n */\nexport const ATTR_HTTP_HOST = 'http.host' as const;\n\n/**\n * Deprecated, use `http.request.method` instead.\n *\n * @example GET\n * @example POST\n * @example HEAD\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.request.method`.\n */\nexport const ATTR_HTTP_METHOD = 'http.method' as const;\n\n/**\n * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const;\n\n/**\n * Deprecated, use `http.request.body.size` instead.\n *\n * @example 5493\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.request.body.size`.\n */\nexport const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED =\n 'http.request_content_length_uncompressed' as const;\n\n/**\n * Deprecated, use `http.response.header.<key>` instead.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.response.header.<key>`.\n */\nexport const ATTR_HTTP_RESPONSE_CONTENT_LENGTH =\n 'http.response_content_length' as const;\n\n/**\n * Deprecated, use `url.scheme` instead.\n *\n * @example http\n * @example https\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `url.scheme` instead.\n */\nexport const ATTR_HTTP_SCHEME = 'http.scheme' as const;\n\n/**\n * Deprecated, use `http.response.status_code` instead.\n *\n * @example 200\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `http.response.status_code`.\n */\nexport const ATTR_HTTP_STATUS_CODE = 'http.status_code' as const;\n\n/**\n * Deprecated, use `url.full` instead.\n *\n * @example https://www.foo.bar/search?q=OpenTelemetry#SemConv\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `url.full`.\n */\nexport const ATTR_HTTP_URL = 'http.url' as const;\n\n/**\n * Deprecated, use `user_agent.original` instead.\n *\n * @example CERN-LineMode/2.15 libwww/2.17b3\n * @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n *\n * @deprecated Replaced by `user_agent.original`.\n */\nexport const ATTR_HTTP_USER_AGENT = 'http.user_agent' as const;\n"]}
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,wBAAiC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size.\n *\n * @example 3495\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const;\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.219.0";
1
+ export declare const VERSION = "0.221.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -3,5 +3,5 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  // this is autogenerated file, see scripts/version-update.js
6
- export const VERSION = '0.219.0';
6
+ export const VERSION = '0.221.0';
7
7
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.219.0';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.221.0';\n"]}
@@ -29,8 +29,6 @@ export interface XMLHttpRequestInstrumentationConfig extends InstrumentationConf
29
29
  ignoreNetworkEvents?: boolean;
30
30
  /** Measure outgoing request size */
31
31
  measureRequestSize?: boolean;
32
- /** Select the HTTP semantic conventions version(s) used. */
33
- semconvStabilityOptIn?: string;
34
32
  }
35
33
  /**
36
34
  * This class represents a XMLHttpRequest plugin for auto instrumentation
@@ -42,7 +40,6 @@ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<X
42
40
  private _tasksCount;
43
41
  private _xhrMem;
44
42
  private _usedResources;
45
- private _semconvStability;
46
43
  private _isEnabled;
47
44
  private _isXhrPatched;
48
45
  constructor(config?: XMLHttpRequestInstrumentationConfig);
@@ -65,10 +62,9 @@ export declare class XMLHttpRequestInstrumentation extends InstrumentationBase<X
65
62
  * Add attributes when span is going to end
66
63
  * @param span
67
64
  * @param xhr
68
- * @param spanUrl
69
65
  * @private
70
66
  */
71
- _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem, spanUrl?: string): void;
67
+ _addFinalSpanAttributes(span: api.Span, xhrMem: XhrMem): void;
72
68
  private _applyAttributesAfterXHR;
73
69
  /**
74
70
  * will collect information about all resources created
@@ -3,15 +3,14 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import * as api from '@opentelemetry/api';
6
- import { SemconvStability, semconvStabilityFromStr, InstrumentationBase, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation';
6
+ import { InstrumentationBase, safeExecuteInTheMiddle, } from '@opentelemetry/instrumentation';
7
7
  import { hrTime, isUrlIgnored, otperformance } from '@opentelemetry/core';
8
8
  import { addSpanNetworkEvents, getResource, PerformanceTimingNames as PTN, shouldPropagateTraceHeaders, parseUrl, } from '@opentelemetry/sdk-trace-web';
9
9
  import { ATTR_ERROR_TYPE, ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_REQUEST_METHOD_ORIGINAL, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_FULL, } from '@opentelemetry/semantic-conventions';
10
- import { ATTR_HTTP_HOST, ATTR_HTTP_METHOD, ATTR_HTTP_SCHEME, ATTR_HTTP_STATUS_CODE, ATTR_HTTP_URL, ATTR_HTTP_USER_AGENT, ATTR_HTTP_REQUEST_BODY_SIZE, ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, } from './semconv';
10
+ import { ATTR_HTTP_REQUEST_BODY_SIZE } from './semconv';
11
11
  import { EventNames } from './enums/EventNames';
12
12
  import { normalizeHttpRequestMethod, serverPortFromUrl, getXHRBodyLength, } from './utils';
13
13
  import { VERSION } from './version';
14
- import { AttributeNames } from './enums/AttributeNames';
15
14
  // how long to wait for observer to collect information about resources
16
15
  // this is needed as event "load" is called before observer
17
16
  // hard to say how long it should really wait, seems like 300ms is
@@ -27,10 +26,8 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
27
26
  _tasksCount = 0;
28
27
  _xhrMem = new WeakMap();
29
28
  _usedResources = new WeakSet();
30
- _semconvStability;
31
29
  constructor(config = {}) {
32
30
  super('@opentelemetry/instrumentation-xml-http-request', VERSION, config);
33
- this._semconvStability = semconvStabilityFromStr('http', config?.semconvStabilityOptIn);
34
31
  }
35
32
  init() { }
36
33
  /**
@@ -66,8 +63,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
66
63
  const childSpan = this.tracer.startSpan('CORS Preflight', {
67
64
  startTime: corsPreFlightRequest[PTN.FETCH_START],
68
65
  });
69
- const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
70
- addSpanNetworkEvents(childSpan, corsPreFlightRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
66
+ addSpanNetworkEvents(childSpan, corsPreFlightRequest, this.getConfig().ignoreNetworkEvents, undefined, true);
71
67
  childSpan.end(corsPreFlightRequest[PTN.RESPONSE_END]);
72
68
  });
73
69
  }
@@ -75,33 +71,14 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
75
71
  * Add attributes when span is going to end
76
72
  * @param span
77
73
  * @param xhr
78
- * @param spanUrl
79
74
  * @private
80
75
  */
81
- _addFinalSpanAttributes(span, xhrMem, spanUrl) {
82
- if (this._semconvStability & SemconvStability.OLD) {
83
- if (xhrMem.status !== undefined) {
84
- span.setAttribute(ATTR_HTTP_STATUS_CODE, xhrMem.status);
85
- }
86
- if (xhrMem.statusText !== undefined) {
87
- span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, xhrMem.statusText);
88
- }
89
- if (typeof spanUrl === 'string') {
90
- const parsedUrl = parseUrl(spanUrl);
91
- span.setAttribute(ATTR_HTTP_HOST, parsedUrl.host);
92
- span.setAttribute(ATTR_HTTP_SCHEME, parsedUrl.protocol.replace(':', ''));
93
- }
94
- // @TODO do we want to collect this or it will be collected earlier once only or
95
- // maybe when parent span is not available ?
96
- span.setAttribute(ATTR_HTTP_USER_AGENT, navigator.userAgent);
97
- }
98
- if (this._semconvStability & SemconvStability.STABLE) {
99
- if (xhrMem.status) {
100
- // Intentionally exclude status=0, because XHR uses 0 for before a
101
- // response is received and semconv says to only add the attribute if
102
- // received a response.
103
- span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);
104
- }
76
+ _addFinalSpanAttributes(span, xhrMem) {
77
+ if (xhrMem.status) {
78
+ // Intentionally exclude status=0, because XHR uses 0 for before a
79
+ // response is received and semconv says to only add the attribute if
80
+ // received a response.
81
+ span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, xhrMem.status);
105
82
  }
106
83
  }
107
84
  _applyAttributesAfterXHR(span, xhr) {
@@ -186,8 +163,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
186
163
  this._addChildSpan(span, corsPreFlightRequest);
187
164
  this._markResourceAsUsed(corsPreFlightRequest);
188
165
  }
189
- const skipOldSemconvContentLengthAttrs = !(this._semconvStability & SemconvStability.OLD);
190
- addSpanNetworkEvents(span, mainRequest, this.getConfig().ignoreNetworkEvents, undefined, skipOldSemconvContentLengthAttrs);
166
+ addSpanNetworkEvents(span, mainRequest, this.getConfig().ignoreNetworkEvents, undefined, true);
191
167
  }
192
168
  }
193
169
  /**
@@ -219,31 +195,19 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
219
195
  this._diag.debug('ignoring span as url matches ignored url');
220
196
  return;
221
197
  }
222
- let name = '';
223
198
  const attributes = {};
224
- if (this._semconvStability & SemconvStability.OLD) {
225
- name = method.toUpperCase();
226
- attributes[ATTR_HTTP_METHOD] = method;
227
- attributes[ATTR_HTTP_URL] = parsedUrl.toString();
199
+ const origMethod = method;
200
+ const normMethod = normalizeHttpRequestMethod(method);
201
+ const name = normMethod;
202
+ attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;
203
+ if (normMethod !== origMethod) {
204
+ attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;
228
205
  }
229
- if (this._semconvStability & SemconvStability.STABLE) {
230
- const origMethod = method;
231
- const normMethod = normalizeHttpRequestMethod(method);
232
- if (!name) {
233
- // The "old" span name wins if emitting both old and stable semconv
234
- // ('http/dup').
235
- name = normMethod;
236
- }
237
- attributes[ATTR_HTTP_REQUEST_METHOD] = normMethod;
238
- if (normMethod !== origMethod) {
239
- attributes[ATTR_HTTP_REQUEST_METHOD_ORIGINAL] = origMethod;
240
- }
241
- attributes[ATTR_URL_FULL] = parsedUrl.toString();
242
- attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;
243
- const serverPort = serverPortFromUrl(parsedUrl);
244
- if (serverPort) {
245
- attributes[ATTR_SERVER_PORT] = serverPort;
246
- }
206
+ attributes[ATTR_URL_FULL] = parsedUrl.toString();
207
+ attributes[ATTR_SERVER_ADDRESS] = parsedUrl.hostname;
208
+ const serverPort = serverPortFromUrl(parsedUrl);
209
+ if (serverPort) {
210
+ attributes[ATTR_SERVER_PORT] = serverPort;
247
211
  }
248
212
  const currentSpan = this.tracer.startSpan(name, {
249
213
  kind: api.SpanKind.CLIENT,
@@ -300,7 +264,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
300
264
  if (span) {
301
265
  plugin._findResourceAndAddNetworkEvents(xhrMem, span, spanUrl, sendStartTime, performanceEndTime);
302
266
  span.addEvent(eventName, endTime);
303
- plugin._addFinalSpanAttributes(span, xhrMem, spanUrl);
267
+ plugin._addFinalSpanAttributes(span, xhrMem);
304
268
  span.end(endTime);
305
269
  plugin._tasksCount--;
306
270
  }
@@ -317,21 +281,19 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
317
281
  if (xhrMem.span) {
318
282
  const span = xhrMem.span;
319
283
  plugin._applyAttributesAfterXHR(span, xhr);
320
- if (plugin._semconvStability & SemconvStability.STABLE) {
321
- if (isError) {
322
- if (errorType) {
323
- span.setStatus({
324
- code: api.SpanStatusCode.ERROR,
325
- message: errorType,
326
- });
327
- span.setAttribute(ATTR_ERROR_TYPE, errorType);
328
- }
329
- }
330
- else if (xhrMem.status && xhrMem.status >= 400) {
331
- span.setStatus({ code: api.SpanStatusCode.ERROR });
332
- span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));
284
+ if (isError) {
285
+ if (errorType) {
286
+ span.setStatus({
287
+ code: api.SpanStatusCode.ERROR,
288
+ message: errorType,
289
+ });
290
+ span.setAttribute(ATTR_ERROR_TYPE, errorType);
333
291
  }
334
292
  }
293
+ else if (xhrMem.status && xhrMem.status >= 400) {
294
+ span.setStatus({ code: api.SpanStatusCode.ERROR });
295
+ span.setAttribute(ATTR_ERROR_TYPE, String(xhrMem.status));
296
+ }
335
297
  }
336
298
  const performanceEndTime = hrTime();
337
299
  const endTime = Date.now();
@@ -385,12 +347,7 @@ export class XMLHttpRequestInstrumentation extends InstrumentationBase {
385
347
  const body = args[0];
386
348
  const bodyLength = getXHRBodyLength(body);
387
349
  if (bodyLength !== undefined) {
388
- if (plugin._semconvStability & SemconvStability.OLD) {
389
- currentSpan.setAttribute(ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED, bodyLength);
390
- }
391
- if (plugin._semconvStability & SemconvStability.STABLE) {
392
- currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);
393
- }
350
+ currentSpan.setAttribute(ATTR_HTTP_REQUEST_BODY_SIZE, bodyLength);
394
351
  }
395
352
  }
396
353
  api.context.with(api.trace.setSpan(api.context.active(), currentSpan), () => {