Skip to content
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

feat: Add span creators to @sentry/tracing package #2736

Merged

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Jul 9, 2020

Continuing from #2723, This PR adds span creators to @sentry/tracing.

During the integration setup, we add three new functions to register this functionality.

// From browser/errors.ts
// If an error occurs, adds span status cancelled
// should this be default behaviour?
registerErrorInstrumentation();

// From browser/backgroundtab.ts
// If document becomes hidden. cancels and ends the active transaction.
if (markBackgroundTransactions) {
  registerBackgroundTabDetection();
}

// From browser/request.ts
// Adds spans for fetch and XHR requests.
registerRequestInstrumentation({ traceFetch, traceXHR, tracingOrigins, shouldCreateSpanForRequest });

We also use a separate MetricsInstrumentation class (in browser/metrics.ts) to track metrics data. That way we can easily swap it out if we want to expose the option in the future.

transaction-view-tracing

I didn't do full tests due to the large size of this PR, but I figured it was something we can get back to.

@AbhiPrasad AbhiPrasad requested a review from HazAT July 10, 2020 16:35
@AbhiPrasad AbhiPrasad changed the title feat: Add span creators to @sentry/trace feat: Add span creators to @sentry/tracing package Jul 10, 2020
@AbhiPrasad AbhiPrasad marked this pull request as ready for review July 10, 2020 16:36
@@ -96,13 +136,40 @@ export class BrowserTracing implements Integration {
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
this._getCurrentHub = getCurrentHub;

const { routingInstrumentation, startTransactionOnLocationChange, startTransactionOnPageLoad } = this.options;
if (this._emitOptionsWarning) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_emitOptionsWarning is based on tracingOrigins only, which we have access to here. Not sure if it's necessary to store it in the class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will refactor the logic here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this is here because we cannot call it in the constructor, and we want to warn the user if they haven't manually set the _option themselves.

Comment on lines 200 to 202
idleTransaction.registerBeforeFinishCallback(transaction => {
this._metrics.addPerformanceEntires(transaction);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to unify it with L199 syntax? (not sure about this context here, would have to verify it. Or we can make L199 accept arrow function instead to make it more "obvious" instead of curried function, your call

Suggested change
idleTransaction.registerBeforeFinishCallback(transaction => {
this._metrics.addPerformanceEntires(transaction);
});
idleTransaction.registerBeforeFinishCallback(this._metrics.addPerformanceEntires);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this issue here was with the this context.

I refactored to something like this:

idleTransaction.registerBeforeFinishCallback((transaction, endTimestamp) => {
  this._metrics.addPerformanceEntires(transaction);
  adjustTransactionDuration(secToMs(maxTransactionDuration), transaction, endTimestamp);
});


if (global.document) {
// tslint:disable-next-line: prefer-for-of
for (let i = 0; i < document.scripts.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to ignore prefer-for-of?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied the implementation from what was there before. I assume it is because we want the performance benefit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remember tbh :D

Copy link
Contributor

@kamilogorek kamilogorek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback after first pass. Your turn @HazAT

packages/tracing/src/browser/browsertracing.ts Outdated Show resolved Hide resolved
packages/tracing/src/browser/request.ts Outdated Show resolved Hide resolved
k-fish added a commit that referenced this pull request Jul 13, 2020
This will add the `@sentry/ember` package. This will provide an Ember addon that fits into the Ember ecosystem and will in the future offer custom framework specific functionality. Once
#2736 and other tracing PR's have landed, we can add Ember specific performance instrumentation.
k-fish added a commit that referenced this pull request Jul 13, 2020
This will add the `@sentry/ember` package. This will provide an Ember addon that fits into the Ember ecosystem and will in the future offer custom framework specific functionality. Once
#2736 and other tracing PR's have landed, we can add Ember specific performance instrumentation.
k-fish added a commit that referenced this pull request Jul 13, 2020
This will add the `@sentry/ember` package. This will provide an Ember addon that fits into the Ember ecosystem and will in the future offer custom framework specific functionality. Once
#2736 and other tracing PR's have landed, we can add Ember specific performance instrumentation.
@k-fish k-fish mentioned this pull request Jul 13, 2020
5 tasks
@AbhiPrasad AbhiPrasad merged commit 3454cf4 into abhi/ref/add-sentry-tracing Jul 14, 2020
@AbhiPrasad AbhiPrasad deleted the abhi/feat/tracing-span-creators branch July 14, 2020 11:44
AbhiPrasad added a commit that referenced this pull request Jul 17, 2020
* feat: Create IdleTransaction class (#2720)

* feat: Add BrowserTracing integration (#2723)

* feat: Add span creators to @sentry/tracing package (#2736)

* ref: Convert React and Vue Tracing to use active transaction (#2741)

* build: generate tracing bundles

* fix: Remove circular dependency between span and transaction

* ref: Add side effects true to tracing

* build: Only include @sentry/browser for bundle

* fix: Make sure vue and react are backwards compatible with @sentry/apm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants