@sentry-internal/tracing
Advanced tools
Comparing version 7.59.0-beta.1 to 7.59.1
@@ -22,2 +22,3 @@ Object.defineProperty(exports, '__esModule', { value: true }); | ||
enableLongTask: true, | ||
_experiments: {}, | ||
...request.defaultRequestInstrumentationOptions, | ||
@@ -105,2 +106,3 @@ }; | ||
shouldCreateSpanForRequest, | ||
enableHTTPTimings, | ||
_experiments, | ||
@@ -153,5 +155,3 @@ } = this.options; | ||
shouldCreateSpanForRequest, | ||
_experiments: { | ||
enableHTTPTimings: _experiments.enableHTTPTimings, | ||
}, | ||
enableHTTPTimings, | ||
}); | ||
@@ -158,0 +158,0 @@ } |
@@ -1,5 +0,1 @@ | ||
var { | ||
_optionalChain | ||
} = require('@sentry/utils/cjs/buildPolyfills'); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
@@ -19,6 +15,6 @@ | ||
traceXHR: true, | ||
enableHTTPTimings: true, | ||
// TODO (v8): Remove this property | ||
tracingOrigins: DEFAULT_TRACE_PROPAGATION_TARGETS, | ||
tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS, | ||
_experiments: {}, | ||
}; | ||
@@ -28,4 +24,11 @@ | ||
function instrumentOutgoingRequests(_options) { | ||
// eslint-disable-next-line deprecation/deprecation | ||
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest, _experiments } = { | ||
const { | ||
traceFetch, | ||
traceXHR, | ||
tracePropagationTargets, | ||
// eslint-disable-next-line deprecation/deprecation | ||
tracingOrigins, | ||
shouldCreateSpanForRequest, | ||
enableHTTPTimings, | ||
} = { | ||
traceFetch: defaultRequestInstrumentationOptions.traceFetch, | ||
@@ -50,3 +53,3 @@ traceXHR: defaultRequestInstrumentationOptions.traceXHR, | ||
const createdSpan = fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans); | ||
if (_optionalChain([_experiments, 'optionalAccess', _2 => _2.enableHTTPTimings]) && createdSpan) { | ||
if (enableHTTPTimings && createdSpan) { | ||
addHTTPTimings(createdSpan); | ||
@@ -60,3 +63,3 @@ } | ||
const createdSpan = xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans); | ||
if (_optionalChain([_experiments, 'optionalAccess', _3 => _3.enableHTTPTimings]) && createdSpan) { | ||
if (enableHTTPTimings && createdSpan) { | ||
addHTTPTimings(createdSpan); | ||
@@ -91,10 +94,44 @@ } | ||
/** | ||
* Converts ALPN protocol ids to name and version. | ||
* | ||
* (https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids) | ||
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol | ||
*/ | ||
function extractNetworkProtocol(nextHopProtocol) { | ||
let name = 'unknown'; | ||
let version = 'unknown'; | ||
let _name = ''; | ||
for (const char of nextHopProtocol) { | ||
// http/1.1 etc. | ||
if (char === '/') { | ||
[name, version] = nextHopProtocol.split('/'); | ||
break; | ||
} | ||
// h2, h3 etc. | ||
if (!isNaN(Number(char))) { | ||
name = _name === 'h' ? 'http' : _name; | ||
version = nextHopProtocol.split(_name)[1]; | ||
break; | ||
} | ||
_name += char; | ||
} | ||
if (_name === nextHopProtocol) { | ||
// webrtc, ftp, etc. | ||
name = _name; | ||
} | ||
return { name, version }; | ||
} | ||
function getAbsoluteTime(time) { | ||
return ((utils.browserPerformanceTimeOrigin || performance.timeOrigin) + time) / 1000; | ||
} | ||
function resourceTimingEntryToSpanData(resourceTiming) { | ||
const version = resourceTiming.nextHopProtocol.split('/')[1] || 'none'; | ||
const { name, version } = extractNetworkProtocol(resourceTiming.nextHopProtocol); | ||
const timingSpanData = []; | ||
if (version) { | ||
timingSpanData.push(['network.protocol.version', version]); | ||
} | ||
timingSpanData.push(['network.protocol.version', version], ['network.protocol.name', name]); | ||
if (!utils.browserPerformanceTimeOrigin) { | ||
@@ -105,5 +142,12 @@ return timingSpanData; | ||
...timingSpanData, | ||
['http.request.connect_start', (utils.browserPerformanceTimeOrigin + resourceTiming.connectStart) / 1000], | ||
['http.request.request_start', (utils.browserPerformanceTimeOrigin + resourceTiming.requestStart) / 1000], | ||
['http.request.response_start', (utils.browserPerformanceTimeOrigin + resourceTiming.responseStart) / 1000], | ||
['http.request.redirect_start', getAbsoluteTime(resourceTiming.redirectStart)], | ||
['http.request.fetch_start', getAbsoluteTime(resourceTiming.fetchStart)], | ||
['http.request.domain_lookup_start', getAbsoluteTime(resourceTiming.domainLookupStart)], | ||
['http.request.domain_lookup_end', getAbsoluteTime(resourceTiming.domainLookupEnd)], | ||
['http.request.connect_start', getAbsoluteTime(resourceTiming.connectStart)], | ||
['http.request.secure_connection_start', getAbsoluteTime(resourceTiming.secureConnectionStart)], | ||
['http.request.connection_end', getAbsoluteTime(resourceTiming.connectEnd)], | ||
['http.request.request_start', getAbsoluteTime(resourceTiming.requestStart)], | ||
['http.request.response_start', getAbsoluteTime(resourceTiming.responseStart)], | ||
['http.request.response_end', getAbsoluteTime(resourceTiming.responseEnd)], | ||
]; | ||
@@ -387,2 +431,3 @@ } | ||
exports.defaultRequestInstrumentationOptions = defaultRequestInstrumentationOptions; | ||
exports.extractNetworkProtocol = extractNetworkProtocol; | ||
exports.fetchCallback = fetchCallback; | ||
@@ -389,0 +434,0 @@ exports.instrumentOutgoingRequests = instrumentOutgoingRequests; |
@@ -20,2 +20,3 @@ import { TRACING_DEFAULTS, addTracingExtensions, startIdleTransaction, getActiveTransaction } from '@sentry/core'; | ||
enableLongTask: true, | ||
_experiments: {}, | ||
...defaultRequestInstrumentationOptions, | ||
@@ -103,2 +104,3 @@ }; | ||
shouldCreateSpanForRequest, | ||
enableHTTPTimings, | ||
_experiments, | ||
@@ -151,5 +153,3 @@ } = this.options; | ||
shouldCreateSpanForRequest, | ||
_experiments: { | ||
enableHTTPTimings: _experiments.enableHTTPTimings, | ||
}, | ||
enableHTTPTimings, | ||
}); | ||
@@ -156,0 +156,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import { _optionalChain } from '@sentry/utils/esm/buildPolyfills'; | ||
import { hasTracingEnabled, getCurrentHub, getDynamicSamplingContextFromClient } from '@sentry/core'; | ||
@@ -14,6 +13,6 @@ import { addInstrumentationHandler, browserPerformanceTimeOrigin, generateSentryTraceHeader, dynamicSamplingContextToSentryBaggageHeader, isInstanceOf, BAGGAGE_HEADER_NAME, SENTRY_XHR_DATA_KEY, stringMatchesSomePattern } from '@sentry/utils'; | ||
traceXHR: true, | ||
enableHTTPTimings: true, | ||
// TODO (v8): Remove this property | ||
tracingOrigins: DEFAULT_TRACE_PROPAGATION_TARGETS, | ||
tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS, | ||
_experiments: {}, | ||
}; | ||
@@ -23,4 +22,11 @@ | ||
function instrumentOutgoingRequests(_options) { | ||
// eslint-disable-next-line deprecation/deprecation | ||
const { traceFetch, traceXHR, tracePropagationTargets, tracingOrigins, shouldCreateSpanForRequest, _experiments } = { | ||
const { | ||
traceFetch, | ||
traceXHR, | ||
tracePropagationTargets, | ||
// eslint-disable-next-line deprecation/deprecation | ||
tracingOrigins, | ||
shouldCreateSpanForRequest, | ||
enableHTTPTimings, | ||
} = { | ||
traceFetch: defaultRequestInstrumentationOptions.traceFetch, | ||
@@ -45,3 +51,3 @@ traceXHR: defaultRequestInstrumentationOptions.traceXHR, | ||
const createdSpan = fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans); | ||
if (_optionalChain([_experiments, 'optionalAccess', _2 => _2.enableHTTPTimings]) && createdSpan) { | ||
if (enableHTTPTimings && createdSpan) { | ||
addHTTPTimings(createdSpan); | ||
@@ -55,3 +61,3 @@ } | ||
const createdSpan = xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans); | ||
if (_optionalChain([_experiments, 'optionalAccess', _3 => _3.enableHTTPTimings]) && createdSpan) { | ||
if (enableHTTPTimings && createdSpan) { | ||
addHTTPTimings(createdSpan); | ||
@@ -86,10 +92,44 @@ } | ||
/** | ||
* Converts ALPN protocol ids to name and version. | ||
* | ||
* (https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids) | ||
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol | ||
*/ | ||
function extractNetworkProtocol(nextHopProtocol) { | ||
let name = 'unknown'; | ||
let version = 'unknown'; | ||
let _name = ''; | ||
for (const char of nextHopProtocol) { | ||
// http/1.1 etc. | ||
if (char === '/') { | ||
[name, version] = nextHopProtocol.split('/'); | ||
break; | ||
} | ||
// h2, h3 etc. | ||
if (!isNaN(Number(char))) { | ||
name = _name === 'h' ? 'http' : _name; | ||
version = nextHopProtocol.split(_name)[1]; | ||
break; | ||
} | ||
_name += char; | ||
} | ||
if (_name === nextHopProtocol) { | ||
// webrtc, ftp, etc. | ||
name = _name; | ||
} | ||
return { name, version }; | ||
} | ||
function getAbsoluteTime(time) { | ||
return ((browserPerformanceTimeOrigin || performance.timeOrigin) + time) / 1000; | ||
} | ||
function resourceTimingEntryToSpanData(resourceTiming) { | ||
const version = resourceTiming.nextHopProtocol.split('/')[1] || 'none'; | ||
const { name, version } = extractNetworkProtocol(resourceTiming.nextHopProtocol); | ||
const timingSpanData = []; | ||
if (version) { | ||
timingSpanData.push(['network.protocol.version', version]); | ||
} | ||
timingSpanData.push(['network.protocol.version', version], ['network.protocol.name', name]); | ||
if (!browserPerformanceTimeOrigin) { | ||
@@ -100,5 +140,12 @@ return timingSpanData; | ||
...timingSpanData, | ||
['http.request.connect_start', (browserPerformanceTimeOrigin + resourceTiming.connectStart) / 1000], | ||
['http.request.request_start', (browserPerformanceTimeOrigin + resourceTiming.requestStart) / 1000], | ||
['http.request.response_start', (browserPerformanceTimeOrigin + resourceTiming.responseStart) / 1000], | ||
['http.request.redirect_start', getAbsoluteTime(resourceTiming.redirectStart)], | ||
['http.request.fetch_start', getAbsoluteTime(resourceTiming.fetchStart)], | ||
['http.request.domain_lookup_start', getAbsoluteTime(resourceTiming.domainLookupStart)], | ||
['http.request.domain_lookup_end', getAbsoluteTime(resourceTiming.domainLookupEnd)], | ||
['http.request.connect_start', getAbsoluteTime(resourceTiming.connectStart)], | ||
['http.request.secure_connection_start', getAbsoluteTime(resourceTiming.secureConnectionStart)], | ||
['http.request.connection_end', getAbsoluteTime(resourceTiming.connectEnd)], | ||
['http.request.request_start', getAbsoluteTime(resourceTiming.requestStart)], | ||
['http.request.response_start', getAbsoluteTime(resourceTiming.responseStart)], | ||
['http.request.response_end', getAbsoluteTime(resourceTiming.responseEnd)], | ||
]; | ||
@@ -379,3 +426,3 @@ } | ||
export { DEFAULT_TRACE_PROPAGATION_TARGETS, addTracingHeadersToFetchRequest, defaultRequestInstrumentationOptions, fetchCallback, instrumentOutgoingRequests, shouldAttachHeaders, xhrCallback }; | ||
export { DEFAULT_TRACE_PROPAGATION_TARGETS, addTracingHeadersToFetchRequest, defaultRequestInstrumentationOptions, extractNetworkProtocol, fetchCallback, instrumentOutgoingRequests, shouldAttachHeaders, xhrCallback }; | ||
//# sourceMappingURL=request.js.map |
{ | ||
"name": "@sentry-internal/tracing", | ||
"version": "7.59.0-beta.1", | ||
"version": "7.59.1", | ||
"description": "Sentry Internal Tracing Package", | ||
@@ -26,5 +26,5 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/core": "7.59.0-beta.1", | ||
"@sentry/types": "7.59.0-beta.1", | ||
"@sentry/utils": "7.59.0-beta.1", | ||
"@sentry/core": "7.59.1", | ||
"@sentry/types": "7.59.1", | ||
"@sentry/utils": "7.59.1", | ||
"tslib": "^2.4.1 || ^1.9.3" | ||
@@ -31,0 +31,0 @@ }, |
@@ -84,3 +84,2 @@ import type { Hub } from '@sentry/core'; | ||
enableInteractions: boolean; | ||
enableHTTPTimings: boolean; | ||
onStartRouteTransaction: (t: Transaction | undefined, ctx: TransactionContext, getCurrentHub: () => Hub) => void; | ||
@@ -87,0 +86,0 @@ }>; |
@@ -7,8 +7,2 @@ import type { Client, Scope, Span } from '@sentry/types'; | ||
/** | ||
* Allow experiments for the request instrumentation. | ||
*/ | ||
_experiments: Partial<{ | ||
enableHTTPTimings: boolean; | ||
}>; | ||
/** | ||
* @deprecated Will be removed in v8. | ||
@@ -39,2 +33,8 @@ * Use `shouldCreateSpanForRequest` to control span creation and `tracePropagationTargets` to control | ||
/** | ||
* If true, Sentry will capture http timings and add them to the corresponding http spans. | ||
* | ||
* Default: true | ||
*/ | ||
enableHTTPTimings: boolean; | ||
/** | ||
* This function will be called before creating a span for a request with the given url. | ||
@@ -86,2 +86,12 @@ * Return false if you don't want a span for the given url. | ||
/** | ||
* Converts ALPN protocol ids to name and version. | ||
* | ||
* (https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids) | ||
* @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol | ||
*/ | ||
export declare function extractNetworkProtocol(nextHopProtocol: string): { | ||
name: string; | ||
version: string; | ||
}; | ||
/** | ||
* A function that determines whether to attach tracing headers to a request. | ||
@@ -88,0 +98,0 @@ * This was extracted from `instrumentOutgoingRequests` to make it easier to test shouldAttachHeaders. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6556
1
880796
+ Added@sentry/core@7.59.1(transitive)
+ Added@sentry/types@7.59.1(transitive)
+ Added@sentry/utils@7.59.1(transitive)
- Removed@sentry/core@7.59.0-beta.1(transitive)
- Removed@sentry/types@7.59.0-beta.1(transitive)
- Removed@sentry/utils@7.59.0-beta.1(transitive)
Updated@sentry/core@7.59.1
Updated@sentry/types@7.59.1
Updated@sentry/utils@7.59.1