@sentry/tracing
Advanced tools
Comparing version 6.18.0 to 6.18.1-beta.0
@@ -23,3 +23,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
activeTransaction.setTag('visibilitychange', 'document.hidden'); | ||
activeTransaction.setTag(constants_1.FINISH_REASON_TAG, constants_1.IDLE_TRANSACTION_FINISH_REASONS[2]); | ||
activeTransaction.finishReason = constants_1.IDLE_TRANSACTION_FINISH_REASONS[2]; /* 'documentHidden' */ | ||
activeTransaction.finish(); | ||
@@ -26,0 +26,0 @@ } |
@@ -10,2 +10,3 @@ import { Hub } from '@sentry/hub'; | ||
* the last finished span as the endtime for the transaction. | ||
* | ||
* Time is in ms. | ||
@@ -17,2 +18,11 @@ * | ||
/** | ||
* The max duration for a transaction. If a transaction duration hits the `finalTimeout` value, it | ||
* will be finished. | ||
* | ||
* Time is in ms. | ||
* | ||
* Default: 30000 | ||
*/ | ||
finalTimeout: number; | ||
/** | ||
* Flag to enable/disable creation of `navigation` transaction on history changes. | ||
@@ -19,0 +29,0 @@ * |
@@ -12,3 +12,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600; | ||
var DEFAULT_BROWSER_TRACING_OPTIONS = tslib_1.__assign({ idleTimeout: idletransaction_1.DEFAULT_IDLE_TIMEOUT, markBackgroundTransactions: true, maxTransactionDuration: exports.DEFAULT_MAX_TRANSACTION_DURATION_SECONDS, routingInstrumentation: router_1.instrumentRoutingWithDefaults, startTransactionOnLocationChange: true, startTransactionOnPageLoad: true }, request_1.defaultRequestInstrumentationOptions); | ||
var DEFAULT_BROWSER_TRACING_OPTIONS = tslib_1.__assign({ idleTimeout: idletransaction_1.DEFAULT_IDLE_TIMEOUT, finalTimeout: idletransaction_1.DEFAULT_FINAL_TIMEOUT, markBackgroundTransactions: true, maxTransactionDuration: exports.DEFAULT_MAX_TRANSACTION_DURATION_SECONDS, routingInstrumentation: router_1.instrumentRoutingWithDefaults, startTransactionOnLocationChange: true, startTransactionOnPageLoad: true }, request_1.defaultRequestInstrumentationOptions); | ||
/** | ||
@@ -15,0 +15,0 @@ * The Browser Tracing integration automatically instruments browser pageload/navigation |
@@ -1,3 +0,3 @@ | ||
export declare const FINISH_REASON_TAG = "finishReason"; | ||
export declare const IDLE_TRANSACTION_FINISH_REASONS: readonly ["heartbeatFailed", "idleTimeout", "documentHidden"]; | ||
export declare const FINISH_REASON_TAG: "finishReason"; | ||
export declare const IDLE_TRANSACTION_FINISH_REASONS: readonly ["heartbeatFailed", "idleTimeout", "documentHidden", "finalTimeout", "externalFinish"]; | ||
//# sourceMappingURL=constants.d.ts.map |
@@ -5,3 +5,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FINISH_REASON_TAG = 'finishReason'; | ||
exports.IDLE_TRANSACTION_FINISH_REASONS = ['heartbeatFailed', 'idleTimeout', 'documentHidden']; | ||
exports.IDLE_TRANSACTION_FINISH_REASONS = [ | ||
'heartbeatFailed', | ||
'idleTimeout', | ||
'documentHidden', | ||
'finalTimeout', | ||
'externalFinish', | ||
]; | ||
//# sourceMappingURL=constants.js.map |
import { Hub } from '@sentry/hub'; | ||
import { TransactionContext } from '@sentry/types'; | ||
import { IDLE_TRANSACTION_FINISH_REASONS } from './constants'; | ||
import { Span, SpanRecorder } from './span'; | ||
import { Transaction } from './transaction'; | ||
export declare const DEFAULT_IDLE_TIMEOUT = 1000; | ||
export declare const DEFAULT_FINAL_TIMEOUT = 30000; | ||
export declare const HEARTBEAT_INTERVAL = 5000; | ||
@@ -31,6 +33,24 @@ /** | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
private readonly _idleTimeout; | ||
private readonly _onScope; | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
private readonly _finalTimeout; | ||
activities: Record<string, boolean>; | ||
/** | ||
* | ||
* Defaults to `externalFinish`, which means transaction.finish() was called outside of the idle transaction (for example, | ||
* by a navigation transaction ending the previous pageload/navigation in some routing instrumentation). | ||
* @default 'externalFinish' | ||
*/ | ||
finishReason: typeof IDLE_TRANSACTION_FINISH_REASONS[number]; | ||
private _prevHeartbeatString; | ||
@@ -44,3 +64,3 @@ private _heartbeatCounter; | ||
*/ | ||
private _initTimeout; | ||
private _idleTimeoutID; | ||
constructor(transactionContext: TransactionContext, _idleHub?: Hub | undefined, | ||
@@ -50,4 +70,15 @@ /** | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
_idleTimeout?: number, _onScope?: boolean); | ||
_idleTimeout?: number, _onScope?: boolean, | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
_finalTimeout?: number); | ||
/** {@inheritDoc} */ | ||
@@ -68,2 +99,10 @@ finish(endTimestamp?: number): string | undefined; | ||
/** | ||
* Cancels the existing idletimeout, if there is one | ||
*/ | ||
private _cancelIdleTimeout; | ||
/** | ||
* Creates an idletimeout | ||
*/ | ||
private _startIdleTimeout; | ||
/** | ||
* Start tracking a specific activity. | ||
@@ -70,0 +109,0 @@ * @param spanId The span id that represents the activity |
@@ -8,3 +8,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULT_IDLE_TIMEOUT = 1000; | ||
exports.DEFAULT_FINAL_TIMEOUT = 30000; | ||
exports.HEARTBEAT_INTERVAL = 5000; | ||
var global = utils_1.getGlobalObject(); | ||
/** | ||
@@ -57,8 +59,20 @@ * @inheritDoc | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
_idleTimeout, | ||
// Whether or not the transaction should put itself on the scope when it starts and pop itself off when it ends | ||
_onScope) { | ||
_onScope, | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
_finalTimeout) { | ||
if (_idleTimeout === void 0) { _idleTimeout = exports.DEFAULT_IDLE_TIMEOUT; } | ||
if (_onScope === void 0) { _onScope = false; } | ||
if (_finalTimeout === void 0) { _finalTimeout = exports.DEFAULT_FINAL_TIMEOUT; } | ||
var _this = _super.call(this, transactionContext, _idleHub) || this; | ||
@@ -68,4 +82,12 @@ _this._idleHub = _idleHub; | ||
_this._onScope = _onScope; | ||
_this._finalTimeout = _finalTimeout; | ||
// Activities store a list of active spans | ||
_this.activities = {}; | ||
/** | ||
* | ||
* Defaults to `externalFinish`, which means transaction.finish() was called outside of the idle transaction (for example, | ||
* by a navigation transaction ending the previous pageload/navigation in some routing instrumentation). | ||
* @default 'externalFinish' | ||
*/ | ||
_this.finishReason = constants_1.IDLE_TRANSACTION_FINISH_REASONS[4]; | ||
// Amount of times heartbeat has counted. Will cause transaction to finish after 3 beats. | ||
@@ -84,7 +106,9 @@ _this._heartbeatCounter = 0; | ||
} | ||
_this._initTimeout = setTimeout(function () { | ||
_this._startIdleTimeout(); | ||
global.setTimeout(function () { | ||
if (!_this._finished) { | ||
_this.finishReason = constants_1.IDLE_TRANSACTION_FINISH_REASONS[3]; /* 'finalTimeout' */ | ||
_this.finish(); | ||
} | ||
}, _this._idleTimeout); | ||
}, _this._finalTimeout); | ||
return _this; | ||
@@ -99,2 +123,3 @@ } | ||
this.activities = {}; | ||
this.setTag(constants_1.FINISH_REASON_TAG, this.finishReason); | ||
if (this.spanRecorder) { | ||
@@ -179,2 +204,24 @@ utils_1.logger.log('[Tracing] finishing IdleTransaction', new Date(endTimestamp * 1000).toISOString(), this.op); | ||
/** | ||
* Cancels the existing idletimeout, if there is one | ||
*/ | ||
IdleTransaction.prototype._cancelIdleTimeout = function () { | ||
if (this._idleTimeoutID) { | ||
global.clearTimeout(this._idleTimeoutID); | ||
this._idleTimeoutID = undefined; | ||
} | ||
}; | ||
/** | ||
* Creates an idletimeout | ||
*/ | ||
IdleTransaction.prototype._startIdleTimeout = function (endTimestamp) { | ||
var _this = this; | ||
this._cancelIdleTimeout(); | ||
this._idleTimeoutID = global.setTimeout(function () { | ||
if (!_this._finished && Object.keys(_this.activities).length === 0) { | ||
_this.finishReason = constants_1.IDLE_TRANSACTION_FINISH_REASONS[1]; /* 'idleTimeout' */ | ||
_this.finish(endTimestamp); | ||
} | ||
}, this._idleTimeout); | ||
}; | ||
/** | ||
* Start tracking a specific activity. | ||
@@ -184,6 +231,3 @@ * @param spanId The span id that represents the activity | ||
IdleTransaction.prototype._pushActivity = function (spanId) { | ||
if (this._initTimeout) { | ||
clearTimeout(this._initTimeout); | ||
this._initTimeout = undefined; | ||
} | ||
this._cancelIdleTimeout(); | ||
utils_1.logger.log("[Tracing] pushActivity: " + spanId); | ||
@@ -198,3 +242,2 @@ this.activities[spanId] = true; | ||
IdleTransaction.prototype._popActivity = function (spanId) { | ||
var _this = this; | ||
if (this.activities[spanId]) { | ||
@@ -210,9 +253,4 @@ utils_1.logger.log("[Tracing] popActivity " + spanId); | ||
// Remember timestampWithMs is in seconds, timeout is in ms | ||
var end_1 = utils_1.timestampWithMs() + timeout / 1000; | ||
setTimeout(function () { | ||
if (!_this._finished) { | ||
_this.setTag(constants_1.FINISH_REASON_TAG, constants_1.IDLE_TRANSACTION_FINISH_REASONS[1]); | ||
_this.finish(end_1); | ||
} | ||
}, timeout); | ||
var endTimestamp = utils_1.timestampWithMs() + timeout / 1000; | ||
this._startIdleTimeout(endTimestamp); | ||
} | ||
@@ -240,3 +278,3 @@ }; | ||
this.setStatus('deadline_exceeded'); | ||
this.setTag(constants_1.FINISH_REASON_TAG, constants_1.IDLE_TRANSACTION_FINISH_REASONS[0]); | ||
this.finishReason = constants_1.IDLE_TRANSACTION_FINISH_REASONS[0]; /* 'heartbeatFailed' */ | ||
this.finish(); | ||
@@ -254,3 +292,3 @@ } | ||
utils_1.logger.log("pinging Heartbeat -> current counter: " + this._heartbeatCounter); | ||
setTimeout(function () { | ||
global.setTimeout(function () { | ||
_this._beat(); | ||
@@ -257,0 +295,0 @@ }, exports.HEARTBEAT_INTERVAL); |
import { Hub } from '@sentry/hub'; | ||
import { Options, TraceparentData, Transaction } from '@sentry/types'; | ||
export declare const TRACEPARENT_REGEXP: RegExp; | ||
import { Options, Transaction } from '@sentry/types'; | ||
/** | ||
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used | ||
* to be declared in this file. It was later moved into `@sentry/utils` as part of a | ||
* move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData` | ||
* is the only tracing function used by `@sentry/node`). | ||
* | ||
* These exports are kept here for backwards compatability's sake. | ||
* | ||
* TODO(v7): Reorganize these exports | ||
* | ||
* See https://github.com/getsentry/sentry-javascript/issues/4642 for more details. | ||
*/ | ||
export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils'; | ||
/** | ||
* Determines if tracing is currently enabled. | ||
@@ -10,10 +22,2 @@ * | ||
export declare function hasTracingEnabled(maybeOptions?: Options | undefined): boolean; | ||
/** | ||
* Extract transaction context data from a `sentry-trace` header. | ||
* | ||
* @param traceparent Traceparent string | ||
* | ||
* @returns Object containing data from the header, or undefined if traceparent string is malformed | ||
*/ | ||
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined; | ||
/** Grabs active transaction off scope, if any */ | ||
@@ -20,0 +24,0 @@ export declare function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined; |
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var hub_1 = require("@sentry/hub"); | ||
exports.TRACEPARENT_REGEXP = new RegExp('^[ \\t]*' + // whitespace | ||
'([0-9a-f]{32})?' + // trace_id | ||
'-?([0-9a-f]{16})?' + // span_id | ||
'-?([01])?' + // sampled | ||
'[ \\t]*$'); | ||
/** | ||
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used | ||
* to be declared in this file. It was later moved into `@sentry/utils` as part of a | ||
* move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData` | ||
* is the only tracing function used by `@sentry/node`). | ||
* | ||
* These exports are kept here for backwards compatability's sake. | ||
* | ||
* TODO(v7): Reorganize these exports | ||
* | ||
* See https://github.com/getsentry/sentry-javascript/issues/4642 for more details. | ||
*/ | ||
var utils_1 = require("@sentry/utils"); | ||
exports.TRACEPARENT_REGEXP = utils_1.TRACEPARENT_REGEXP; | ||
exports.extractTraceparentData = utils_1.extractTraceparentData; | ||
/** | ||
* Determines if tracing is currently enabled. | ||
@@ -19,28 +29,2 @@ * | ||
exports.hasTracingEnabled = hasTracingEnabled; | ||
/** | ||
* Extract transaction context data from a `sentry-trace` header. | ||
* | ||
* @param traceparent Traceparent string | ||
* | ||
* @returns Object containing data from the header, or undefined if traceparent string is malformed | ||
*/ | ||
function extractTraceparentData(traceparent) { | ||
var matches = traceparent.match(exports.TRACEPARENT_REGEXP); | ||
if (matches) { | ||
var parentSampled = void 0; | ||
if (matches[3] === '1') { | ||
parentSampled = true; | ||
} | ||
else if (matches[3] === '0') { | ||
parentSampled = false; | ||
} | ||
return { | ||
traceId: matches[1], | ||
parentSampled: parentSampled, | ||
parentSpanId: matches[2], | ||
}; | ||
} | ||
return undefined; | ||
} | ||
exports.extractTraceparentData = extractTraceparentData; | ||
/** Grabs active transaction off scope, if any */ | ||
@@ -70,4 +54,4 @@ function getActiveTransaction(maybeHub) { | ||
// so it can be used in manual instrumentation without necessitating a hard dependency on @sentry/utils | ||
var utils_1 = require("@sentry/utils"); | ||
exports.stripUrlQueryAndFragment = utils_1.stripUrlQueryAndFragment; | ||
var utils_2 = require("@sentry/utils"); | ||
exports.stripUrlQueryAndFragment = utils_2.stripUrlQueryAndFragment; | ||
//# sourceMappingURL=utils.js.map |
import { getGlobalObject, logger } from '@sentry/utils'; | ||
import { FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS } from '../constants'; | ||
import { IDLE_TRANSACTION_FINISH_REASONS } from '../constants'; | ||
import { getActiveTransaction } from '../utils'; | ||
@@ -22,3 +22,3 @@ var global = getGlobalObject(); | ||
activeTransaction.setTag('visibilitychange', 'document.hidden'); | ||
activeTransaction.setTag(FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS[2]); | ||
activeTransaction.finishReason = IDLE_TRANSACTION_FINISH_REASONS[2]; /* 'documentHidden' */ | ||
activeTransaction.finish(); | ||
@@ -25,0 +25,0 @@ } |
@@ -10,2 +10,3 @@ import { Hub } from '@sentry/hub'; | ||
* the last finished span as the endtime for the transaction. | ||
* | ||
* Time is in ms. | ||
@@ -17,2 +18,11 @@ * | ||
/** | ||
* The max duration for a transaction. If a transaction duration hits the `finalTimeout` value, it | ||
* will be finished. | ||
* | ||
* Time is in ms. | ||
* | ||
* Default: 30000 | ||
*/ | ||
finalTimeout: number; | ||
/** | ||
* Flag to enable/disable creation of `navigation` transaction on history changes. | ||
@@ -19,0 +29,0 @@ * |
import { __assign } from "tslib"; | ||
import { getGlobalObject, logger } from '@sentry/utils'; | ||
import { startIdleTransaction } from '../hubextensions'; | ||
import { DEFAULT_IDLE_TIMEOUT } from '../idletransaction'; | ||
import { DEFAULT_FINAL_TIMEOUT, DEFAULT_IDLE_TIMEOUT } from '../idletransaction'; | ||
import { extractTraceparentData, secToMs } from '../utils'; | ||
@@ -11,3 +11,3 @@ import { registerBackgroundTabDetection } from './backgroundtab'; | ||
export var DEFAULT_MAX_TRANSACTION_DURATION_SECONDS = 600; | ||
var DEFAULT_BROWSER_TRACING_OPTIONS = __assign({ idleTimeout: DEFAULT_IDLE_TIMEOUT, markBackgroundTransactions: true, maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS, routingInstrumentation: instrumentRoutingWithDefaults, startTransactionOnLocationChange: true, startTransactionOnPageLoad: true }, defaultRequestInstrumentationOptions); | ||
var DEFAULT_BROWSER_TRACING_OPTIONS = __assign({ idleTimeout: DEFAULT_IDLE_TIMEOUT, finalTimeout: DEFAULT_FINAL_TIMEOUT, markBackgroundTransactions: true, maxTransactionDuration: DEFAULT_MAX_TRANSACTION_DURATION_SECONDS, routingInstrumentation: instrumentRoutingWithDefaults, startTransactionOnLocationChange: true, startTransactionOnPageLoad: true }, defaultRequestInstrumentationOptions); | ||
/** | ||
@@ -14,0 +14,0 @@ * The Browser Tracing integration automatically instruments browser pageload/navigation |
@@ -1,3 +0,3 @@ | ||
export declare const FINISH_REASON_TAG = "finishReason"; | ||
export declare const IDLE_TRANSACTION_FINISH_REASONS: readonly ["heartbeatFailed", "idleTimeout", "documentHidden"]; | ||
export declare const FINISH_REASON_TAG: "finishReason"; | ||
export declare const IDLE_TRANSACTION_FINISH_REASONS: readonly ["heartbeatFailed", "idleTimeout", "documentHidden", "finalTimeout", "externalFinish"]; | ||
//# sourceMappingURL=constants.d.ts.map |
// Store finish reasons in tuple to save on bundle size | ||
// Readonly type should enforce that this is not mutated. | ||
export var FINISH_REASON_TAG = 'finishReason'; | ||
export var IDLE_TRANSACTION_FINISH_REASONS = ['heartbeatFailed', 'idleTimeout', 'documentHidden']; | ||
export var IDLE_TRANSACTION_FINISH_REASONS = [ | ||
'heartbeatFailed', | ||
'idleTimeout', | ||
'documentHidden', | ||
'finalTimeout', | ||
'externalFinish', | ||
]; | ||
//# sourceMappingURL=constants.js.map |
import { Hub } from '@sentry/hub'; | ||
import { TransactionContext } from '@sentry/types'; | ||
import { IDLE_TRANSACTION_FINISH_REASONS } from './constants'; | ||
import { Span, SpanRecorder } from './span'; | ||
import { Transaction } from './transaction'; | ||
export declare const DEFAULT_IDLE_TIMEOUT = 1000; | ||
export declare const DEFAULT_FINAL_TIMEOUT = 30000; | ||
export declare const HEARTBEAT_INTERVAL = 5000; | ||
@@ -31,6 +33,24 @@ /** | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
private readonly _idleTimeout; | ||
private readonly _onScope; | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
private readonly _finalTimeout; | ||
activities: Record<string, boolean>; | ||
/** | ||
* | ||
* Defaults to `externalFinish`, which means transaction.finish() was called outside of the idle transaction (for example, | ||
* by a navigation transaction ending the previous pageload/navigation in some routing instrumentation). | ||
* @default 'externalFinish' | ||
*/ | ||
finishReason: typeof IDLE_TRANSACTION_FINISH_REASONS[number]; | ||
private _prevHeartbeatString; | ||
@@ -44,3 +64,3 @@ private _heartbeatCounter; | ||
*/ | ||
private _initTimeout; | ||
private _idleTimeoutID; | ||
constructor(transactionContext: TransactionContext, _idleHub?: Hub | undefined, | ||
@@ -50,4 +70,15 @@ /** | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
_idleTimeout?: number, _onScope?: boolean); | ||
_idleTimeout?: number, _onScope?: boolean, | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
_finalTimeout?: number); | ||
/** {@inheritDoc} */ | ||
@@ -68,2 +99,10 @@ finish(endTimestamp?: number): string | undefined; | ||
/** | ||
* Cancels the existing idletimeout, if there is one | ||
*/ | ||
private _cancelIdleTimeout; | ||
/** | ||
* Creates an idletimeout | ||
*/ | ||
private _startIdleTimeout; | ||
/** | ||
* Start tracking a specific activity. | ||
@@ -70,0 +109,0 @@ * @param spanId The span id that represents the activity |
import { __extends, __values } from "tslib"; | ||
import { logger, timestampWithMs } from '@sentry/utils'; | ||
import { getGlobalObject, logger, timestampWithMs } from '@sentry/utils'; | ||
import { FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS } from './constants'; | ||
@@ -7,3 +7,5 @@ import { SpanRecorder } from './span'; | ||
export var DEFAULT_IDLE_TIMEOUT = 1000; | ||
export var DEFAULT_FINAL_TIMEOUT = 30000; | ||
export var HEARTBEAT_INTERVAL = 5000; | ||
var global = getGlobalObject(); | ||
/** | ||
@@ -56,8 +58,20 @@ * @inheritDoc | ||
* @default 1000 | ||
* | ||
* TODO: Make _idleTimeout and _finalTimeout required to reduce duplication when setting the options | ||
* in `BrowserTracing`. This is considered a breaking change to the IdleTransaction API, | ||
* so we need to make sure we communicate it with react native. | ||
*/ | ||
_idleTimeout, | ||
// Whether or not the transaction should put itself on the scope when it starts and pop itself off when it ends | ||
_onScope) { | ||
_onScope, | ||
/** | ||
* The final value that a transaction cannot exceed | ||
* @default 30000 | ||
* @experimental | ||
* @internal | ||
*/ | ||
_finalTimeout) { | ||
if (_idleTimeout === void 0) { _idleTimeout = DEFAULT_IDLE_TIMEOUT; } | ||
if (_onScope === void 0) { _onScope = false; } | ||
if (_finalTimeout === void 0) { _finalTimeout = DEFAULT_FINAL_TIMEOUT; } | ||
var _this = _super.call(this, transactionContext, _idleHub) || this; | ||
@@ -67,4 +81,12 @@ _this._idleHub = _idleHub; | ||
_this._onScope = _onScope; | ||
_this._finalTimeout = _finalTimeout; | ||
// Activities store a list of active spans | ||
_this.activities = {}; | ||
/** | ||
* | ||
* Defaults to `externalFinish`, which means transaction.finish() was called outside of the idle transaction (for example, | ||
* by a navigation transaction ending the previous pageload/navigation in some routing instrumentation). | ||
* @default 'externalFinish' | ||
*/ | ||
_this.finishReason = IDLE_TRANSACTION_FINISH_REASONS[4]; | ||
// Amount of times heartbeat has counted. Will cause transaction to finish after 3 beats. | ||
@@ -83,7 +105,9 @@ _this._heartbeatCounter = 0; | ||
} | ||
_this._initTimeout = setTimeout(function () { | ||
_this._startIdleTimeout(); | ||
global.setTimeout(function () { | ||
if (!_this._finished) { | ||
_this.finishReason = IDLE_TRANSACTION_FINISH_REASONS[3]; /* 'finalTimeout' */ | ||
_this.finish(); | ||
} | ||
}, _this._idleTimeout); | ||
}, _this._finalTimeout); | ||
return _this; | ||
@@ -98,2 +122,3 @@ } | ||
this.activities = {}; | ||
this.setTag(FINISH_REASON_TAG, this.finishReason); | ||
if (this.spanRecorder) { | ||
@@ -178,2 +203,24 @@ logger.log('[Tracing] finishing IdleTransaction', new Date(endTimestamp * 1000).toISOString(), this.op); | ||
/** | ||
* Cancels the existing idletimeout, if there is one | ||
*/ | ||
IdleTransaction.prototype._cancelIdleTimeout = function () { | ||
if (this._idleTimeoutID) { | ||
global.clearTimeout(this._idleTimeoutID); | ||
this._idleTimeoutID = undefined; | ||
} | ||
}; | ||
/** | ||
* Creates an idletimeout | ||
*/ | ||
IdleTransaction.prototype._startIdleTimeout = function (endTimestamp) { | ||
var _this = this; | ||
this._cancelIdleTimeout(); | ||
this._idleTimeoutID = global.setTimeout(function () { | ||
if (!_this._finished && Object.keys(_this.activities).length === 0) { | ||
_this.finishReason = IDLE_TRANSACTION_FINISH_REASONS[1]; /* 'idleTimeout' */ | ||
_this.finish(endTimestamp); | ||
} | ||
}, this._idleTimeout); | ||
}; | ||
/** | ||
* Start tracking a specific activity. | ||
@@ -183,6 +230,3 @@ * @param spanId The span id that represents the activity | ||
IdleTransaction.prototype._pushActivity = function (spanId) { | ||
if (this._initTimeout) { | ||
clearTimeout(this._initTimeout); | ||
this._initTimeout = undefined; | ||
} | ||
this._cancelIdleTimeout(); | ||
logger.log("[Tracing] pushActivity: " + spanId); | ||
@@ -197,3 +241,2 @@ this.activities[spanId] = true; | ||
IdleTransaction.prototype._popActivity = function (spanId) { | ||
var _this = this; | ||
if (this.activities[spanId]) { | ||
@@ -209,9 +252,4 @@ logger.log("[Tracing] popActivity " + spanId); | ||
// Remember timestampWithMs is in seconds, timeout is in ms | ||
var end_1 = timestampWithMs() + timeout / 1000; | ||
setTimeout(function () { | ||
if (!_this._finished) { | ||
_this.setTag(FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS[1]); | ||
_this.finish(end_1); | ||
} | ||
}, timeout); | ||
var endTimestamp = timestampWithMs() + timeout / 1000; | ||
this._startIdleTimeout(endTimestamp); | ||
} | ||
@@ -239,3 +277,3 @@ }; | ||
this.setStatus('deadline_exceeded'); | ||
this.setTag(FINISH_REASON_TAG, IDLE_TRANSACTION_FINISH_REASONS[0]); | ||
this.finishReason = IDLE_TRANSACTION_FINISH_REASONS[0]; /* 'heartbeatFailed' */ | ||
this.finish(); | ||
@@ -253,3 +291,3 @@ } | ||
logger.log("pinging Heartbeat -> current counter: " + this._heartbeatCounter); | ||
setTimeout(function () { | ||
global.setTimeout(function () { | ||
_this._beat(); | ||
@@ -256,0 +294,0 @@ }, HEARTBEAT_INTERVAL); |
import { Hub } from '@sentry/hub'; | ||
import { Options, TraceparentData, Transaction } from '@sentry/types'; | ||
export declare const TRACEPARENT_REGEXP: RegExp; | ||
import { Options, Transaction } from '@sentry/types'; | ||
/** | ||
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used | ||
* to be declared in this file. It was later moved into `@sentry/utils` as part of a | ||
* move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData` | ||
* is the only tracing function used by `@sentry/node`). | ||
* | ||
* These exports are kept here for backwards compatability's sake. | ||
* | ||
* TODO(v7): Reorganize these exports | ||
* | ||
* See https://github.com/getsentry/sentry-javascript/issues/4642 for more details. | ||
*/ | ||
export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils'; | ||
/** | ||
* Determines if tracing is currently enabled. | ||
@@ -10,10 +22,2 @@ * | ||
export declare function hasTracingEnabled(maybeOptions?: Options | undefined): boolean; | ||
/** | ||
* Extract transaction context data from a `sentry-trace` header. | ||
* | ||
* @param traceparent Traceparent string | ||
* | ||
* @returns Object containing data from the header, or undefined if traceparent string is malformed | ||
*/ | ||
export declare function extractTraceparentData(traceparent: string): TraceparentData | undefined; | ||
/** Grabs active transaction off scope, if any */ | ||
@@ -20,0 +24,0 @@ export declare function getActiveTransaction<T extends Transaction>(maybeHub?: Hub): T | undefined; |
import { getCurrentHub } from '@sentry/hub'; | ||
export var TRACEPARENT_REGEXP = new RegExp('^[ \\t]*' + // whitespace | ||
'([0-9a-f]{32})?' + // trace_id | ||
'-?([0-9a-f]{16})?' + // span_id | ||
'-?([01])?' + // sampled | ||
'[ \\t]*$'); | ||
/** | ||
* The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used | ||
* to be declared in this file. It was later moved into `@sentry/utils` as part of a | ||
* move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData` | ||
* is the only tracing function used by `@sentry/node`). | ||
* | ||
* These exports are kept here for backwards compatability's sake. | ||
* | ||
* TODO(v7): Reorganize these exports | ||
* | ||
* See https://github.com/getsentry/sentry-javascript/issues/4642 for more details. | ||
*/ | ||
export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils'; | ||
/** | ||
* Determines if tracing is currently enabled. | ||
@@ -17,27 +25,2 @@ * | ||
} | ||
/** | ||
* Extract transaction context data from a `sentry-trace` header. | ||
* | ||
* @param traceparent Traceparent string | ||
* | ||
* @returns Object containing data from the header, or undefined if traceparent string is malformed | ||
*/ | ||
export function extractTraceparentData(traceparent) { | ||
var matches = traceparent.match(TRACEPARENT_REGEXP); | ||
if (matches) { | ||
var parentSampled = void 0; | ||
if (matches[3] === '1') { | ||
parentSampled = true; | ||
} | ||
else if (matches[3] === '0') { | ||
parentSampled = false; | ||
} | ||
return { | ||
traceId: matches[1], | ||
parentSampled: parentSampled, | ||
parentSpanId: matches[2], | ||
}; | ||
} | ||
return undefined; | ||
} | ||
/** Grabs active transaction off scope, if any */ | ||
@@ -44,0 +27,0 @@ export function getActiveTransaction(maybeHub) { |
{ | ||
"name": "@sentry/tracing", | ||
"version": "6.18.0", | ||
"version": "6.18.1-beta.0", | ||
"description": "Extensions for Sentry AM", | ||
@@ -19,10 +19,10 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/hub": "6.18.0", | ||
"@sentry/minimal": "6.18.0", | ||
"@sentry/types": "6.18.0", | ||
"@sentry/utils": "6.18.0", | ||
"@sentry/hub": "6.18.1-beta.0", | ||
"@sentry/minimal": "6.18.1-beta.0", | ||
"@sentry/types": "6.18.1-beta.0", | ||
"@sentry/utils": "6.18.1-beta.0", | ||
"tslib": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"@sentry/browser": "6.18.0", | ||
"@sentry/browser": "6.18.1-beta.0", | ||
"@types/express": "^4.17.1", | ||
@@ -29,0 +29,0 @@ "@types/jsdom": "^16.2.3", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2285084
16659
2
+ Added@sentry/hub@6.18.1-beta.0(transitive)
+ Added@sentry/minimal@6.18.1-beta.0(transitive)
+ Added@sentry/types@6.18.1-beta.0(transitive)
+ Added@sentry/utils@6.18.1-beta.0(transitive)
- Removed@sentry/hub@6.18.0(transitive)
- Removed@sentry/minimal@6.18.0(transitive)
- Removed@sentry/types@6.18.0(transitive)
- Removed@sentry/utils@6.18.0(transitive)
Updated@sentry/hub@6.18.1-beta.0
Updated@sentry/types@6.18.1-beta.0
Updated@sentry/utils@6.18.1-beta.0