Skip to content

Commit

Permalink
fix imports & export utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Jan 25, 2024
1 parent b588e6d commit a4488c1
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 140 deletions.
14 changes: 4 additions & 10 deletions packages/angular/src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ import { NavigationEnd, NavigationStart, ResolveEnd } from '@angular/router';
import {
WINDOW,
browserTracingIntegration as originalBrowserTracingIntegration,
browserTracingStartNavigationSpan,
getCurrentScope,
} from '@sentry/browser';
import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
getActiveSpan,
getClient,
spanToJSON,
startInactiveSpan,
} from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getActiveSpan, spanToJSON, startInactiveSpan } from '@sentry/core';
import type { Integration, Span, Transaction, TransactionContext } from '@sentry/types';
import { logger, stripUrlQueryAndFragment, timestampInSeconds } from '@sentry/utils';
import type { Observable } from 'rxjs';
Expand Down Expand Up @@ -110,10 +105,9 @@ export class TraceService implements OnDestroy {

const strippedUrl = stripUrlQueryAndFragment(navigationEvent.url);

const client = getClient();
if (hooksBasedInstrumentation && client && client.emit) {
if (hooksBasedInstrumentation) {
if (!getActiveSpan()) {
client.emit('startNavigationSpan', {
browserTracingStartNavigationSpan({
name: strippedUrl,
op: 'navigation',
origin: 'auto.navigation.angular',
Expand Down
4 changes: 4 additions & 0 deletions packages/browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ export {
} from '@sentry-internal/feedback';

export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
defaultRequestInstrumentationOptions,
instrumentOutgoingRequests,
browserTracingIntegration,
browserTracingStartNavigationSpan,
browserTracingStartPageLoadSpan,
} from '@sentry-internal/tracing';
export type { RequestInstrumentationOptions } from '@sentry-internal/tracing';
export {
Expand Down
113 changes: 2 additions & 111 deletions packages/core/src/tracing/trace.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import type {
Instrumenter,
Primitive,
Scope,
Span,
SpanTimeInput,
TransactionContext,
TransactionMetadata,
} from '@sentry/types';
import type { SpanAttributes } from '@sentry/types';
import type { SpanOrigin } from '@sentry/types';
import type { TransactionSource } from '@sentry/types';
import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types';

import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils';

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

interface StartSpanOptions extends TransactionContext {
/** A manually specified start time for the created `Span` object. */
startTime?: SpanTimeInput;

/** If defined, start this span off this scope instead off the current scope. */
scope?: Scope;

/** The name of the span. */
name: string;

/** An op for the span. This is a categorization for spans. */
op?: string;

/** The origin of the span - if it comes from auto instrumenation or manual instrumentation. */
origin?: SpanOrigin;

/** Attributes for the span. */
attributes?: SpanAttributes;

// All remaining fields are deprecated

/**
* @deprecated Manually set the end timestamp instead.
*/
trimEnd?: boolean;

/**
* @deprecated This cannot be set manually anymore.
*/
parentSampled?: boolean;

/**
* @deprecated Use attributes or set data on scopes instead.
*/
metadata?: Partial<TransactionMetadata>;

/**
* The name thingy.
* @deprecated Use `name` instead.
*/
description?: string;

/**
* @deprecated Use `span.setStatus()` instead.
*/
status?: string;

/**
* @deprecated Use `scope` instead.
*/
parentSpanId?: string;

/**
* @deprecated You cannot manually set the span to sampled anymore.
*/
sampled?: boolean;

/**
* @deprecated You cannot manually set the spanId anymore.
*/
spanId?: string;

/**
* @deprecated You cannot manually set the traceId anymore.
*/
traceId?: string;

/**
* @deprecated Use an attribute instead.
*/
source?: TransactionSource;

/**
* @deprecated Use attributes or set tags on the scope instead.
*/
tags?: { [key: string]: Primitive };

/**
* @deprecated Use attributes instead.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data?: { [key: string]: any };

/**
* @deprecated Use `startTime` instead.
*/
startTimestamp?: number;

/**
* @deprecated Use `span.end()` instead.
*/
endTimestamp?: number;

/**
* @deprecated You cannot set the instrumenter manually anymore.
*/
instrumenter?: Instrumenter;
}

/**
* Wraps a function with a transaction/span and finishes the span after the function is done.
*
Expand Down
34 changes: 29 additions & 5 deletions packages/tracing-internal/src/browser/browserTracingIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines, complexity */
import type { IdleTransaction } from '@sentry/core';
import { IdleTransaction, getClient } from '@sentry/core';
import { defineIntegration, getCurrentHub } from '@sentry/core';
import {
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
Expand Down Expand Up @@ -347,7 +347,7 @@ export const _browserTracingIntegration = ((_options: Partial<BrowserTracingOpti
origin: 'auto.pageload.browser',
metadata: { source: 'url' },
};
client.emit('startPageLoadSpan', context);
browserTracingStartPageLoadSpan(context);
}

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

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

export const browserTracingIntegration = defineIntegration(_browserTracingIntegration);

/**
* Manually start a page load span.
* This will only do something if the BrowserTracing integration has been setup.
*/
export function browserTracingStartPageLoadSpan(spanOptions: StartSpanOptions): void {
const client = getClient();
if (!client || !client.emit) {
return;
}

client.emit('startPageLoadSpan', spanOptions);
}

/**
* Manually start a navigation span.
* This will only do something if the BrowserTracing integration has been setup.
*/
export function browserTracingStartNavigationSpan(spanOptions: StartSpanOptions): void {
const client = getClient();
if (!client || !client.emit) {
return;
}

client.emit('startNavigationSpan', spanOptions);
}

/** Returns the value of a meta tag */
export function getMetaContent(metaName: string): string | undefined {
// Can't specify generic to `getDomElement` because tracing can be used
Expand Down
27 changes: 14 additions & 13 deletions packages/tracing-internal/src/browser/browsertracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
*/
instrumentPageLoad: boolean;

/**
* Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
* not suited towards doing precise measurements of operations. By default, we recommend that this option
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
*
* Default: true
*/
startTransactionOnLocationChange: boolean;

/**
* Flag to enable/disable creation of `navigation` transaction on history changes.
* Default: true
Expand All @@ -93,16 +84,26 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
* Default: true
* @deprecated Configure `instrumentPageLoad` instead.
*/
startTransactionOnPageLoad: boolean;
startTransactionOnPageLoad?: boolean;

/**
* Flag spans where tabs moved to background with "cancelled". Browser background tab timing is
* not suited towards doing precise measurements of operations. By default, we recommend that this option
* be enabled as background transactions can mess up your statistics in nondeterministic ways.
*
* Default: true
*/
markBackgroundSpan: boolean;

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

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

private _hasSetTracePropagationTargets: boolean;

public constructor(_options?: Partial<BrowserTracingOptions>) {
public constructor(_options: Partial<BrowserTracingOptions> = {}) {
this.name = BROWSER_TRACING_INTEGRATION_ID;
this._hasSetTracePropagationTargets = false;

Expand Down Expand Up @@ -321,7 +322,7 @@ export class BrowserTracing implements Integration {
instrumentNavigation,
);

if (markBackgroundTransactions) {
if (markBackgroundSpan) {
registerBackgroundTabDetection();
}

Expand Down
6 changes: 5 additions & 1 deletion packages/tracing-internal/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export {
BROWSER_TRACING_INTEGRATION_ID,
} from './browsertracing';

export { browserTracingIntegration } from './browserTracingIntegration';
export {
browserTracingIntegration,
browserTracingStartNavigationSpan,
browserTracingStartPageLoadSpan,
} from './browserTracingIntegration';

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

Expand Down
4 changes: 4 additions & 0 deletions packages/tracing-internal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export {
export type { LazyLoadedIntegration } from './node';

export {
// eslint-disable-next-line deprecation/deprecation
BrowserTracing,
browserTracingIntegration,
browserTracingStartNavigationSpan,
browserTracingStartPageLoadSpan,
BROWSER_TRACING_INTEGRATION_ID,
instrumentOutgoingRequests,
defaultRequestInstrumentationOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export type { StackFrame } from './stackframe';
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
export type { TextEncoderInternal } from './textencoder';
export type { PropagationContext, TracePropagationTargets } from './tracing';
export type { StartSpanOptions } from './startSpanOptions';
export type {
CustomSamplingContext,
SamplingContext,
Expand Down
Loading

0 comments on commit a4488c1

Please sign in to comment.