|
| 1 | +import { expect, it } from 'vitest'; |
| 2 | +import type { Event } from '@sentry/core'; |
| 3 | +import { createRunner } from '../../../../runner'; |
| 4 | + |
| 5 | +it('does not propagate trace from worker to durable object when enableRpcTracePropagation is disabled', async ({ |
| 6 | + signal, |
| 7 | +}) => { |
| 8 | + let workerTraceId: string | undefined; |
| 9 | + let workerSpanId: string | undefined; |
| 10 | + let doTraceId: string | undefined; |
| 11 | + let doParentSpanId: string | undefined; |
| 12 | + |
| 13 | + const runner = createRunner(__dirname) |
| 14 | + .expect(envelope => { |
| 15 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 16 | + |
| 17 | + expect(transactionEvent).toEqual( |
| 18 | + expect.objectContaining({ |
| 19 | + contexts: expect.objectContaining({ |
| 20 | + trace: expect.objectContaining({ |
| 21 | + op: 'http.server', |
| 22 | + data: expect.objectContaining({ |
| 23 | + 'sentry.origin': 'auto.http.cloudflare', |
| 24 | + }), |
| 25 | + origin: 'auto.http.cloudflare', |
| 26 | + }), |
| 27 | + }), |
| 28 | + transaction: 'GET /hello', |
| 29 | + }), |
| 30 | + ); |
| 31 | + doTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 32 | + doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; |
| 33 | + }) |
| 34 | + .expect(envelope => { |
| 35 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 36 | + |
| 37 | + expect(transactionEvent).toEqual( |
| 38 | + expect.objectContaining({ |
| 39 | + contexts: expect.objectContaining({ |
| 40 | + trace: expect.objectContaining({ |
| 41 | + op: 'http.server', |
| 42 | + data: expect.objectContaining({ |
| 43 | + 'sentry.origin': 'auto.http.cloudflare', |
| 44 | + }), |
| 45 | + origin: 'auto.http.cloudflare', |
| 46 | + }), |
| 47 | + }), |
| 48 | + transaction: 'GET /', |
| 49 | + }), |
| 50 | + ); |
| 51 | + workerTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 52 | + workerSpanId = transactionEvent.contexts?.trace?.span_id as string; |
| 53 | + }) |
| 54 | + .unordered() |
| 55 | + .start(signal); |
| 56 | + await runner.makeRequest('get', '/'); |
| 57 | + await runner.completed(); |
| 58 | + |
| 59 | + expect(workerTraceId).toBeDefined(); |
| 60 | + expect(doTraceId).toBeDefined(); |
| 61 | + expect(workerTraceId).not.toBe(doTraceId); |
| 62 | + |
| 63 | + expect(workerSpanId).toBeDefined(); |
| 64 | + expect(doParentSpanId).toBeUndefined(); |
| 65 | +}); |
| 66 | + |
| 67 | +it('does not propagate trace from queue handler to durable object when enableRpcTracePropagation is disabled', async ({ |
| 68 | + signal, |
| 69 | +}) => { |
| 70 | + let queueTraceId: string | undefined; |
| 71 | + let queueSpanId: string | undefined; |
| 72 | + let doTraceId: string | undefined; |
| 73 | + let doParentSpanId: string | undefined; |
| 74 | + |
| 75 | + const runner = createRunner(__dirname) |
| 76 | + .expect(envelope => { |
| 77 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 78 | + |
| 79 | + expect(transactionEvent).toEqual( |
| 80 | + expect.objectContaining({ |
| 81 | + contexts: expect.objectContaining({ |
| 82 | + trace: expect.objectContaining({ |
| 83 | + op: 'http.server', |
| 84 | + data: expect.objectContaining({ |
| 85 | + 'sentry.origin': 'auto.http.cloudflare', |
| 86 | + }), |
| 87 | + origin: 'auto.http.cloudflare', |
| 88 | + }), |
| 89 | + }), |
| 90 | + transaction: 'GET /hello', |
| 91 | + }), |
| 92 | + ); |
| 93 | + doTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 94 | + doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; |
| 95 | + }) |
| 96 | + .expect(envelope => { |
| 97 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 98 | + |
| 99 | + expect(transactionEvent).toEqual( |
| 100 | + expect.objectContaining({ |
| 101 | + contexts: expect.objectContaining({ |
| 102 | + trace: expect.objectContaining({ |
| 103 | + op: 'queue.process', |
| 104 | + data: expect.objectContaining({ |
| 105 | + 'sentry.origin': 'auto.faas.cloudflare.queue', |
| 106 | + }), |
| 107 | + origin: 'auto.faas.cloudflare.queue', |
| 108 | + }), |
| 109 | + }), |
| 110 | + transaction: 'process my-queue', |
| 111 | + }), |
| 112 | + ); |
| 113 | + queueTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 114 | + queueSpanId = transactionEvent.contexts?.trace?.span_id as string; |
| 115 | + }) |
| 116 | + // Also expect the fetch transaction from the /queue/send request |
| 117 | + .expect(envelope => { |
| 118 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 119 | + |
| 120 | + expect(transactionEvent).toEqual( |
| 121 | + expect.objectContaining({ |
| 122 | + contexts: expect.objectContaining({ |
| 123 | + trace: expect.objectContaining({ |
| 124 | + op: 'http.server', |
| 125 | + data: expect.objectContaining({ |
| 126 | + 'sentry.origin': 'auto.http.cloudflare', |
| 127 | + }), |
| 128 | + origin: 'auto.http.cloudflare', |
| 129 | + }), |
| 130 | + }), |
| 131 | + transaction: 'GET /queue/send', |
| 132 | + }), |
| 133 | + ); |
| 134 | + }) |
| 135 | + .unordered() |
| 136 | + .start(signal); |
| 137 | + // The fetch handler sends a message to the queue, which triggers the queue consumer |
| 138 | + await runner.makeRequest('get', '/queue/send'); |
| 139 | + await runner.completed(); |
| 140 | + |
| 141 | + expect(queueTraceId).toBeDefined(); |
| 142 | + expect(doTraceId).toBeDefined(); |
| 143 | + expect(queueTraceId).not.toBe(doTraceId); |
| 144 | + |
| 145 | + expect(queueSpanId).toBeDefined(); |
| 146 | + expect(doParentSpanId).toBeUndefined(); |
| 147 | +}); |
| 148 | + |
| 149 | +it('does not propagate trace from scheduled handler to durable object when enableRpcTracePropagation is disabled', async ({ |
| 150 | + signal, |
| 151 | +}) => { |
| 152 | + let scheduledTraceId: string | undefined; |
| 153 | + let scheduledSpanId: string | undefined; |
| 154 | + let doTraceId: string | undefined; |
| 155 | + let doParentSpanId: string | undefined; |
| 156 | + |
| 157 | + const runner = createRunner(__dirname) |
| 158 | + .withWranglerArgs('--test-scheduled') |
| 159 | + .expect(envelope => { |
| 160 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 161 | + |
| 162 | + expect(transactionEvent).toEqual( |
| 163 | + expect.objectContaining({ |
| 164 | + contexts: expect.objectContaining({ |
| 165 | + trace: expect.objectContaining({ |
| 166 | + op: 'http.server', |
| 167 | + data: expect.objectContaining({ |
| 168 | + 'sentry.origin': 'auto.http.cloudflare', |
| 169 | + }), |
| 170 | + origin: 'auto.http.cloudflare', |
| 171 | + }), |
| 172 | + }), |
| 173 | + transaction: 'GET /hello', |
| 174 | + }), |
| 175 | + ); |
| 176 | + doTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 177 | + doParentSpanId = transactionEvent.contexts?.trace?.parent_span_id as string; |
| 178 | + }) |
| 179 | + .expect(envelope => { |
| 180 | + const transactionEvent = envelope[1]?.[0]?.[1] as Event; |
| 181 | + |
| 182 | + expect(transactionEvent).toEqual( |
| 183 | + expect.objectContaining({ |
| 184 | + contexts: expect.objectContaining({ |
| 185 | + trace: expect.objectContaining({ |
| 186 | + op: 'faas.cron', |
| 187 | + data: expect.objectContaining({ |
| 188 | + 'sentry.origin': 'auto.faas.cloudflare.scheduled', |
| 189 | + }), |
| 190 | + origin: 'auto.faas.cloudflare.scheduled', |
| 191 | + }), |
| 192 | + }), |
| 193 | + }), |
| 194 | + ); |
| 195 | + scheduledTraceId = transactionEvent.contexts?.trace?.trace_id as string; |
| 196 | + scheduledSpanId = transactionEvent.contexts?.trace?.span_id as string; |
| 197 | + }) |
| 198 | + .unordered() |
| 199 | + .start(signal); |
| 200 | + await runner.makeRequest('get', '/__scheduled?cron=*+*+*+*+*'); |
| 201 | + await runner.completed(); |
| 202 | + |
| 203 | + expect(scheduledTraceId).toBeDefined(); |
| 204 | + expect(doTraceId).toBeDefined(); |
| 205 | + expect(scheduledTraceId).not.toBe(doTraceId); |
| 206 | + |
| 207 | + expect(scheduledSpanId).toBeDefined(); |
| 208 | + expect(doParentSpanId).toBeUndefined(); |
| 209 | +}); |
0 commit comments