Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import { ProxyTracerProvider } from '@opentelemetry/api';
2
3import SafeTracer from './SafeTracer.js';
4
5describe('SafeTracer', () => {
6 describe('traced', () => {
7 it('shuold run the underlying function with provided args, propagate return value', () => {
8 const fn = jest.fn<(it: unknown) => number>().mockReturnValue(1);
9 const tracer = new SafeTracer(
10 new ProxyTracerProvider().getTracer('noop'),
11 );
12 const traced = tracer.traced(
13 {
14 resource: 'test',
15 operation: 'something',
16 attributesFromArgs(args) {
17 // eslint-disable-next-line no-restricted-syntax
18 return { it: JSON.stringify(args) };
19 },
20 },
21 fn,
22 );
23
24 expect(traced('hello')).toBe(1);
25 expect(fn).toHaveBeenCalledWith('hello');
26 });
27 });
28});