From f5e882eb283e353c2da7a360b90da22d8a12ce35 Mon Sep 17 00:00:00 2001 From: Youngteac Hong Date: Fri, 21 Jun 2024 14:39:56 +0900 Subject: [PATCH] Add MetricInterceptor --- package.json | 2 +- src/api/index.ts | 2 +- src/api/interceptor.ts | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6d3f36a..f7d19ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dashboard", - "version": "0.1.0", + "version": "0.4.23", "private": true, "homepage": "https://yorkie.dev/dashboard", "dependencies": { diff --git a/src/api/index.ts b/src/api/index.ts index 809362c..5d0f306 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -29,7 +29,7 @@ export * from './types'; const interceptor = new InterceptorBuilder(); const transport = createGrpcWebTransport({ baseUrl: process.env.REACT_APP_API_ADDR!, - interceptors: [interceptor.createAuthInterceptor()], + interceptors: [interceptor.createAuthInterceptor(), interceptor.createMetricInterceptor()], defaultTimeoutMs: 3000, }); const client = createPromiseClient(AdminService, transport); diff --git a/src/api/interceptor.ts b/src/api/interceptor.ts index 5e7bbac..65a1d08 100644 --- a/src/api/interceptor.ts +++ b/src/api/interceptor.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import pkg from '../../package.json'; import { Interceptor } from '@connectrpc/connect'; export class InterceptorBuilder { @@ -39,4 +40,15 @@ export class InterceptorBuilder { return await next(req); }; } + + /** + * `createMetricInterceptor` creates an interceptor to add the x-yorkie-user-agent header for each + * request. + */ + createMetricInterceptor(): Interceptor { + return (next) => async (req) => { + req.header.set('x-yorkie-user-agent', pkg.name + '/' + pkg.version); + return await next(req); + }; + } }