Skip to content

Commit 35d0286

Browse files
committed
fixup! feat(cloudflare): Split alarms into multiple traces and link them
1 parent ce3a761 commit 35d0286

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

packages/cloudflare/src/utils/traceLinks.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ export function getTraceLinkKey(methodName: string): string {
3232
/**
3333
* Stores the current span context in Durable Object storage for trace linking.
3434
* Uses the original uninstrumented storage to avoid creating spans for internal operations.
35+
* Errors are silently ignored to prevent internal storage failures from propagating to user code.
3536
*/
3637
export async function storeSpanContext(originalStorage: DurableObjectStorage, methodName: string): Promise<void> {
37-
const activeSpan = getActiveSpan();
38-
if (activeSpan) {
39-
const spanContext = activeSpan.spanContext();
40-
const storedContext: StoredSpanContext = {
41-
traceId: spanContext.traceId,
42-
spanId: spanContext.spanId,
43-
sampled: spanContext.traceFlags === TraceFlags.SAMPLED,
44-
};
45-
await originalStorage.put(getTraceLinkKey(methodName), storedContext);
38+
try {
39+
const activeSpan = getActiveSpan();
40+
if (activeSpan) {
41+
const spanContext = activeSpan.spanContext();
42+
const storedContext: StoredSpanContext = {
43+
traceId: spanContext.traceId,
44+
spanId: spanContext.spanId,
45+
sampled: spanContext.traceFlags === TraceFlags.SAMPLED,
46+
};
47+
await originalStorage.put(getTraceLinkKey(methodName), storedContext);
48+
}
49+
} catch {
50+
// Silently ignore storage errors to prevent internal failures from affecting user code
4651
}
4752
}
4853

packages/cloudflare/src/wrapMethodWithSentry.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ export function wrapMethodWithSentry<T extends OriginalMethod>(
162162
}
163163

164164
const spanName = wrapperOptions.spanName || methodName;
165-
const attributes = {
166-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp || 'function',
167-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.durable_object',
168-
};
165+
const attributes = wrapperOptions.spanOp
166+
? {
167+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,
168+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.durable_object',
169+
}
170+
: {};
169171

170172
const executeSpan = (): unknown => {
171173
return startSpan({ name: spanName, attributes, links }, async span => {

packages/cloudflare/test/traceLinks.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,23 @@ describe('traceLinks', () => {
8181

8282
expect(mockStorage.put).not.toHaveBeenCalled();
8383
});
84+
85+
it('silently ignores storage errors', async () => {
86+
const mockSpanContext = {
87+
traceId: 'abc123def456789012345678901234ab',
88+
spanId: '1234567890abcdef',
89+
traceFlags: TraceFlags.SAMPLED,
90+
};
91+
const mockSpan = {
92+
spanContext: vi.fn().mockReturnValue(mockSpanContext),
93+
};
94+
vi.mocked(sentryCore.getActiveSpan).mockReturnValue(mockSpan as any);
95+
96+
const mockStorage = createMockStorage();
97+
mockStorage.put = vi.fn().mockRejectedValue(new Error('Storage quota exceeded'));
98+
99+
await expect(storeSpanContext(mockStorage, 'alarm')).resolves.toBeUndefined();
100+
});
84101
});
85102

86103
describe('getStoredSpanContext', () => {

0 commit comments

Comments
 (0)