-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add scope.getTransaction, rename scope.setTransaction -> setTransactionName #2668
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
Changes from all commits
5728da3
4cd4146
a116d0f
eeb80d0
9a9a360
2b08c65
24e2494
0faac9b
c327c03
045fd88
2d7ccba
6779197
5ee0fe3
e0273ad
ebd3680
fd23147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
ScopeContext, | ||
Severity, | ||
Span, | ||
Transaction, | ||
User, | ||
} from '@sentry/types'; | ||
import { getGlobalObject, isPlainObject, isThenable, SyncPromise, timestampWithMs } from '@sentry/utils'; | ||
|
@@ -47,8 +48,8 @@ export class Scope implements ScopeInterface { | |
/** Severity */ | ||
protected _level?: Severity; | ||
|
||
/** Transaction */ | ||
protected _transaction?: string; | ||
/** Transaction Name */ | ||
protected _transactionName?: string; | ||
|
||
/** Span */ | ||
protected _span?: Span; | ||
|
@@ -185,12 +186,20 @@ export class Scope implements ScopeInterface { | |
/** | ||
* @inheritDoc | ||
*/ | ||
public setTransaction(transaction?: string): this { | ||
this._transaction = transaction; | ||
public setTransactionName(name?: string): this { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. offtopic: This whole transaction thing will be very confused (and possibly broken) if someone uses |
||
this._transactionName = name; | ||
this._notifyScopeListeners(); | ||
return this; | ||
} | ||
|
||
/** | ||
* Can be removed in major version. | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @deprecated in favor of {@link this.setTransactionName} | ||
*/ | ||
public setTransaction(name?: string): this { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kilobytes, kilobytes 😶 |
||
return this.setTransactionName(name); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
|
@@ -210,13 +219,23 @@ export class Scope implements ScopeInterface { | |
} | ||
|
||
/** | ||
* Internal getter for Span, used in Hub. | ||
* @hidden | ||
* @inheritDoc | ||
*/ | ||
public getSpan(): Span | undefined { | ||
return this._span; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public getTransaction(): Transaction | undefined { | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const span = this.getSpan() as Span & { spanRecorder: { spans: Span[] } }; | ||
if (span && span.spanRecorder && span.spanRecorder.spans[0]) { | ||
return span.spanRecorder.spans[0] as Transaction; | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Inherit values from the parent scope. | ||
* @param scope to clone. | ||
|
@@ -231,7 +250,7 @@ export class Scope implements ScopeInterface { | |
newScope._user = scope._user; | ||
newScope._level = scope._level; | ||
newScope._span = scope._span; | ||
newScope._transaction = scope._transaction; | ||
newScope._transactionName = scope._transactionName; | ||
newScope._fingerprint = scope._fingerprint; | ||
newScope._eventProcessors = [...scope._eventProcessors]; | ||
} | ||
|
@@ -294,7 +313,7 @@ export class Scope implements ScopeInterface { | |
this._user = {}; | ||
this._contexts = {}; | ||
this._level = undefined; | ||
this._transaction = undefined; | ||
this._transactionName = undefined; | ||
this._fingerprint = undefined; | ||
this._span = undefined; | ||
this._notifyScopeListeners(); | ||
|
@@ -374,8 +393,8 @@ export class Scope implements ScopeInterface { | |
if (this._level) { | ||
event.level = this._level; | ||
} | ||
if (this._transaction) { | ||
event.transaction = this._transaction; | ||
if (this._transactionName) { | ||
event.transaction = this._transactionName; | ||
} | ||
// We want to set the trace context for normal events only if there isn't already | ||
// a trace context on the event. There is a product feature in place where we link | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are not technically "correct". defined/undefined test should be moved to
scope.test.ts
, as this functionality is owned by theScope
, and tests below should only assert that a given method was called on the scope.expect(s.getTransaction).toBeCalled()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to
scope.test.ts