Skip to content

Commit

Permalink
Add MetricInterceptor (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins authored Jun 21, 2024
1 parent cbf4e97 commit 7c44e7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashboard",
"version": "0.1.0",
"version": "0.4.23",
"private": true,
"homepage": "https://yorkie.dev/dashboard",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/api/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import pkg from '../../package.json';
import { Interceptor } from '@connectrpc/connect';

export class InterceptorBuilder {
Expand All @@ -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);
};
}
}

0 comments on commit 7c44e7c

Please sign in to comment.