Skip to content

Commit

Permalink
Fix measuring duration metric on http error: add division by 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
jougene committed Jul 8, 2024
1 parent eb3b93c commit 95c3c03
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/http-client/http-client-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class HttpClientTemplate {
try {
const response = await this.httpClient.request<T>(config);

const end = Date.now();
const duration = (Date.now() - start) / 1000;

this.requestTime?.observe((end - start) / 1000, {
this.requestTime?.observe(duration, {
id: this.id,
method: config.method?.toUpperCase() ?? 'unknown',
uri: config.url ?? 'unknown',
Expand All @@ -57,6 +57,8 @@ export class HttpClientTemplate {

return response;
} catch (error) {
const duration = (Date.now() - start) / 1000;

let status = 'unknown';
let code = 'unknown';

Expand All @@ -76,7 +78,8 @@ export class HttpClientTemplate {
...commonLabels,
code,
});
this.requestTime?.observe(Date.now() - start, commonLabels);

this.requestTime?.observe(duration, commonLabels);

throw error;
}
Expand Down

0 comments on commit 95c3c03

Please sign in to comment.