@@ -31,11 +31,11 @@ import {Spanner} from '..';
3131 * by MetricsTracer to monitor and report metrics for each individual gRPC call attempt.
3232 */
3333class MetricAttemptTracer {
34- private _startTime : Date ;
34+ private _startTime : number ;
3535 public status : string ;
3636
3737 constructor ( ) {
38- this . _startTime = new Date ( Date . now ( ) ) ;
38+ this . _startTime = performance . now ( ) ;
3939 this . status = Status [ Status . UNKNOWN ] ;
4040 }
4141
@@ -67,12 +67,12 @@ class MetricAttemptTracer {
6767 */
6868class MetricOperationTracer {
6969 private _attemptCount : number ;
70- private _startTime : Date ;
70+ private _startTime : number ;
7171 private _currentAttempt : MetricAttemptTracer | null ;
7272
7373 constructor ( ) {
7474 this . _attemptCount = 0 ;
75- this . _startTime = new Date ( Date . now ( ) ) ;
75+ this . _startTime = performance . now ( ) ;
7676 this . _currentAttempt = null ;
7777 }
7878
@@ -173,13 +173,13 @@ export class MetricsTracer {
173173 }
174174
175175 /**
176- * Returns the difference in milliseconds between two Date objects .
176+ * Returns the difference in milliseconds between two times .
177177 * @param start The start time.
178178 * @param end The end time.
179179 * @returns The time difference in milliseconds.
180180 */
181- private _getMillisecondTimeDifference ( start : Date , end : Date ) : number {
182- return end . valueOf ( ) - start . valueOf ( ) ;
181+ private _getMillisecondTimeDifference ( start : number , end : number ) : number {
182+ return end - start ;
183183 }
184184
185185 /**
@@ -235,7 +235,7 @@ export class MetricsTracer {
235235 if ( ! this . enabled ) return ;
236236 this . currentOperation ! . currentAttempt ! . status = Status [ statusCode ] ;
237237 const attemptAttributes = this . _createAttemptOtelAttributes ( ) ;
238- const endTime = new Date ( Date . now ( ) ) ;
238+ const endTime = performance . now ( ) ;
239239 const attemptLatencyMilliseconds = this . _getMillisecondTimeDifference (
240240 this . currentOperation ! . currentAttempt ! . startTime ,
241241 endTime ,
@@ -265,7 +265,7 @@ export class MetricsTracer {
265265 */
266266 public recordOperationCompletion ( ) {
267267 if ( ! this . enabled || ! this . currentOperation ) return ;
268- const endTime = new Date ( Date . now ( ) ) ;
268+ const endTime = performance . now ( ) ;
269269 const operationAttributes = this . _createOperationOtelAttributes ( ) ;
270270 const operationLatencyMilliseconds = this . _getMillisecondTimeDifference (
271271 this . currentOperation ! . startTime ,
0 commit comments