Skip to content

feat(core): Remove startTransaction export #11015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ async function run() {
Sentry.startSpan({ name: 'child_span' }, () => {
// whatever a user would do here
});

// unfinished spans are filtered out
Sentry.startInactiveSpan({ name: 'span_4' });
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const transaction = Sentry.startTransaction({ name: 'some_transaction' });
const transaction = Sentry.startInactiveSpan({
name: 'some_transaction',
forceTransaction: true,
});

transaction.setMeasurement('metric.foo', 42, 'ms');
transaction.setMeasurement('metric.bar', 1337, 'nanoseconds');
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions packages/browser/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export {
makeMain,
setCurrentClient,
Scope,
// eslint-disable-next-line deprecation/deprecation
startTransaction,
continueTrace,
SDK_VERSION,
setContext,
Expand Down
33 changes: 0 additions & 33 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type {
CaptureContext,
CheckIn,
CustomSamplingContext,
Event,
EventHint,
EventProcessor,
Expand All @@ -13,7 +12,6 @@ import type {
Session,
SessionContext,
SeverityLevel,
TransactionContext,
User,
} from '@sentry/types';
import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
Expand All @@ -22,7 +20,6 @@ import { DEFAULT_ENVIRONMENT } from './constants';
import { getClient, getCurrentScope, getIsolationScope } from './currentScopes';
import { DEBUG_BUILD } from './debug-build';
import type { Hub } from './hub';
import { getCurrentHub } from './hub';
import { closeSession, makeSession, updateSession } from './session';
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
Expand Down Expand Up @@ -124,36 +121,6 @@ export function setUser(user: User | null): ReturnType<Hub['setUser']> {
getIsolationScope().setUser(user);
}

/**
* Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
*
* A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
* new child span within the transaction or any span, call the respective `.startChild()` method.
*
* Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
*
* The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
* finished child spans will be sent to Sentry.
*
* NOTE: This function should only be used for *manual* instrumentation. Auto-instrumentation should call
* `startTransaction` directly on the hub.
*
* @param context Properties of the new `Transaction`.
* @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
* default values). See {@link Options.tracesSampler}.
*
* @returns The transaction which was just started
*
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
*/
export function startTransaction(
context: TransactionContext,
customSamplingContext?: CustomSamplingContext,
): ReturnType<Hub['startTransaction']> {
// eslint-disable-next-line deprecation/deprecation
return getCurrentHub().startTransaction({ ...context }, customSamplingContext);
}

/**
* Create a cron monitor check in and send it to Sentry.
*
Expand Down
43 changes: 0 additions & 43 deletions packages/core/src/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
Breadcrumb,
BreadcrumbHint,
Client,
CustomSamplingContext,
Event,
EventHint,
Extra,
Expand All @@ -16,8 +15,6 @@ import type {
Session,
SessionContext,
SeverityLevel,
Transaction,
TransactionContext,
User,
} from '@sentry/types';
import { GLOBAL_OBJ, consoleSandbox, dateTimestampInSeconds, isThenable, logger, uuid4 } from '@sentry/utils';
Expand Down Expand Up @@ -438,46 +435,6 @@ export class Hub implements HubInterface {
}
}

/**
* Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
*
* A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
* new child span within the transaction or any span, call the respective `.startChild()` method.
*
* Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
*
* The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
* finished child spans will be sent to Sentry.
*
* @param context Properties of the new `Transaction`.
* @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
* default values). See {@link Options.tracesSampler}.
*
* @returns The transaction which was just started
*
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
*/
public startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction {
const result = this._callExtensionMethod<Transaction>('startTransaction', context, customSamplingContext);

if (DEBUG_BUILD && !result) {
// eslint-disable-next-line deprecation/deprecation
const client = this.getClient();
if (!client) {
logger.warn(
"Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'",
);
} else {
logger.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
Sentry.addTracingExtensions();
Sentry.init({...});
`);
}
}

return result;
}

/**
* @inheritDoc
*
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export {
captureMessage,
close,
flush,
// eslint-disable-next-line deprecation/deprecation
startTransaction,
setContext,
setExtra,
setExtras,
Expand Down
61 changes: 2 additions & 59 deletions packages/core/src/tracing/hubextensions.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@
import type { ClientOptions, CustomSamplingContext, Hub, TransactionContext } from '@sentry/types';
import { getMainCarrier } from '../asyncContext';

import { registerErrorInstrumentation } from './errors';
import { sampleTransaction } from './sampling';
import { Transaction } from './transaction';

/**
* Creates a new transaction and adds a sampling decision if it doesn't yet have one.
*
* The Hub.startTransaction method delegates to this method to do its work, passing the Hub instance in as `this`, as if
* it had been called on the hub directly. Exists as a separate function so that it can be injected into the class as an
* "extension method."
*
* @param this: The Hub starting the transaction
* @param transactionContext: Data used to configure the transaction
* @param CustomSamplingContext: Optional data to be provided to the `tracesSampler` function (if any)
*
* @returns The new transaction
*
* @see {@link Hub.startTransaction}
*/
function _startTransaction(
this: Hub,
transactionContext: TransactionContext,
customSamplingContext?: CustomSamplingContext,
): Transaction {
// eslint-disable-next-line deprecation/deprecation
const client = this.getClient();
const options: Partial<ClientOptions> = (client && client.getOptions()) || {};

// eslint-disable-next-line deprecation/deprecation
let transaction = new Transaction(transactionContext, this);
transaction = sampleTransaction(transaction, options, {
name: transactionContext.name,
parentSampled: transactionContext.parentSampled,
transactionContext,
attributes: {
// eslint-disable-next-line deprecation/deprecation
...transactionContext.data,
...transactionContext.attributes,
},
...customSamplingContext,
});
if (client) {
client.emit('startTransaction', transaction);
client.emit('spanStart', transaction);
}
return transaction;
}

/**
* Adds tracing extensions to the global hub.
* Adds tracing extensions.
* TODO (v8): Do we still need this?? Can we solve this differently?
*/
export function addTracingExtensions(): void {
const carrier = getMainCarrier();
if (!carrier.__SENTRY__) {
return;
}
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
if (!carrier.__SENTRY__.extensions.startTransaction) {
carrier.__SENTRY__.extensions.startTransaction = _startTransaction;
}

registerErrorInstrumentation();
}
4 changes: 2 additions & 2 deletions packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export class SentrySpan implements Span {
private _logMessage?: string;

/**
* You should never call the constructor manually, always use `Sentry.startTransaction()`
* or call `startChild()` on an existing span.
* You should never call the constructor manually, always use `Sentry.startSpan()`
* or other span methods.
* @internal
* @hideconstructor
* @hidden
Expand Down
Loading