Skip to content

Commit 47a0a45

Browse files
HazATkamilogorek
andauthored
Ref/apm transaction timeout (getsentry#2412)
* ref: Correct check for transaction length * meta: Travis bumps, Readme and changelog * ref: Rename option, Make time in seconds * fix: Wording * Update packages/apm/src/integrations/tracing.ts Co-Authored-By: Kamil Ogórek <kamil.ogorek@gmail.com>
1 parent cee5772 commit 47a0a45

File tree

9 files changed

+26
-126
lines changed

9 files changed

+26
-126
lines changed

.travis.yml

+2-26
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ branches:
66
- master
77
- /^release\/.+$/
88
- /^major\/.+$/
9-
- 4.x
109

11-
install: yarn
10+
install: yarn --ignore-engines
1211
os: linux
1312

1413
language: node_js
@@ -39,32 +38,9 @@ jobs:
3938
- name: '@sentry/browser - browserstack integration tests'
4039
node_js: '10'
4140
script: scripts/browser-integration.sh
42-
- name: 'raven-node [node v4]'
43-
if: branch = 4.x
44-
node_js: '4'
45-
script: scripts/raven-node.sh
46-
- name: 'raven-node [node v6]'
47-
if: branch = 4.x
48-
node_js: '6'
49-
script: scripts/raven-node.sh
50-
- name: 'raven-node [node v8]'
51-
if: branch = 4.x
52-
node_js: '8'
53-
script: scripts/raven-node.sh
54-
- name: 'raven-node [node v10]'
55-
if: branch = 4.x
56-
node_js: '10'
57-
script: scripts/raven-node.sh
58-
- name: 'raven-js - unit and integration tests'
59-
if: branch = 4.x
60-
node_js: '8'
61-
addons:
62-
chrome: stable
63-
firefox: latest
64-
script: scripts/raven-js.sh
6541
- stage: Deploy
6642
name: '@sentry/packages - pack and zeus upload'
67-
node_js: '10'
43+
node_js: '12'
6844
script: scripts/pack-and-upload.sh || [[ ! "$TRAVIS_BRANCH" =~ ^release/ ]]
6945

7046
notifications:

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 5.12.2
6+
7+
- [apm] ref: Check if Tracing integration is enabled before dropping transaction
8+
59
## 5.12.1
610

711
- [apm] ref: If `maxTransactionTimeout` = `0` there is no timeout

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ package. Please refer to the README and instructions of those SDKs for more deta
3737
including integrations for React, Angular, Ember, Vue and Backbone
3838
- [`@sentry/node`](https://github.com/getsentry/sentry-javascript/tree/master/packages/node): SDK for Node, including
3939
integrations for Express, Koa, Loopback, Sails and Connect
40+
- [`@sentry/react-native`](https://github.com/getsentry/sentry-react-native): SDK for React Native with support for native crashes
4041
- [`@sentry/integrations`](https://github.com/getsentry/sentry-javascript/tree/master/packages/integrations): Pluggable
4142
integrations that can be used to enhance JS SDKs
4243
- [`@sentry/electron`](https://github.com/getsentry/sentry-electron): SDK for Electron with support for native crashes
@@ -77,7 +78,8 @@ Besides the high-level SDKs, this repository contains shared packages, helpers a
7778
development. If you're thinking about contributing to or creating a JavaScript-based SDK, have a look at the resources
7879
below:
7980

80-
81+
- [`@sentry/apm`](https://github.com/getsentry/sentry-javascript/tree/master/packages/apm): Provides Integrations and
82+
extensions for APM
8183
- [`@sentry/hub`](https://github.com/getsentry/sentry-javascript/tree/master/packages/hub): Global state management of
8284
SDKs
8385
- [`@sentry/minimal`](https://github.com/getsentry/sentry-javascript/tree/master/packages/minimal): Minimal SDK for

packages/apm/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
# Sentry APM Extensions
99

10-
# TODO
11-
1210
[![npm version](https://img.shields.io/npm/v/@sentry/apm.svg)](https://www.npmjs.com/package/@sentry/apm)
1311
[![npm dm](https://img.shields.io/npm/dm/@sentry/apm.svg)](https://www.npmjs.com/package/@sentry/apm)
1412
[![npm dt](https://img.shields.io/npm/dt/@sentry/apm.svg)](https://www.npmjs.com/package/@sentry/apm)

packages/apm/src/integrations/tracing.ts

+17-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
isMatchingPattern,
66
logger,
77
supportsNativeFetch,
8-
timestampWithMs,
98
} from '@sentry/utils';
109

1110
import { Span as SpanClass } from '../span';
@@ -43,6 +42,7 @@ interface TracingOptions {
4342
/**
4443
* The time to wait in ms until the transaction will be finished. The transaction will use the end timestamp of
4544
* the last finished span as the endtime for the transaction.
45+
* Time is in ms.
4646
*
4747
* Default: 500
4848
*/
@@ -65,14 +65,15 @@ interface TracingOptions {
6565
tracesSampleRate: number;
6666

6767
/**
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-
* If you want to have an unlimited timeout set it to 0.
71-
* Time is in ms.
68+
* The maximum duration of a transaction before it will be discarded. This is for some edge cases where a browser
69+
* completely freezes the JS state and picks it up later (background tabs).
70+
* So after this duration, the SDK will not send the event.
71+
* If you want to have an unlimited duration set it to 0.
72+
* Time is in seconds.
7273
*
73-
* Default: 600000 = 10min
74+
* Default: 600
7475
*/
75-
maxTransactionTimeout: number;
76+
maxTransactionDuration: number;
7677
}
7778

7879
/** JSDoc */
@@ -127,7 +128,7 @@ export class Tracing implements Integration {
127128
const defaultTracingOrigins = ['localhost', /^\//];
128129
const defaults = {
129130
idleTimeout: 500,
130-
maxTransactionTimeout: 600000,
131+
maxTransactionDuration: 600,
131132
shouldCreateSpanForRequest(url: string): boolean {
132133
const origins = (_options && _options.tracingOrigins) || defaultTracingOrigins;
133134
return (
@@ -194,18 +195,21 @@ export class Tracing implements Integration {
194195
});
195196
}
196197

197-
// This EventProcessor makes sure that we never send an transaction that is older than maxTransactionTimeout
198+
// This EventProcessor makes sure that the transaction is not longer than maxTransactionDuration
198199
addGlobalEventProcessor((event: Event) => {
199200
const self = getCurrentHub().getIntegration(Tracing);
200201
if (!self) {
201202
return event;
202203
}
203204

204205
if (
206+
Tracing.options.maxTransactionDuration !== 0 &&
207+
Tracing._isEnabled() &&
205208
event.type === 'transaction' &&
206209
event.timestamp &&
207-
Tracing.options.maxTransactionTimeout !== 0 &&
208-
timestampWithMs() > event.timestamp + Tracing.options.maxTransactionTimeout
210+
event.start_timestamp &&
211+
(event.timestamp - event.start_timestamp > Tracing.options.maxTransactionDuration ||
212+
event.timestamp - event.start_timestamp < 0)
209213
) {
210214
return null;
211215
}
@@ -302,16 +306,8 @@ export class Tracing implements Integration {
302306
public static finishIdleTransaction(): void {
303307
const active = Tracing._activeTransaction as SpanClass;
304308
if (active) {
305-
if (
306-
Tracing.options.maxTransactionTimeout !== 0 &&
307-
timestampWithMs() > active.startTimestamp + Tracing.options.maxTransactionTimeout
308-
) {
309-
// If we reached the max timeout of the transaction, we will just not finish it and therefore discard it.
310-
Tracing._activeTransaction = undefined;
311-
} else {
312-
// true = use timestamp of last span
313-
active.finish(true);
314-
}
309+
// true = use timestamp of last span
310+
active.finish(true);
315311
}
316312
}
317313

scripts/detect-raven.sh

-41
This file was deleted.

scripts/raven-js-saucelabs.sh

-11
This file was deleted.

scripts/raven-js.sh

-12
This file was deleted.

scripts/raven-node.sh

-12
This file was deleted.

0 commit comments

Comments
 (0)