故障排除
了解如何排查跟踪设置的问题。
如果您需要帮助管理事务,可以阅读更多内容。如果您需要额外的帮助,可以在 GitHub 上提问。付费计划的客户还可以联系支持。
当 Sentry 捕获事务时,会为其分配一个事务名称。此名称通常由 Sentry SDK 根据您使用的框架集成自动生成。如果您无法利用自动事务生成(或希望自定义事务名称的生成方式),可以在初始化 SDK 时注册一个全局事件处理器。
例如:
import { addGlobalEventProcessor } from "@sentry/react-native";
addGlobalEventProcessor((event) => {
if (event.type === "transaction") {
event.transaction = sanitizeTransactionName(event.transaction);
}
return event;
});
目前,每个标签的最大字符限制为 200 个字符。超过 200 个字符的标签将被截断,丢失可能重要的信息。为了保留这些数据,可以将数据拆分到多个标签中。
例如,一个超过 200 个字符的标签请求:
https://empowerplant.io/api/0/projects/ep/setup_form/?user_id=314159265358979323846264338327&tracking_id=EasyAsABC123OrSimpleAsDoReMi&product_name=PlantToHumanTranslator&product_id=161803398874989484820458683436563811772030917980576
上述超过 200 个字符的请求将被截断为:
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
},
);