chore: Move tracing decorators into the codebase (#4623)
* Vendorize tracing, finally fix service name issues * Upgrade datadaog-metrics, rename decorators -> tracing * lint
This commit is contained in:
39
server/__mocks__/dd-trace.ts
Normal file
39
server/__mocks__/dd-trace.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||
import { Tracer } from "dd-trace";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
const emptyFn = function () {};
|
||||
|
||||
const callableHandlers = {
|
||||
get<T, P extends keyof T>(_target: T, _prop: P, _receiver: any): T[P] {
|
||||
const newMock = new Proxy(emptyFn, callableHandlers);
|
||||
return (newMock as any) as T[P];
|
||||
},
|
||||
|
||||
apply<T extends (...args: any) => any, A extends Parameters<T>>(
|
||||
_target: T,
|
||||
_thisArg: any,
|
||||
_args: A
|
||||
): ReturnType<T> {
|
||||
const newMock = new Proxy(emptyFn, callableHandlers);
|
||||
return (newMock as any) as ReturnType<T>;
|
||||
},
|
||||
};
|
||||
|
||||
const callableMock = new Proxy(emptyFn, callableHandlers);
|
||||
|
||||
type MockTracer = Tracer & { isMock?: boolean };
|
||||
|
||||
export const mockTracer = new Proxy({} as MockTracer, {
|
||||
get<K extends keyof MockTracer>(_target: Tracer, key: K) {
|
||||
if (key === "isMock") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (key === "wrap") {
|
||||
return (_: any, f: any) => f;
|
||||
}
|
||||
|
||||
return callableMock;
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user