MCPcopy Index your code
hub / github.com/loopbackio/loopback-next / TracingInterceptor

Class TracingInterceptor

examples/context/src/interceptor-proxy.ts:36–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34const GREETER = BindingKey.create<Greeter>('greeter');
35
36@injectable(asGlobalInterceptor('tracing'))
37class TracingInterceptor implements Provider<Interceptor> {
38 constructor(
39 @inject(REQUEST_ID_GENERATOR) private generator: RequestIdGenerator,
40 ) {}
41
42 value() {
43 return this.intercept.bind(this);
44 }
45
46 async intercept<T>(
47 invocationCtx: InvocationContext,
48 next: () => ValueOrPromise<T>,
49 ) {
50 const reqCtx = invocationCtx.getSync(REQUEST_CONTEXT);
51 let reqId = await reqCtx.get(REQUEST_ID, {optional: true});
52 if (!reqId) {
53 reqId = this.generator(reqCtx);
54 // We need to set request id to `reqCtx` as `invocationCtx` is transient
55 reqCtx.bind(REQUEST_ID).to(reqId);
56 console.log(
57 'Adding request id at %s: %s',
58 invocationCtx.targetName,
59 reqId,
60 );
61 } else {
62 console.log(
63 'Request id found at %s: %s',
64 invocationCtx.targetName,
65 reqId,
66 );
67 }
68 return next();
69 }
70}
71
72class Converter {
73 toUpperCase(name: string) {

Callers

nothing calls this directly

Calls 2

injectableFunction · 0.90
asGlobalInterceptorFunction · 0.90

Tested by

no test coverage detected