Skip to content

Commit

Permalink
elevate enableHTTPTimings
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Jul 17, 2023
1 parent 9398d3e commit 92249f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
13 changes: 2 additions & 11 deletions packages/tracing-internal/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
*/
enableLongTask: boolean;

/**
* If true, Sentry will capture http timings and add them to the corresponding http spans.
*
* Default: true
*/
enableHTTPTimings: boolean;

/**
* _metricOptions allows the user to send options to change how metrics are collected.
*
Expand Down Expand Up @@ -146,7 +139,7 @@ const DEFAULT_BROWSER_TRACING_OPTIONS: BrowserTracingOptions = {
startTransactionOnLocationChange: true,
startTransactionOnPageLoad: true,
enableLongTask: true,
enableHTTPTimings: true,
_experiments: {},
...defaultRequestInstrumentationOptions,
};

Expand Down Expand Up @@ -285,9 +278,7 @@ export class BrowserTracing implements Integration {
traceXHR,
tracePropagationTargets,
shouldCreateSpanForRequest,
_experiments: {
enableHTTPTimings,
},
enableHTTPTimings,
});
}

Expand Down
31 changes: 19 additions & 12 deletions packages/tracing-internal/src/browser/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/];

/** Options for Request Instrumentation */
export interface RequestInstrumentationOptions {
/**
* Allow experiments for the request instrumentation.
*/
_experiments: Partial<{
enableHTTPTimings: boolean;
}>;

/**
* @deprecated Will be removed in v8.
* Use `shouldCreateSpanForRequest` to control span creation and `tracePropagationTargets` to control
Expand Down Expand Up @@ -52,6 +45,13 @@ export interface RequestInstrumentationOptions {
*/
traceXHR: boolean;

/**
* 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.
* Return false if you don't want a span for the given url.
Expand Down Expand Up @@ -114,16 +114,23 @@ type PolymorphicRequestHeaders =
export const defaultRequestInstrumentationOptions: RequestInstrumentationOptions = {
traceFetch: true,
traceXHR: true,
enableHTTPTimings: true,
// TODO (v8): Remove this property
tracingOrigins: DEFAULT_TRACE_PROPAGATION_TARGETS,
tracePropagationTargets: DEFAULT_TRACE_PROPAGATION_TARGETS,
_experiments: {},
};

/** Registers span creators for xhr and fetch requests */
export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumentationOptions>): void {
// 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,
traceXHR: defaultRequestInstrumentationOptions.traceXHR,
..._options,
Expand All @@ -143,7 +150,7 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
if (traceFetch) {
addInstrumentationHandler('fetch', (handlerData: FetchData) => {
const createdSpan = fetchCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_experiments?.enableHTTPTimings && createdSpan) {
if (enableHTTPTimings && createdSpan) {
addHTTPTimings(createdSpan);
}
});
Expand All @@ -152,7 +159,7 @@ export function instrumentOutgoingRequests(_options?: Partial<RequestInstrumenta
if (traceXHR) {
addInstrumentationHandler('xhr', (handlerData: XHRData) => {
const createdSpan = xhrCallback(handlerData, shouldCreateSpan, shouldAttachHeadersWithTargets, spans);
if (_experiments?.enableHTTPTimings && createdSpan) {
if (enableHTTPTimings && createdSpan) {
addHTTPTimings(createdSpan);
}
});
Expand Down

0 comments on commit 92249f3

Please sign in to comment.