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:
Tom Moor
2022-12-31 12:54:51 +00:00
committed by GitHub
parent 1e036ebd0e
commit c6fb764631
26 changed files with 501 additions and 190 deletions

View 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;
},
});