英文:
How to exclude App Cold Start from duration in Sentry
问题
我有一个集成了Sentry的React Native应用程序。我在其中使用Sentry的性能功能,使用自动仪表化来测量react-navigation库中的屏幕加载时间。是否有办法在事务列表的p50或p95计算中排除app.start.cold
跨度?我只关心navigation
操作的时间,但p95显示从应用程序冷启动开始的持续时间(例如,列表上第一个事务为15.60秒),这对我来说没有意义。是否有办法更改它,只显示navigation
跨度的持续时间?
英文:
I have React Native app with Sentry integrated. I use Performance from Sentry with automatic instrumentation in order to measure screen load times within react-navigation library). Is there any way to exclude app.start.cold
span from p50 or p95 calculation on the transactions list? I am only interested in the time of navigation
operation, but p95 shows duration in seconds starting from App Cold Start (i.e 15.60s for first transaction on the list) which is not meaningful for me. Is there any way to change it and show duration just for navigation
span?
答案1
得分: 1
如果你不想看到app.start.*
的跨度,你可以在SDK中禁用App启动跟踪。
Sentry.init({
dsn: __YOUR_DSN__,
integrations: [
new Sentry.ReactNativeTracing({
enableAppStartTracking: false,
// ... 其他选项
}),
],
// ...
});
或者,你可以保留应用程序启动跟踪并在beforeSendTransaction
回调中删除跨度,这样你仍然可以获得关于应用程序启动的信息。
请注意,这可能导致数据不准确,因为事务被截断到应用程序启动后的第一个跨度开始。
beforeSendTransaction(event, hint) {
let spanIndexToDelete = null;
let newTransactionStart = null;
event.spans?.forEach((span, index) => {
if (span.op?.startsWith('app.start')) {
spanIndexToDelete = index;
} else {
if (newTransactionStart === null) {
newTransactionStart = span.startTimestamp;
} else if (newTransactionStart > span.startTimestamp) {
newTransactionStart = span.startTimestamp;
}
}
});
if (newTransactionStart) {
event.start_timestamp = newTransactionStart;
}
spanIndexToDelete && event.spans?.splice(spanIndexToDelete, 1);
return event;
}
了解更多有关此回调的信息:https://docs.sentry.io/platforms/react-native/configuration/options/#before-send-transaction
英文:
if you don't want to see the app.start.*
spans you can disable the App Start tracking in the SDK.
Sentry.init({
dsn: __YOUR_DSN__,
integrations: [
new Sentry.ReactNativeTracing({
enableAppStartTracking: false,
// ... other options
}),
],
// ...
});
Or you can keep the app starts tracking and remove the spans in the beforeSendTransaction
callback, this way you will still have the information about the app start in the measurements.
Note that this might lead to inaccurate data, as the transaction is trimmed to the start of the first span after the app start.
beforeSendTransaction(event, hint) {
let spanIndexToDelete = null;
let newTransactionStart: number | null = null;
event.spans?.forEach((span, index) => {
if (span.op?.startsWith('app.start')) {
spanIndexToDelete = index;
} else {
if (newTransactionStart === null) {
newTransactionStart = span.startTimestamp;
} else if (newTransactionStart > span.startTimestamp) {
newTransactionStart = span.startTimestamp;
}
}
});
if (newTransactionStart) {
event.start_timestamp = newTransactionStart;
}
spanIndexToDelete && event.spans?.splice(spanIndexToDelete, 1);
return event;
},
More about the callback https://docs.sentry.io/platforms/react-native/configuration/options/#before-send-transaction
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论