Skip to content

Commit bd4abef

Browse files
authored
feat: Add maxTransactionTimeout + set transaction name (#2399)
* feat: Add maxTransactionTimeout * meta: fix CI * ci: fix * feat: Always set transaction on the scope + span * fix: symlink * meta: Changelog
1 parent 9a54650 commit bd4abef

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

.travis.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ branches:
88
- /^major\/.+$/
99
- 4.x
1010

11-
install: true
12-
sudo: required
11+
install: yarn
12+
os: linux
1313

1414
language: node_js
1515
dist: bionic
@@ -19,9 +19,6 @@ cache:
1919
directories:
2020
- node_modules
2121

22-
matrix:
23-
fast_finish: true
24-
2522
stages:
2623
- Test
2724
- Deploy

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- [apm] fix: Add new option to `Tracing` `maxTransactionTimeout` determines the max length of a transaction
6+
- [hub] ref: Always also set transaction name on the top span in the scope
7+
58
## 5.11.1
69

710
- [apm] feat: Add build bundle including @sentry/browser + @sentry/apm

packages/apm/src/integrations/tracing.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import {
55
isMatchingPattern,
66
logger,
77
supportsNativeFetch,
8+
timestampWithMs,
89
} from '@sentry/utils';
910

11+
import { Span as SpanClass } from '../span';
12+
1013
/**
1114
* Options for Tracing integration
1215
*/
@@ -60,6 +63,15 @@ interface TracingOptions {
6063
* Default: 1
6164
*/
6265
tracesSampleRate: number;
66+
67+
/**
68+
* The maximum time a transaction can be before it will be dropped. This is for some edge cases where a browser
69+
* completely freezes the JS state and picks it up later. So after this timeout, the SDK will not send the event.
70+
* Time is in ms.
71+
*
72+
* Default: 120000
73+
*/
74+
maxTransactionTimeout: number;
6375
}
6476

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

250263
/**
251264
* Update transaction
265+
* @deprecated
252266
*/
253267
public static updateTransactionName(name: string): void {
254-
const activeTransaction = Tracing._activeTransaction;
255-
if (!activeTransaction) {
256-
return;
268+
// const activeTransaction = Tracing._activeTransaction;
269+
// if (!activeTransaction) {
270+
// return;
271+
// }
272+
const _getCurrentHub = Tracing._getCurrentHub;
273+
if (_getCurrentHub) {
274+
const hub = _getCurrentHub();
275+
if (hub) {
276+
hub.configureScope(scope => {
277+
scope.setTransaction(name);
278+
});
279+
}
257280
}
258281
// TODO
259-
(activeTransaction as any).transaction = name;
282+
// (activeTransaction as any).transaction = name;
260283
}
261284

262285
/**
263286
* Finshes the current active transaction
264287
*/
265288
public static finishIdleTransaction(): void {
266-
const active = Tracing._activeTransaction;
289+
const active = Tracing._activeTransaction as SpanClass;
267290
if (active) {
268-
// true = use timestamp of last span
269-
active.finish(true);
291+
if (timestampWithMs() > active.startTimestamp + Tracing.options.maxTransactionTimeout) {
292+
// If we reached the max timeout of the transaction, we will just not finish it and therefore discard it.
293+
Tracing._activeTransaction = undefined;
294+
} else {
295+
// true = use timestamp of last span
296+
active.finish(true);
297+
}
270298
}
271299
}
272300

packages/hub/src/scope.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ export class Scope implements ScopeInterface {
185185
*/
186186
public setTransaction(transaction?: string): this {
187187
this._transaction = transaction;
188+
if (this._span) {
189+
(this._span as any).transaction = transaction;
190+
}
188191
this._notifyScopeListeners();
189192
return this;
190193
}

0 commit comments

Comments
 (0)