| 34 | const GREETER = BindingKey.create<Greeter>('greeter'); |
| 35 | |
| 36 | @injectable(asGlobalInterceptor('tracing')) |
| 37 | class 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 | |
| 72 | class Converter { |
| 73 | toUpperCase(name: string) { |
nothing calls this directly
no test coverage detected