Skip to content

Commit 0faac9b

Browse files
committed
ref: Rename setTransaction
1 parent 24e2494 commit 0faac9b

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
- [core] feat: Export `makeMain` (#2665)
1010
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)
1111
- [gatsby] feat: Add @sentry/gatsby package (#2652)
12-
- [apm] feat: Add `Sentry.getSpan` to return the Span on the Scope (#2668)
12+
- [apm] feat: Add `scope.getTransaction` to return a Transaction if it exists (#2668)
13+
- [apm] ref: Depracate `scope.setTransaction` in favor of `scope.setTransactionName` (#2668)
1314
- [core] ref: Rename `whitelistUrls/blacklistUrls` to `allowUrls/denyUrls` (#2671)
1415

1516
## 5.17.0

packages/hub/src/scope.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export class Scope implements ScopeInterface {
4848
/** Severity */
4949
protected _level?: Severity;
5050

51-
/** Transaction */
52-
protected _transaction?: string;
51+
/** Transaction Name */
52+
protected _transactionName?: string;
5353

5454
/** Span */
5555
protected _span?: Span;
@@ -186,12 +186,20 @@ export class Scope implements ScopeInterface {
186186
/**
187187
* @inheritDoc
188188
*/
189-
public setTransaction(transaction?: string): this {
190-
this._transaction = transaction;
189+
public setTransactionName(name?: string): this {
190+
this._transactionName = name;
191191
this._notifyScopeListeners();
192192
return this;
193193
}
194194

195+
/**
196+
* Can be removed in major version.
197+
* @deprecated in favor of {@link this.setTransactionName}
198+
*/
199+
public setTransaction(name?: string): this {
200+
return this.setTransactionName(name);
201+
}
202+
195203
/**
196204
* @inheritDoc
197205
*/
@@ -244,7 +252,7 @@ export class Scope implements ScopeInterface {
244252
newScope._user = scope._user;
245253
newScope._level = scope._level;
246254
newScope._span = scope._span;
247-
newScope._transaction = scope._transaction;
255+
newScope._transactionName = scope._transactionName;
248256
newScope._fingerprint = scope._fingerprint;
249257
newScope._eventProcessors = [...scope._eventProcessors];
250258
}
@@ -307,7 +315,7 @@ export class Scope implements ScopeInterface {
307315
this._user = {};
308316
this._contexts = {};
309317
this._level = undefined;
310-
this._transaction = undefined;
318+
this._transactionName = undefined;
311319
this._fingerprint = undefined;
312320
this._span = undefined;
313321
this._notifyScopeListeners();
@@ -387,8 +395,8 @@ export class Scope implements ScopeInterface {
387395
if (this._level) {
388396
event.level = this._level;
389397
}
390-
if (this._transaction) {
391-
event.transaction = this._transaction;
398+
if (this._transactionName) {
399+
event.transaction = this._transactionName;
392400
}
393401
// We want to set the trace context for normal events only if there isn't already
394402
// a trace context on the event. There is a product feature in place where we link

packages/hub/test/scope.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ describe('Scope', () => {
7373
expect((scope as any)._level).toEqual(Severity.Critical);
7474
});
7575

76-
test('setTransaction', () => {
76+
test('setTransactionName', () => {
7777
const scope = new Scope();
78-
scope.setTransaction('/abc');
79-
expect((scope as any)._transaction).toEqual('/abc');
78+
scope.setTransactionName('/abc');
79+
expect((scope as any)._transactionName).toEqual('/abc');
8080
});
8181

82-
test('setTransaction with no value unsets it', () => {
82+
test('setTransactionName with no value unsets it', () => {
8383
const scope = new Scope();
84-
scope.setTransaction('/abc');
85-
scope.setTransaction();
86-
expect((scope as any)._transaction).toBeUndefined();
84+
scope.setTransactionName('/abc');
85+
scope.setTransactionName();
86+
expect((scope as any)._transactionName).toBeUndefined();
8787
});
8888

8989
test('setContext', () => {
@@ -157,7 +157,7 @@ describe('Scope', () => {
157157
scope.setUser({ id: '1' });
158158
scope.setFingerprint(['abcd']);
159159
scope.setLevel(Severity.Warning);
160-
scope.setTransaction('/abc');
160+
scope.setTransactionName('/abc');
161161
scope.addBreadcrumb({ message: 'test' }, 100);
162162
scope.setContext('os', { id: '1' });
163163
const event: Event = {};
@@ -256,7 +256,7 @@ describe('Scope', () => {
256256
test('scope transaction should have priority over event transaction', () => {
257257
expect.assertions(1);
258258
const scope = new Scope();
259-
scope.setTransaction('/abc');
259+
scope.setTransactionName('/abc');
260260
const event: Event = {};
261261
event.transaction = '/cdf';
262262
return scope.applyToEvent(event).then(processedEvent => {

packages/types/src/scope.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ export interface Scope {
7272
setLevel(level: Severity): this;
7373

7474
/**
75-
* Sets the transaction on the scope for future events.
76-
* @param transaction string This will be converted in a tag in Sentry
75+
* Sets the transaction name on the scope for future events.
7776
*/
78-
setTransaction(transaction?: string): this;
77+
setTransactionName(name?: string): this;
7978

8079
/**
8180
* Sets context data with the given name.

0 commit comments

Comments
 (0)