Skip to content

Commit fcf9bac

Browse files
authored
feat(core): Remove startTransaction export (#11015)
Instead we, for now, inline this directly into core `trace` functions, which is the only place left where we use this.
1 parent 5ccc813 commit fcf9bac

File tree

29 files changed

+86
-397
lines changed

29 files changed

+86
-397
lines changed

dev-packages/browser-integration-tests/suites/public-api/startSpan/basic/subject.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ async function run() {
33
Sentry.startSpan({ name: 'child_span' }, () => {
44
// whatever a user would do here
55
});
6+
7+
// unfinished spans are filtered out
8+
Sentry.startInactiveSpan({ name: 'span_4' });
69
});
710
}
811

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const transaction = Sentry.startTransaction({ name: 'some_transaction' });
1+
const transaction = Sentry.startInactiveSpan({
2+
name: 'some_transaction',
3+
forceTransaction: true,
4+
});
25

36
transaction.setMeasurement('metric.foo', 42, 'ms');
47
transaction.setMeasurement('metric.bar', 1337, 'nanoseconds');

dev-packages/browser-integration-tests/suites/public-api/startTransaction/basic_usage/subject.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/public-api/startTransaction/basic_usage/test.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

dev-packages/browser-integration-tests/suites/public-api/startTransaction/init.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/browser/src/exports.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ export {
4343
makeMain,
4444
setCurrentClient,
4545
Scope,
46-
// eslint-disable-next-line deprecation/deprecation
47-
startTransaction,
4846
continueTrace,
4947
SDK_VERSION,
5048
setContext,

packages/core/src/exports.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {
22
CaptureContext,
33
CheckIn,
4-
CustomSamplingContext,
54
Event,
65
EventHint,
76
EventProcessor,
@@ -13,7 +12,6 @@ import type {
1312
Session,
1413
SessionContext,
1514
SeverityLevel,
16-
TransactionContext,
1715
User,
1816
} from '@sentry/types';
1917
import { GLOBAL_OBJ, isThenable, logger, timestampInSeconds, uuid4 } from '@sentry/utils';
@@ -22,7 +20,6 @@ import { DEFAULT_ENVIRONMENT } from './constants';
2220
import { getClient, getCurrentScope, getIsolationScope } from './currentScopes';
2321
import { DEBUG_BUILD } from './debug-build';
2422
import type { Hub } from './hub';
25-
import { getCurrentHub } from './hub';
2623
import { closeSession, makeSession, updateSession } from './session';
2724
import type { ExclusiveEventHintOrCaptureContext } from './utils/prepareEvent';
2825
import { parseEventHintOrCaptureContext } from './utils/prepareEvent';
@@ -124,36 +121,6 @@ export function setUser(user: User | null): ReturnType<Hub['setUser']> {
124121
getIsolationScope().setUser(user);
125122
}
126123

127-
/**
128-
* Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
129-
*
130-
* A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
131-
* new child span within the transaction or any span, call the respective `.startChild()` method.
132-
*
133-
* Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
134-
*
135-
* The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
136-
* finished child spans will be sent to Sentry.
137-
*
138-
* NOTE: This function should only be used for *manual* instrumentation. Auto-instrumentation should call
139-
* `startTransaction` directly on the hub.
140-
*
141-
* @param context Properties of the new `Transaction`.
142-
* @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
143-
* default values). See {@link Options.tracesSampler}.
144-
*
145-
* @returns The transaction which was just started
146-
*
147-
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
148-
*/
149-
export function startTransaction(
150-
context: TransactionContext,
151-
customSamplingContext?: CustomSamplingContext,
152-
): ReturnType<Hub['startTransaction']> {
153-
// eslint-disable-next-line deprecation/deprecation
154-
return getCurrentHub().startTransaction({ ...context }, customSamplingContext);
155-
}
156-
157124
/**
158125
* Create a cron monitor check in and send it to Sentry.
159126
*

packages/core/src/hub.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
Breadcrumb,
44
BreadcrumbHint,
55
Client,
6-
CustomSamplingContext,
76
Event,
87
EventHint,
98
Extra,
@@ -16,8 +15,6 @@ import type {
1615
Session,
1716
SessionContext,
1817
SeverityLevel,
19-
Transaction,
20-
TransactionContext,
2118
User,
2219
} from '@sentry/types';
2320
import { GLOBAL_OBJ, consoleSandbox, dateTimestampInSeconds, isThenable, logger, uuid4 } from '@sentry/utils';
@@ -438,46 +435,6 @@ export class Hub implements HubInterface {
438435
}
439436
}
440437

441-
/**
442-
* Starts a new `Transaction` and returns it. This is the entry point to manual tracing instrumentation.
443-
*
444-
* A tree structure can be built by adding child spans to the transaction, and child spans to other spans. To start a
445-
* new child span within the transaction or any span, call the respective `.startChild()` method.
446-
*
447-
* Every child span must be finished before the transaction is finished, otherwise the unfinished spans are discarded.
448-
*
449-
* The transaction must be finished with a call to its `.end()` method, at which point the transaction with all its
450-
* finished child spans will be sent to Sentry.
451-
*
452-
* @param context Properties of the new `Transaction`.
453-
* @param customSamplingContext Information given to the transaction sampling function (along with context-dependent
454-
* default values). See {@link Options.tracesSampler}.
455-
*
456-
* @returns The transaction which was just started
457-
*
458-
* @deprecated Use `startSpan()`, `startSpanManual()` or `startInactiveSpan()` instead.
459-
*/
460-
public startTransaction(context: TransactionContext, customSamplingContext?: CustomSamplingContext): Transaction {
461-
const result = this._callExtensionMethod<Transaction>('startTransaction', context, customSamplingContext);
462-
463-
if (DEBUG_BUILD && !result) {
464-
// eslint-disable-next-line deprecation/deprecation
465-
const client = this.getClient();
466-
if (!client) {
467-
logger.warn(
468-
"Tracing extension 'startTransaction' is missing. You should 'init' the SDK before calling 'startTransaction'",
469-
);
470-
} else {
471-
logger.warn(`Tracing extension 'startTransaction' has not been added. Call 'addTracingExtensions' before calling 'init':
472-
Sentry.addTracingExtensions();
473-
Sentry.init({...});
474-
`);
475-
}
476-
}
477-
478-
return result;
479-
}
480-
481438
/**
482439
* @inheritDoc
483440
*

packages/core/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export {
1717
captureMessage,
1818
close,
1919
flush,
20-
// eslint-disable-next-line deprecation/deprecation
21-
startTransaction,
2220
setContext,
2321
setExtra,
2422
setExtras,
Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,9 @@
1-
import type { ClientOptions, CustomSamplingContext, Hub, TransactionContext } from '@sentry/types';
2-
import { getMainCarrier } from '../asyncContext';
3-
41
import { registerErrorInstrumentation } from './errors';
5-
import { sampleTransaction } from './sampling';
6-
import { Transaction } from './transaction';
72

83
/**
9-
* Creates a new transaction and adds a sampling decision if it doesn't yet have one.
10-
*
11-
* The Hub.startTransaction method delegates to this method to do its work, passing the Hub instance in as `this`, as if
12-
* it had been called on the hub directly. Exists as a separate function so that it can be injected into the class as an
13-
* "extension method."
14-
*
15-
* @param this: The Hub starting the transaction
16-
* @param transactionContext: Data used to configure the transaction
17-
* @param CustomSamplingContext: Optional data to be provided to the `tracesSampler` function (if any)
18-
*
19-
* @returns The new transaction
20-
*
21-
* @see {@link Hub.startTransaction}
22-
*/
23-
function _startTransaction(
24-
this: Hub,
25-
transactionContext: TransactionContext,
26-
customSamplingContext?: CustomSamplingContext,
27-
): Transaction {
28-
// eslint-disable-next-line deprecation/deprecation
29-
const client = this.getClient();
30-
const options: Partial<ClientOptions> = (client && client.getOptions()) || {};
31-
32-
// eslint-disable-next-line deprecation/deprecation
33-
let transaction = new Transaction(transactionContext, this);
34-
transaction = sampleTransaction(transaction, options, {
35-
name: transactionContext.name,
36-
parentSampled: transactionContext.parentSampled,
37-
transactionContext,
38-
attributes: {
39-
// eslint-disable-next-line deprecation/deprecation
40-
...transactionContext.data,
41-
...transactionContext.attributes,
42-
},
43-
...customSamplingContext,
44-
});
45-
if (client) {
46-
client.emit('startTransaction', transaction);
47-
client.emit('spanStart', transaction);
48-
}
49-
return transaction;
50-
}
51-
52-
/**
53-
* Adds tracing extensions to the global hub.
4+
* Adds tracing extensions.
5+
* TODO (v8): Do we still need this?? Can we solve this differently?
546
*/
557
export function addTracingExtensions(): void {
56-
const carrier = getMainCarrier();
57-
if (!carrier.__SENTRY__) {
58-
return;
59-
}
60-
carrier.__SENTRY__.extensions = carrier.__SENTRY__.extensions || {};
61-
if (!carrier.__SENTRY__.extensions.startTransaction) {
62-
carrier.__SENTRY__.extensions.startTransaction = _startTransaction;
63-
}
64-
658
registerErrorInstrumentation();
669
}

packages/core/src/tracing/sentrySpan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export class SentrySpan implements Span {
6060
private _logMessage?: string;
6161

6262
/**
63-
* You should never call the constructor manually, always use `Sentry.startTransaction()`
64-
* or call `startChild()` on an existing span.
63+
* You should never call the constructor manually, always use `Sentry.startSpan()`
64+
* or other span methods.
6565
* @internal
6666
* @hideconstructor
6767
* @hidden

0 commit comments

Comments
 (0)