fix: sentry tracing

This commit is contained in:
devthejo 2025-06-23 00:07:49 +02:00
parent 8ba4056187
commit 4a0f3ab7ef
2 changed files with 217 additions and 215 deletions

View file

@ -346,11 +346,12 @@ export default async function trackLocation() {
if (count > 0) {
locationLogger.info(`Found ${count} pending records, forcing sync`);
const transaction = Sentry.startTransaction({
await Sentry.startSpan(
{
name: "force-sync-pending-records",
op: "geolocation-sync",
});
},
async (span) => {
try {
const { userToken } = getAuthState();
const state = await BackgroundGeolocation.getState();
@ -371,7 +372,7 @@ export default async function trackLocation() {
},
});
transaction.setStatus("ok");
span.setStatus("ok");
} else {
Sentry.addBreadcrumb({
message: "Forced sync skipped",
@ -383,7 +384,7 @@ export default async function trackLocation() {
},
});
transaction.setStatus("cancelled");
span.setStatus("cancelled");
}
} catch (error) {
locationLogger.error("Forced sync failed", {
@ -401,10 +402,11 @@ export default async function trackLocation() {
},
});
transaction.setStatus("internal_error");
} finally {
transaction.finish();
span.setStatus("internal_error");
throw error; // Re-throw to ensure span captures the error
}
},
);
}
} catch (error) {
locationLogger.error("Failed to get pending records count", {

View file

@ -12,13 +12,12 @@ const logger = createLogger({
// Background task to cancel expired notifications
const backgroundTask = async () => {
const transaction = Sentry.startTransaction({
await Sentry.startSpan(
{
name: "auto-cancel-expired-notifications",
op: "background-task",
});
Sentry.getCurrentScope().setSpan(transaction);
},
async (span) => {
try {
logger.info("Starting auto-cancel expired notifications task");
@ -29,12 +28,13 @@ const backgroundTask = async () => {
});
// Get displayed notifications with timeout protection
const getNotificationsSpan = transaction.startChild({
let notifications;
await Sentry.startSpan(
{
op: "get-displayed-notifications",
description: "Getting displayed notifications",
});
let notifications;
},
async (getNotificationsSpan) => {
try {
// Add timeout protection for the API call
notifications = await Promise.race([
@ -50,9 +50,9 @@ const backgroundTask = async () => {
} catch (error) {
getNotificationsSpan.setStatus("internal_error");
throw error;
} finally {
getNotificationsSpan.finish();
}
},
);
if (!Array.isArray(notifications)) {
logger.warn("No notifications array received", { notifications });
@ -166,7 +166,7 @@ const backgroundTask = async () => {
},
});
transaction.setStatus("ok");
span.setStatus("ok");
} catch (error) {
logger.error("Auto-cancel task failed", { error });
@ -177,11 +177,11 @@ const backgroundTask = async () => {
},
});
transaction.setStatus("internal_error");
span.setStatus("internal_error");
throw error; // Re-throw to be handled by caller
} finally {
transaction.finish();
}
},
);
};
export const useAutoCancelExpired = () => {