|
| 1 | +const { loggingTransport } = require('@sentry-internal/node-integration-tests'); |
| 2 | +const Sentry = require('@sentry/node'); |
| 3 | + |
| 4 | +Sentry.init({ |
| 5 | + dsn: 'https://[email protected]/1337', |
| 6 | + release: '1.0', |
| 7 | + tracesSampleRate: 1.0, |
| 8 | + transport: loggingTransport, |
| 9 | +}); |
| 10 | + |
| 11 | +// Stop the process from exiting before the transaction is sent |
| 12 | +setInterval(() => {}, 1000); |
| 13 | + |
| 14 | +const run = async () => { |
| 15 | + // Test ported from the OTEL implementation: |
| 16 | + // https://github.com/open-telemetry/opentelemetry-js-contrib/blob/0d6ebded313bb75b5a0e7a6422206c922daf3943/plugins/node/instrumentation-lru-memoizer/test/index.test.ts#L28 |
| 17 | + const memoizer = require('lru-memoizer'); |
| 18 | + |
| 19 | + let memoizerLoadCallback; |
| 20 | + const memoizedFoo = memoizer({ |
| 21 | + load: (_param, callback) => { |
| 22 | + memoizerLoadCallback = callback; |
| 23 | + }, |
| 24 | + hash: () => 'bar', |
| 25 | + }); |
| 26 | + |
| 27 | + Sentry.startSpan({ op: 'run' }, async span => { |
| 28 | + const outerSpanContext = span.spanContext(); |
| 29 | + |
| 30 | + memoizedFoo({ foo: 'bar' }, () => { |
| 31 | + const innerContext = Sentry.getActiveSpan().spanContext(); |
| 32 | + |
| 33 | + // The span context should be the same as the outer span |
| 34 | + // Throwing an error here will cause the test to fail |
| 35 | + if (outerSpanContext !== innerContext) { |
| 36 | + throw new Error('Outer and inner span context should match'); |
| 37 | + } |
| 38 | + }); |
| 39 | + |
| 40 | + span.end(); |
| 41 | + }); |
| 42 | + |
| 43 | + // Invoking the load callback outside the span |
| 44 | + memoizerLoadCallback(); |
| 45 | +}; |
| 46 | + |
| 47 | +run(); |
0 commit comments