Skip to content

Commit a027510

Browse files
committed
Fix ExecContext telemetry timing: Capture start time before query execution
This addresses the second part of @vikrantpuppala's review comment: "shouldn't this be before runQuery?" Changes: - Capture executeStart = time.Now() BEFORE calling runQuery() - Use BeforeExecuteWithTime() with the pre-captured timestamp - Ensures telemetry measures actual query execution time accurately Without this fix, telemetry would miss ~100-1000μs of execution time (the time between query start and getting the operation handle). Now ExecContext matches the pattern already implemented in QueryContext.
1 parent 746974e commit a027510

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
123123

124124
corrId := driverctx.CorrelationIdFromContext(ctx)
125125

126+
// Capture execution start time for telemetry before running the query
127+
executeStart := time.Now()
126128
exStmtResp, opStatusResp, err := c.runQuery(ctx, query, args)
127129
log, ctx = client.LoggerAndContext(ctx, exStmtResp)
128130
stagingErr := c.execStagingOperation(exStmtResp, ctx)
@@ -132,7 +134,8 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
132134
var closeOpErr error // Track CloseOperation errors for telemetry
133135
if c.telemetry != nil && exStmtResp != nil && exStmtResp.OperationHandle != nil && exStmtResp.OperationHandle.OperationId != nil {
134136
statementID = client.SprintGuid(exStmtResp.OperationHandle.OperationId.GUID)
135-
ctx = c.telemetry.BeforeExecute(ctx, statementID)
137+
// Use BeforeExecuteWithTime to set the correct start time (before execution)
138+
ctx = c.telemetry.BeforeExecuteWithTime(ctx, c.id, statementID, executeStart)
136139
defer func() {
137140
finalErr := err
138141
if stagingErr != nil {

0 commit comments

Comments
 (0)