Skip to content

Commit

Permalink
feat: Add maxTransactionTimeout + set transaction name (#2399)
Browse files Browse the repository at this point in the history
* feat: Add maxTransactionTimeout

* meta: fix CI

* ci: fix

* feat: Always set transaction on the scope + span

* fix: symlink

* meta: Changelog
  • Loading branch information
HazAT committed Jan 29, 2020
1 parent 9a54650 commit bd4abef
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ branches:
- /^major\/.+$/
- 4.x

install: true
sudo: required
install: yarn
os: linux

language: node_js
dist: bionic
Expand All @@ -19,9 +19,6 @@ cache:
directories:
- node_modules

matrix:
fast_finish: true

stages:
- Test
- Deploy
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- [apm] fix: Add new option to `Tracing` `maxTransactionTimeout` determines the max length of a transaction
- [hub] ref: Always also set transaction name on the top span in the scope

## 5.11.1

- [apm] feat: Add build bundle including @sentry/browser + @sentry/apm
Expand Down
42 changes: 35 additions & 7 deletions packages/apm/src/integrations/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import {
isMatchingPattern,
logger,
supportsNativeFetch,
timestampWithMs,
} from '@sentry/utils';

import { Span as SpanClass } from '../span';

/**
* Options for Tracing integration
*/
Expand Down Expand Up @@ -60,6 +63,15 @@ interface TracingOptions {
* Default: 1
*/
tracesSampleRate: number;

/**
* The maximum time a transaction can be before it will be dropped. This is for some edge cases where a browser
* completely freezes the JS state and picks it up later. So after this timeout, the SDK will not send the event.
* Time is in ms.
*
* Default: 120000
*/
maxTransactionTimeout: number;
}

/** JSDoc */
Expand Down Expand Up @@ -114,6 +126,7 @@ export class Tracing implements Integration {
const defaultTracingOrigins = ['localhost', /^\//];
const defaults = {
idleTimeout: 500,
maxTransactionTimeout: 120000,
shouldCreateSpanForRequest(url: string): boolean {
const origins = (_options && _options.tracingOrigins) || defaultTracingOrigins;
return (
Expand Down Expand Up @@ -249,24 +262,39 @@ export class Tracing implements Integration {

/**
* Update transaction
* @deprecated
*/
public static updateTransactionName(name: string): void {
const activeTransaction = Tracing._activeTransaction;
if (!activeTransaction) {
return;
// const activeTransaction = Tracing._activeTransaction;
// if (!activeTransaction) {
// return;
// }
const _getCurrentHub = Tracing._getCurrentHub;
if (_getCurrentHub) {
const hub = _getCurrentHub();
if (hub) {
hub.configureScope(scope => {
scope.setTransaction(name);
});
}
}
// TODO
(activeTransaction as any).transaction = name;
// (activeTransaction as any).transaction = name;
}

/**
* Finshes the current active transaction
*/
public static finishIdleTransaction(): void {
const active = Tracing._activeTransaction;
const active = Tracing._activeTransaction as SpanClass;
if (active) {
// true = use timestamp of last span
active.finish(true);
if (timestampWithMs() > active.startTimestamp + Tracing.options.maxTransactionTimeout) {
// If we reached the max timeout of the transaction, we will just not finish it and therefore discard it.
Tracing._activeTransaction = undefined;
} else {
// true = use timestamp of last span
active.finish(true);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/hub/src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ export class Scope implements ScopeInterface {
*/
public setTransaction(transaction?: string): this {
this._transaction = transaction;
if (this._span) {
(this._span as any).transaction = transaction;
}
this._notifyScopeListeners();
return this;
}
Expand Down

0 comments on commit bd4abef

Please sign in to comment.