故障排除
了解如何排查追踪设置的问题。
如果您需要帮助管理事务,可以在此了解更多。如果您需要额外的帮助,可以在 GitHub 上提问。付费计划的客户还可以联系支持。
当 Sentry 捕获事务时,会为它们分配一个事务名称。此名称通常由 Sentry SDK 根据您使用的框架集成自动生成。如果您无法利用自动事务生成(或希望自定义事务名称的生成方式),可以使用在初始化 SDK 时注册的全局事件处理器。
例如:
// All JavaScript-based SDKs include this function, so it's safe to replace `@sentry/browser`
// with your particular SDK
import { addEventProcessor } from "@sentry/browser";
addEventProcessor((event) => {
if (event.type === "transaction") {
event.transaction = sanitizeTransactionName(event.transaction);
}
return event;
});
对于使用 browserTracingIntegration
集成的浏览器 JavaScript 应用程序,可以使用 beforeStartSpan
选项根据 URL 更好地将 navigation
/pageload
事务分组。
import * as Sentry from "@sentry/browser";
Sentry.init({
// ...
integrations: [
Sentry.browserTracingIntegration({
beforeStartSpan: (context) => {
return {
...context,
// You could use your UI's routing library to find the matching
// route template here. We don't have one right now, so do some basic
// parameter replacements.
name: location.pathname
.replace(/\/[a-f0-9]{32}/g, "/<hash>")
.replace(/\/\d+/g, "/<digits>"),
};
},
}),
],
});
目前,每个标签的最大字符限制为 200 个字符。超过 200 字符的标签将被截断,可能会丢失重要信息。为了保留这些数据,您可以将数据拆分到多个标签中。
例如,一个超过 200 字符的标签如下:
https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=161803398874989484820458683436563811772030917980576
...将被截断为:
https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=1618033988749894848
建议将数据作为属性添加到跨度,而不是使用标签。使用 span.setAttribute()
可以将任意长度的数据添加到跨度。您可以根据需要向跨度添加任意多个属性。
const baseUrl = "https://empowerplant.io";
const endpoint = "/api/0/projects/ep/setup_form";
const parameters = {
user_id: 314159265358979323846264338327,
tracking_id: "EasyAsABC123OrSimpleAsDoReMi",
product_name: PlantToHumanTranslator,
product_id: 161803398874989484820458683436563811772030917980576,
};
startSpan(
{
op: "http.client",
name: "setup form",
// you can add attributes when starting the span
attributes: {
baseUrl,
endpoint,
},
},
(span) => {
// or you can add attributes to an existing span
for (const key of parameters) {
span.setAttribute(`parameters.${key}`, parameters[key]);
}
// do something to be measured
},
);