Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5728da34cd4146a116d0feeb80d09a9a3602b08c6524e24940faac9bc327c03045fd882d7ccba67791975ee0fe3e0273adebd3680fd23147File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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 { | ||
Contributor 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| * @deprecated in favor of {@link this.setTransactionName} | ||
| */ | ||
| public setTransaction(name?: string): this { | ||
Contributor 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,6 +2,7 @@ import { Breadcrumb } from './breadcrumb'; | ||
| import { EventProcessor } from './eventprocessor'; | ||
| import { Severity } from './severity'; | ||
| import { Span } from './span'; | ||
| import { Transaction } from './transaction'; | ||
| import { User } from './user'; | ||
| /** JSDocs */ | ||
| @@ -71,10 +72,9 @@ export interface Scope { | ||
| setLevel(level: Severity): this; | ||
| /** | ||
| * Sets the transaction on the scope for future events. | ||
| * @param transaction string This will be converted in a tag in Sentry | ||
| * Sets the transaction name on the scope for future events. | ||
| */ | ||
| setTransaction(transaction?: string): this; | ||
| setTransactionName(name?: string): this; | ||
| /** | ||
| * Sets context data with the given name. | ||
| @@ -89,6 +89,16 @@ export interface Scope { | ||
| */ | ||
| setSpan(span?: Span): this; | ||
| /** | ||
| * Returns the `Span` if there is one | ||
| */ | ||
| getSpan(): Span | undefined; | ||
HazAT marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /** | ||
| * Returns the `Transaction` if there is one | ||
| */ | ||
| getTransaction(): Transaction | undefined; | ||
| /** | ||
| * Updates the scope with provided data. Can work in three variations: | ||
| * - plain object containing updatable attributes | ||
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