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