Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/util/sentry/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,42 @@ describe('excludeEvents', () => {
expect(result.start_timestamp).toBe(1234567890);
});

it('drops event when trace.timed_out flag is true', () => {
const event = {
transaction: 'Onboarding - Overall Journey',
contexts: {
trace: {
span_id: 'abc123',
trace_id: 'def456',
data: {
'trace.timed_out': true,
},
},
},
};

const result = excludeEvents(event);
expect(result).toBeNull();
});

it('keeps event when trace.timed_out flag is absent', () => {
const event = {
transaction: 'Onboarding - Overall Journey',
contexts: {
trace: {
span_id: 'abc123',
trace_id: 'def456',
data: {
'some.other.attr': 'value',
},
},
},
};

const result = excludeEvents(event);
expect(result).toBe(event);
});

it('returns main-exp for experimental environment and main build type', async () => {
const METAMASK_ENVIRONMENT = 'exp';
const isDev = false;
Expand Down
4 changes: 4 additions & 0 deletions app/util/sentry/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ export function excludeEvents(event: SentryEvent | null): SentryEvent | null {
}
}
}
if (event?.contexts?.trace?.data?.['trace.timed_out'] === true) {
return null;
}
Comment thread
smgv marked this conversation as resolved.

//Modify or drop event here
if (event?.transaction === 'Route Change') {
//Route change is dropped because is does not reflect a screen we can action on.
Expand Down
41 changes: 40 additions & 1 deletion app/util/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,11 @@ describe('Trace', () => {
updateCachedConsent(true);

const spanEndMock = jest.fn();
const spanMock = { end: spanEndMock } as unknown as Span;
const spanMock = {
end: spanEndMock,
setStatus: jest.fn(),
setAttribute: jest.fn(),
} as unknown as Span;

startSpanManualMock.mockImplementationOnce((_, fn) =>
fn(spanMock, () => {
Expand All @@ -404,6 +408,41 @@ describe('Trace', () => {

expect(spanEndMock).toHaveBeenCalledTimes(1);
});

it('marks span as timed out with deadline_exceeded status when cleanup fires for open span', () => {
updateCachedConsent(true);

const spanEndMock = jest.fn();
const setStatusMock = jest.fn();
const setAttributeMock = jest.fn();
const spanMock = {
end: spanEndMock,
setStatus: setStatusMock,
setAttribute: setAttributeMock,
} as unknown as Span;

startSpanManualMock.mockImplementationOnce((_, fn) =>
fn(spanMock, () => {
// Intentionally empty
}),
);

trace({
name: NAME_MOCK,
id: ID_MOCK,
tags: TAGS_MOCK,
data: DATA_MOCK,
});

jest.advanceTimersByTime(TRACES_CLEANUP_INTERVAL);

expect(setStatusMock).toHaveBeenCalledWith({
code: 2,
message: 'deadline_exceeded',
});
expect(setAttributeMock).toHaveBeenCalledWith('trace.timed_out', true);
expect(spanEndMock).toHaveBeenCalledTimes(1);
});
});

describe('flushBufferedTraces', () => {
Expand Down
4 changes: 4 additions & 0 deletions app/util/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ function startTrace(request: TraceRequest): TraceContext {

const timeoutId = setTimeout(() => {
log('Trace cleanup due to timeout', name, id);
if (span) {
span.setStatus({ code: 2, message: 'deadline_exceeded' });
span.setAttribute('trace.timed_out', true);
}
end();
tracesByKey.delete(getTraceKey(request));
}, TRACES_CLEANUP_INTERVAL);
Expand Down
Loading