@sentry/apm
Advanced tools
Comparing version 5.16.1 to 5.17.0
@@ -47,14 +47,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
* @deprecated | ||
* This is here to make sure we don't break users that relied on calling startSpan to create a transaction | ||
* with the transaction poperty set. | ||
* TODO: consider removing this in a future release. | ||
* | ||
* This is for backwards compatibility with releases before startTransaction | ||
* existed, to allow for a smoother transition. | ||
*/ | ||
if (context.transaction !== undefined) { | ||
utils_1.logger.warn("Use `Sentry.startTransaction({name: " + context.transaction + "})` to start a Transaction."); | ||
context.name = context.transaction; | ||
{ | ||
// The `TransactionContext.name` field used to be called `transaction`. | ||
var transactionContext = context; | ||
if (transactionContext.transaction !== undefined) { | ||
transactionContext.name = transactionContext.transaction; | ||
} | ||
// Check for not undefined since we defined it's ok to start a transaction | ||
// with an empty name. | ||
if (transactionContext.name !== undefined) { | ||
utils_1.logger.warn('Deprecated: Use startTransaction to start transactions and Transaction.startChild to start spans.'); | ||
return this.startTransaction(transactionContext); | ||
} | ||
} | ||
// We have the check of not undefined since we defined it's ok to start a transaction with an empty name | ||
// tslint:disable-next-line: strict-type-predicates | ||
if (context.name !== undefined) { | ||
return this.startTransaction(context); | ||
} | ||
var scope = this.getScope(); | ||
@@ -61,0 +67,0 @@ if (scope) { |
@@ -126,2 +126,6 @@ import { Hub } from '@sentry/hub'; | ||
private static _heartbeatCounter; | ||
/** Holds the latest LargestContentfulPaint value (it changes during page load). */ | ||
private static _lcp?; | ||
/** Force any pending LargestContentfulPaint records to be dispatched. */ | ||
private static _forceLCP; | ||
/** | ||
@@ -179,3 +183,3 @@ * Constructor for Tracing | ||
/** | ||
* Finshes the current active transaction | ||
* Finishes the current active transaction | ||
*/ | ||
@@ -192,2 +196,6 @@ static finishIdleTransaction(endTimestamp: number): void; | ||
/** | ||
* Starts tracking the Largest Contentful Paint on the current page. | ||
*/ | ||
private static _trackLCP; | ||
/** | ||
* Sets the status of the current active transaction (if there is one) | ||
@@ -194,0 +202,0 @@ */ |
@@ -25,2 +25,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
global.performance.mark('sentry-tracing-init'); | ||
Tracing._trackLCP(); | ||
} | ||
@@ -255,3 +256,5 @@ var defaults = { | ||
} | ||
Tracing._activeTransaction = hub.startSpan(tslib_1.__assign({ trimEnd: true }, transactionContext)); | ||
Tracing._activeTransaction = hub.startTransaction(tslib_1.__assign({ trimEnd: true }, transactionContext)); | ||
// We set the transaction here on the scope so error events pick up the trace context and attach it to the error | ||
hub.configureScope(function (scope) { return scope.setSpan(Tracing._activeTransaction); }); | ||
// The reason we do this here is because of cached responses | ||
@@ -266,3 +269,3 @@ // If we start and transaction without an activity it would never finish since there is no activity | ||
/** | ||
* Finshes the current active transaction | ||
* Finishes the current active transaction | ||
*/ | ||
@@ -316,2 +319,11 @@ Tracing.finishIdleTransaction = function (endTimestamp) { | ||
Tracing._log('[Tracing] Adding & adjusting spans using Performance API'); | ||
// FIXME: depending on the 'op' directly is brittle. | ||
if (transactionSpan.op === 'pageload') { | ||
// Force any pending records to be dispatched. | ||
Tracing._forceLCP(); | ||
if (Tracing._lcp) { | ||
// Set the last observed LCP score. | ||
transactionSpan.setData('_sentry_web_vitals', { LCP: Tracing._lcp }); | ||
} | ||
} | ||
var timeOrigin = Tracing._msToSec(performance.timeOrigin); | ||
@@ -431,2 +443,50 @@ // tslint:disable-next-line: completed-docs | ||
/** | ||
* Starts tracking the Largest Contentful Paint on the current page. | ||
*/ | ||
Tracing._trackLCP = function () { | ||
// Based on reference implementation from https://web.dev/lcp/#measure-lcp-in-javascript. | ||
// Use a try/catch instead of feature detecting `largest-contentful-paint` | ||
// support, since some browsers throw when using the new `type` option. | ||
// https://bugs.webkit.org/show_bug.cgi?id=209216 | ||
try { | ||
// Keep track of whether (and when) the page was first hidden, see: | ||
// https://github.com/w3c/page-visibility/issues/29 | ||
// NOTE: ideally this check would be performed in the document <head> | ||
// to avoid cases where the visibility state changes before this code runs. | ||
var firstHiddenTime_1 = document.visibilityState === 'hidden' ? 0 : Infinity; | ||
document.addEventListener('visibilitychange', function (event) { | ||
firstHiddenTime_1 = Math.min(firstHiddenTime_1, event.timeStamp); | ||
}, { once: true }); | ||
var updateLCP_1 = function (entry) { | ||
// Only include an LCP entry if the page wasn't hidden prior to | ||
// the entry being dispatched. This typically happens when a page is | ||
// loaded in a background tab. | ||
if (entry.startTime < firstHiddenTime_1) { | ||
// NOTE: the `startTime` value is a getter that returns the entry's | ||
// `renderTime` value, if available, or its `loadTime` value otherwise. | ||
// The `renderTime` value may not be available if the element is an image | ||
// that's loaded cross-origin without the `Timing-Allow-Origin` header. | ||
Tracing._lcp = tslib_1.__assign({}, (entry.id && { elementId: entry.id }), (entry.size && { elementSize: entry.size }), { value: entry.startTime }); | ||
} | ||
}; | ||
// Create a PerformanceObserver that calls `updateLCP` for each entry. | ||
var po_1 = new PerformanceObserver(function (entryList) { | ||
entryList.getEntries().forEach(updateLCP_1); | ||
}); | ||
// Observe entries of type `largest-contentful-paint`, including buffered entries, | ||
// i.e. entries that occurred before calling `observe()` below. | ||
po_1.observe({ | ||
buffered: true, | ||
// @ts-ignore | ||
type: 'largest-contentful-paint', | ||
}); | ||
Tracing._forceLCP = function () { | ||
po_1.takeRecords().forEach(updateLCP_1); | ||
}; | ||
} | ||
catch (e) { | ||
// Do nothing if the browser doesn't support this API. | ||
} | ||
}; | ||
/** | ||
* Sets the status of the current active transaction (if there is one) | ||
@@ -575,2 +635,6 @@ */ | ||
Tracing._heartbeatCounter = 0; | ||
/** Force any pending LargestContentfulPaint records to be dispatched. */ | ||
Tracing._forceLCP = function () { | ||
/* No-op, replaced later if LCP API is available. */ | ||
}; | ||
return Tracing; | ||
@@ -577,0 +641,0 @@ }()); |
@@ -46,14 +46,20 @@ import { getMainCarrier } from '@sentry/hub'; | ||
* @deprecated | ||
* This is here to make sure we don't break users that relied on calling startSpan to create a transaction | ||
* with the transaction poperty set. | ||
* TODO: consider removing this in a future release. | ||
* | ||
* This is for backwards compatibility with releases before startTransaction | ||
* existed, to allow for a smoother transition. | ||
*/ | ||
if (context.transaction !== undefined) { | ||
logger.warn("Use `Sentry.startTransaction({name: " + context.transaction + "})` to start a Transaction."); | ||
context.name = context.transaction; | ||
{ | ||
// The `TransactionContext.name` field used to be called `transaction`. | ||
var transactionContext = context; | ||
if (transactionContext.transaction !== undefined) { | ||
transactionContext.name = transactionContext.transaction; | ||
} | ||
// Check for not undefined since we defined it's ok to start a transaction | ||
// with an empty name. | ||
if (transactionContext.name !== undefined) { | ||
logger.warn('Deprecated: Use startTransaction to start transactions and Transaction.startChild to start spans.'); | ||
return this.startTransaction(transactionContext); | ||
} | ||
} | ||
// We have the check of not undefined since we defined it's ok to start a transaction with an empty name | ||
// tslint:disable-next-line: strict-type-predicates | ||
if (context.name !== undefined) { | ||
return this.startTransaction(context); | ||
} | ||
var scope = this.getScope(); | ||
@@ -60,0 +66,0 @@ if (scope) { |
@@ -126,2 +126,6 @@ import { Hub } from '@sentry/hub'; | ||
private static _heartbeatCounter; | ||
/** Holds the latest LargestContentfulPaint value (it changes during page load). */ | ||
private static _lcp?; | ||
/** Force any pending LargestContentfulPaint records to be dispatched. */ | ||
private static _forceLCP; | ||
/** | ||
@@ -179,3 +183,3 @@ * Constructor for Tracing | ||
/** | ||
* Finshes the current active transaction | ||
* Finishes the current active transaction | ||
*/ | ||
@@ -192,2 +196,6 @@ static finishIdleTransaction(endTimestamp: number): void; | ||
/** | ||
* Starts tracking the Largest Contentful Paint on the current page. | ||
*/ | ||
private static _trackLCP; | ||
/** | ||
* Sets the status of the current active transaction (if there is one) | ||
@@ -194,0 +202,0 @@ */ |
@@ -24,2 +24,3 @@ import * as tslib_1 from "tslib"; | ||
global.performance.mark('sentry-tracing-init'); | ||
Tracing._trackLCP(); | ||
} | ||
@@ -254,3 +255,5 @@ var defaults = { | ||
} | ||
Tracing._activeTransaction = hub.startSpan(tslib_1.__assign({ trimEnd: true }, transactionContext)); | ||
Tracing._activeTransaction = hub.startTransaction(tslib_1.__assign({ trimEnd: true }, transactionContext)); | ||
// We set the transaction here on the scope so error events pick up the trace context and attach it to the error | ||
hub.configureScope(function (scope) { return scope.setSpan(Tracing._activeTransaction); }); | ||
// The reason we do this here is because of cached responses | ||
@@ -265,3 +268,3 @@ // If we start and transaction without an activity it would never finish since there is no activity | ||
/** | ||
* Finshes the current active transaction | ||
* Finishes the current active transaction | ||
*/ | ||
@@ -315,2 +318,11 @@ Tracing.finishIdleTransaction = function (endTimestamp) { | ||
Tracing._log('[Tracing] Adding & adjusting spans using Performance API'); | ||
// FIXME: depending on the 'op' directly is brittle. | ||
if (transactionSpan.op === 'pageload') { | ||
// Force any pending records to be dispatched. | ||
Tracing._forceLCP(); | ||
if (Tracing._lcp) { | ||
// Set the last observed LCP score. | ||
transactionSpan.setData('_sentry_web_vitals', { LCP: Tracing._lcp }); | ||
} | ||
} | ||
var timeOrigin = Tracing._msToSec(performance.timeOrigin); | ||
@@ -430,2 +442,50 @@ // tslint:disable-next-line: completed-docs | ||
/** | ||
* Starts tracking the Largest Contentful Paint on the current page. | ||
*/ | ||
Tracing._trackLCP = function () { | ||
// Based on reference implementation from https://web.dev/lcp/#measure-lcp-in-javascript. | ||
// Use a try/catch instead of feature detecting `largest-contentful-paint` | ||
// support, since some browsers throw when using the new `type` option. | ||
// https://bugs.webkit.org/show_bug.cgi?id=209216 | ||
try { | ||
// Keep track of whether (and when) the page was first hidden, see: | ||
// https://github.com/w3c/page-visibility/issues/29 | ||
// NOTE: ideally this check would be performed in the document <head> | ||
// to avoid cases where the visibility state changes before this code runs. | ||
var firstHiddenTime_1 = document.visibilityState === 'hidden' ? 0 : Infinity; | ||
document.addEventListener('visibilitychange', function (event) { | ||
firstHiddenTime_1 = Math.min(firstHiddenTime_1, event.timeStamp); | ||
}, { once: true }); | ||
var updateLCP_1 = function (entry) { | ||
// Only include an LCP entry if the page wasn't hidden prior to | ||
// the entry being dispatched. This typically happens when a page is | ||
// loaded in a background tab. | ||
if (entry.startTime < firstHiddenTime_1) { | ||
// NOTE: the `startTime` value is a getter that returns the entry's | ||
// `renderTime` value, if available, or its `loadTime` value otherwise. | ||
// The `renderTime` value may not be available if the element is an image | ||
// that's loaded cross-origin without the `Timing-Allow-Origin` header. | ||
Tracing._lcp = tslib_1.__assign({}, (entry.id && { elementId: entry.id }), (entry.size && { elementSize: entry.size }), { value: entry.startTime }); | ||
} | ||
}; | ||
// Create a PerformanceObserver that calls `updateLCP` for each entry. | ||
var po_1 = new PerformanceObserver(function (entryList) { | ||
entryList.getEntries().forEach(updateLCP_1); | ||
}); | ||
// Observe entries of type `largest-contentful-paint`, including buffered entries, | ||
// i.e. entries that occurred before calling `observe()` below. | ||
po_1.observe({ | ||
buffered: true, | ||
// @ts-ignore | ||
type: 'largest-contentful-paint', | ||
}); | ||
Tracing._forceLCP = function () { | ||
po_1.takeRecords().forEach(updateLCP_1); | ||
}; | ||
} | ||
catch (e) { | ||
// Do nothing if the browser doesn't support this API. | ||
} | ||
}; | ||
/** | ||
* Sets the status of the current active transaction (if there is one) | ||
@@ -574,2 +634,6 @@ */ | ||
Tracing._heartbeatCounter = 0; | ||
/** Force any pending LargestContentfulPaint records to be dispatched. */ | ||
Tracing._forceLCP = function () { | ||
/* No-op, replaced later if LCP API is available. */ | ||
}; | ||
return Tracing; | ||
@@ -576,0 +640,0 @@ }()); |
{ | ||
"name": "@sentry/apm", | ||
"version": "5.16.1", | ||
"version": "5.17.0", | ||
"description": "Extensions for APM", | ||
@@ -19,7 +19,7 @@ "repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"dependencies": { | ||
"@sentry/browser": "5.16.1", | ||
"@sentry/hub": "5.16.1", | ||
"@sentry/minimal": "5.16.1", | ||
"@sentry/types": "5.16.1", | ||
"@sentry/utils": "5.16.1", | ||
"@sentry/browser": "5.17.0", | ||
"@sentry/hub": "5.17.0", | ||
"@sentry/minimal": "5.17.0", | ||
"@sentry/types": "5.17.0", | ||
"@sentry/utils": "5.17.0", | ||
"tslib": "^1.9.3" | ||
@@ -26,0 +26,0 @@ }, |
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
358127
3930
+ Added@sentry/browser@5.17.0(transitive)
+ Added@sentry/core@5.17.0(transitive)
+ Added@sentry/hub@5.17.0(transitive)
+ Added@sentry/minimal@5.17.0(transitive)
+ Added@sentry/types@5.17.0(transitive)
+ Added@sentry/utils@5.17.0(transitive)
- Removed@sentry/browser@5.16.1(transitive)
- Removed@sentry/core@5.16.1(transitive)
- Removed@sentry/hub@5.16.1(transitive)
- Removed@sentry/minimal@5.16.1(transitive)
- Removed@sentry/types@5.16.1(transitive)
- Removed@sentry/utils@5.16.1(transitive)
Updated@sentry/browser@5.17.0
Updated@sentry/hub@5.17.0
Updated@sentry/minimal@5.17.0
Updated@sentry/types@5.17.0
Updated@sentry/utils@5.17.0