Skip to content

Commit a4488c1

Browse files
committed
fix imports & export utils
1 parent b588e6d commit a4488c1

File tree

9 files changed

+167
-140
lines changed

9 files changed

+167
-140
lines changed

packages/angular/src/tracing.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ import { NavigationEnd, NavigationStart, ResolveEnd } from '@angular/router';
1010
import {
1111
WINDOW,
1212
browserTracingIntegration as originalBrowserTracingIntegration,
13+
browserTracingStartNavigationSpan,
1314
getCurrentScope,
1415
} from '@sentry/browser';
15-
import {
16-
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
17-
getActiveSpan,
18-
getClient,
19-
spanToJSON,
20-
startInactiveSpan,
21-
} from '@sentry/core';
16+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, spanToJSON, startInactiveSpan } from '@sentry/core';
2217
import type { Integration, Span, Transaction, TransactionContext } from '@sentry/types';
2318
import { logger, stripUrlQueryAndFragment, timestampInSeconds } from '@sentry/utils';
2419
import type { Observable } from 'rxjs';
@@ -110,10 +105,9 @@ export class TraceService implements OnDestroy {
110105

111106
const strippedUrl = stripUrlQueryAndFragment(navigationEvent.url);
112107

113-
const client = getClient();
114-
if (hooksBasedInstrumentation && client && client.emit) {
108+
if (hooksBasedInstrumentation) {
115109
if (!getActiveSpan()) {
116-
client.emit('startNavigationSpan', {
110+
browserTracingStartNavigationSpan({
117111
name: strippedUrl,
118112
op: 'navigation',
119113
origin: 'auto.navigation.angular',

packages/browser/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ export {
5454
} from '@sentry-internal/feedback';
5555

5656
export {
57+
// eslint-disable-next-line deprecation/deprecation
5758
BrowserTracing,
5859
defaultRequestInstrumentationOptions,
5960
instrumentOutgoingRequests,
61+
browserTracingIntegration,
62+
browserTracingStartNavigationSpan,
63+
browserTracingStartPageLoadSpan,
6064
} from '@sentry-internal/tracing';
6165
export type { RequestInstrumentationOptions } from '@sentry-internal/tracing';
6266
export {

packages/core/src/tracing/trace.ts

Lines changed: 2 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
import type {
2-
Instrumenter,
3-
Primitive,
4-
Scope,
5-
Span,
6-
SpanTimeInput,
7-
TransactionContext,
8-
TransactionMetadata,
9-
} from '@sentry/types';
10-
import type { SpanAttributes } from '@sentry/types';
11-
import type { SpanOrigin } from '@sentry/types';
12-
import type { TransactionSource } from '@sentry/types';
1+
import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types';
2+
133
import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils';
144

155
import { DEBUG_BUILD } from '../debug-build';
@@ -20,105 +10,6 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors';
2010
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
2111
import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
2212

23-
interface StartSpanOptions extends TransactionContext {
24-
/** A manually specified start time for the created `Span` object. */
25-
startTime?: SpanTimeInput;
26-
27-
/** If defined, start this span off this scope instead off the current scope. */
28-
scope?: Scope;
29-
30-
/** The name of the span. */
31-
name: string;
32-
33-
/** An op for the span. This is a categorization for spans. */
34-
op?: string;
35-
36-
/** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */
37-
origin?: SpanOrigin;
38-
39-
/** Attributes for the span. */
40-
attributes?: SpanAttributes;
41-
42-
// All remaining fields are deprecated
43-
44-
/**
45-
* @deprecated Manually set the end timestamp instead.
46-
*/
47-
trimEnd?: boolean;
48-
49-
/**
50-
* @deprecated This cannot be set manually anymore.
51-
*/
52-
parentSampled?: boolean;
53-
54-
/**
55-
* @deprecated Use attributes or set data on scopes instead.
56-
*/
57-
metadata?: Partial<TransactionMetadata>;
58-
59-
/**
60-
* The name thingy.
61-
* @deprecated Use `name` instead.
62-
*/
63-
description?: string;
64-
65-
/**
66-
* @deprecated Use `span.setStatus()` instead.
67-
*/
68-
status?: string;
69-
70-
/**
71-
* @deprecated Use `scope` instead.
72-
*/
73-
parentSpanId?: string;
74-
75-
/**
76-
* @deprecated You cannot manually set the span to sampled anymore.
77-
*/
78-
sampled?: boolean;
79-
80-
/**
81-
* @deprecated You cannot manually set the spanId anymore.
82-
*/
83-
spanId?: string;
84-
85-
/**
86-
* @deprecated You cannot manually set the traceId anymore.
87-
*/
88-
traceId?: string;
89-
90-
/**
91-
* @deprecated Use an attribute instead.
92-
*/
93-
source?: TransactionSource;
94-
95-
/**
96-
* @deprecated Use attributes or set tags on the scope instead.
97-
*/
98-
tags?: { [key: string]: Primitive };
99-
100-
/**
101-
* @deprecated Use attributes instead.
102-
*/
103-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
104-
data?: { [key: string]: any };
105-
106-
/**
107-
* @deprecated Use `startTime` instead.
108-
*/
109-
startTimestamp?: number;
110-
111-
/**
112-
* @deprecated Use `span.end()` instead.
113-
*/
114-
endTimestamp?: number;
115-
116-
/**
117-
* @deprecated You cannot set the instrumenter manually anymore.
118-
*/
119-
instrumenter?: Instrumenter;
120-
}
121-
12213
/**
12314
* Wraps a function with a transaction/span and finishes the span after the function is done.
12415
*

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines, complexity */
2-
import type { IdleTransaction } from '@sentry/core';
2+
import { IdleTransaction, getClient } from '@sentry/core';
33
import { defineIntegration, getCurrentHub } from '@sentry/core';
44
import {
55
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
@@ -347,7 +347,7 @@ export const _browserTracingIntegration = ((_options: Partial<BrowserTracingOpti
347347
origin: 'auto.pageload.browser',
348348
metadata: { source: 'url' },
349349
};
350-
client.emit('startPageLoadSpan', context);
350+
browserTracingStartPageLoadSpan(context);
351351
}
352352

353353
if (options.instrumentNavigation && client.emit) {
@@ -381,9 +381,7 @@ export const _browserTracingIntegration = ((_options: Partial<BrowserTracingOpti
381381
metadata: { source: 'url' },
382382
};
383383

384-
// We know this is fine because we checked above...
385-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
386-
client.emit!('startNavigationSpan', context);
384+
browserTracingStartNavigationSpan(context);
387385
}
388386
});
389387
}
@@ -409,6 +407,32 @@ export const _browserTracingIntegration = ((_options: Partial<BrowserTracingOpti
409407

410408
export const browserTracingIntegration = defineIntegration(_browserTracingIntegration);
411409

410+
/**
411+
* Manually start a page load span.
412+
* This will only do something if the BrowserTracing integration has been setup.
413+
*/
414+
export function browserTracingStartPageLoadSpan(spanOptions: StartSpanOptions): void {
415+
const client = getClient();
416+
if (!client || !client.emit) {
417+
return;
418+
}
419+
420+
client.emit('startPageLoadSpan', spanOptions);
421+
}
422+
423+
/**
424+
* Manually start a navigation span.
425+
* This will only do something if the BrowserTracing integration has been setup.
426+
*/
427+
export function browserTracingStartNavigationSpan(spanOptions: StartSpanOptions): void {
428+
const client = getClient();
429+
if (!client || !client.emit) {
430+
return;
431+
}
432+
433+
client.emit('startNavigationSpan', spanOptions);
434+
}
435+
412436
/** Returns the value of a meta tag */
413437
export function getMetaContent(metaName: string): string | undefined {
414438
// Can't specify generic to `getDomElement` because tracing can be used

packages/tracing-internal/src/browser/browsertracing.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
7171
*/
7272
instrumentPageLoad: boolean;
7373

74-
/**
75-
* Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
76-
* not suited towards doing precise measurements of operations. By default, we recommend that this option
77-
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
78-
*
79-
* Default: true
80-
*/
81-
startTransactionOnLocationChange: boolean;
82-
8374
/**
8475
* Flag to enable/disable creation of `navigation` transaction on history changes.
8576
* Default: true
@@ -93,16 +84,26 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
9384
* Default: true
9485
* @deprecated Configure `instrumentPageLoad` instead.
9586
*/
96-
startTransactionOnPageLoad: boolean;
87+
startTransactionOnPageLoad?: boolean;
88+
89+
/**
90+
* Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
91+
* not suited towards doing precise measurements of operations. By default, we recommend that this option
92+
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
93+
*
94+
* Default: true
95+
*/
96+
markBackgroundSpan: boolean;
9797

9898
/**
9999
* Flag Transactions where tabs moved to background with "cancelled". Browser background tab timing is
100100
* not suited towards doing precise measurements of operations. By default, we recommend that this option
101101
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
102102
*
103103
* Default: true
104+
* @deprecated Configure `markBackgroundSpan` instead.
104105
*/
105-
markBackgroundTransactions: boolean;
106+
markBackgroundTransactions?: boolean;
106107

107108
/**
108109
* If true, Sentry will capture long tasks and add them to the corresponding transaction.
@@ -201,7 +202,7 @@ export class BrowserTracing implements Integration {
201202

202203
private _hasSetTracePropagationTargets: boolean;
203204

204-
public constructor(_options?: Partial<BrowserTracingOptions>) {
205+
public constructor(_options: Partial<BrowserTracingOptions> = {}) {
205206
this.name = BROWSER_TRACING_INTEGRATION_ID;
206207
this._hasSetTracePropagationTargets = false;
207208

@@ -321,7 +322,7 @@ export class BrowserTracing implements Integration {
321322
instrumentNavigation,
322323
);
323324

324-
if (markBackgroundTransactions) {
325+
if (markBackgroundSpan) {
325326
registerBackgroundTabDetection();
326327
}
327328

packages/tracing-internal/src/browser/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export {
88
BROWSER_TRACING_INTEGRATION_ID,
99
} from './browsertracing';
1010

11-
export { browserTracingIntegration } from './browserTracingIntegration';
11+
export {
12+
browserTracingIntegration,
13+
browserTracingStartNavigationSpan,
14+
browserTracingStartPageLoadSpan,
15+
} from './browserTracingIntegration';
1216

1317
export { instrumentOutgoingRequests, defaultRequestInstrumentationOptions } from './request';
1418

packages/tracing-internal/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export {
1313
export type { LazyLoadedIntegration } from './node';
1414

1515
export {
16+
// eslint-disable-next-line deprecation/deprecation
1617
BrowserTracing,
18+
browserTracingIntegration,
19+
browserTracingStartNavigationSpan,
20+
browserTracingStartPageLoadSpan,
1721
BROWSER_TRACING_INTEGRATION_ID,
1822
instrumentOutgoingRequests,
1923
defaultRequestInstrumentationOptions,

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export type { StackFrame } from './stackframe';
104104
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
105105
export type { TextEncoderInternal } from './textencoder';
106106
export type { PropagationContext, TracePropagationTargets } from './tracing';
107+
export type { StartSpanOptions } from './startSpanOptions';
107108
export type {
108109
CustomSamplingContext,
109110
SamplingContext,

0 commit comments

Comments
 (0)