Skip to content

Commit 8e54ec1

Browse files
authored
[chore] [receiverr/sqlserver] add event name and update time unit (#39027)
according to the convetion, we should use `s` instead of `ms`. https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/metrics.md#instrument-units > When instruments are measuring durations, seconds (i.e. s) SHOULD be used. add event name to help identify the records /cc @XSAM
1 parent 0c27c2f commit 8e54ec1

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

Diff for: receiver/sqlserverreceiver/logs-documentation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
| Attributes | Description | Type |
44
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------|
5-
| sqlserver.total_elapsed_time | Total elapsed time, reported in milliseconds, for completed executions of this plan.<br> | int |
5+
| sqlserver.total_elapsed_time | Total elapsed time, reported in second, for completed executions of this plan.<br> | float |
66
| sqlserver.total_rows | Total number of rows returned by the query. Can't be null.<br><br>Always 0 when a natively compiled stored procedure queries a memory-optimized table. | int |
7-
| sqlserver.total_worker_time | Total amount of CPU time, reported in milliseconds, that was consumed by executions of this plan since it was compiled.<br><br>For natively compiled stored procedures, total_worker_time might not be accurate if many executions take less than 1 millisecond. | int |
7+
| sqlserver.total_worker_time | Total amount of CPU time, reported in seconds, that was consumed by executions of this plan since it was compiled.<br><br>For natively compiled stored procedures, total_worker_time might not be accurate if many executions take less than 1 millisecond. | float |
88
| sqlserver.total_logical_reads | Total number of logical reads performed by executions of this plan since it was compiled.<br><br>Always 0 when querying a memory-optimized table. | int |
99
| sqlserver.total_logical_writes | Total number of logical writes performed by executions of this plan since it was compiled.<br><br>Always 0 when querying a memory-optimized table. | int |
1010
| sqlserver.total_physical_reads | Total number of physical reads performed by executions of this plan since it was compiled.<br><br>Always 0 when querying a memory-optimized table. | int |

Diff for: receiver/sqlserverreceiver/scraper.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
572572

573573
record := scopedLog.LogRecords().AppendEmpty()
574574
record.SetTimestamp(timestamp)
575+
record.SetEventName("top query")
575576
record.Attributes().PutStr("db.system.name", "microsoft.sql_server")
576577

577578
record.Attributes().PutStr(computerNameKey, row[computerNameKey])
@@ -584,7 +585,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
584585

585586
s.logger.Debug(fmt.Sprintf("QueryHash: %v, PlanHash: %v, DataRow: %v", queryHashVal, queryPlanHashVal, row))
586587

587-
record.Attributes().PutInt(dbPrefix+totalElapsedTime, totalElapsedTimeDiffs[i])
588+
record.Attributes().PutDouble(dbPrefix+totalElapsedTime, float64(totalElapsedTimeDiffs[i])/1000)
588589

589590
// handling `total_rows`
590591
rowsReturnVal, err := strconv.ParseInt(row[rowsReturned], 10, 64)
@@ -644,7 +645,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
644645
errs = append(errs, err)
645646
} else {
646647
if cached, diff := s.cacheAndDiff(queryHashVal, queryPlanHashVal, totalWorkerTime, workerTime/1000); cached {
647-
record.Attributes().PutInt(dbPrefix+totalWorkerTime, diff)
648+
record.Attributes().PutDouble(dbPrefix+totalWorkerTime, float64(diff)/1000)
648649
}
649650
}
650651

Diff for: receiver/sqlserverreceiver/scraper_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ func TestQueryTextAndPlanQuery(t *testing.T) {
394394
// golden.WriteLogs(t, expectedFile, actualLogs)
395395
expectedLogs, _ := golden.ReadLogs(expectedFile)
396396
errs := plogtest.CompareLogs(expectedLogs, actualLogs, plogtest.IgnoreTimestamp())
397+
assert.Equal(t, "top query", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
397398
assert.NoError(t, errs)
398399
}
399400

Diff for: receiver/sqlserverreceiver/testdata/expectedQueryTextAndPlanQuery.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ resourceLogs:
2727
stringValue: "307844333131323930393432394131423530"
2828
- key: sqlserver.total_elapsed_time
2929
value:
30-
intValue: "2"
30+
doubleValue: "0.002"
3131
- key: sqlserver.total_rows
3232
value:
3333
intValue: "1"
@@ -45,7 +45,7 @@ resourceLogs:
4545
intValue: "5"
4646
- key: sqlserver.total_worker_time
4747
value:
48-
intValue: "2"
48+
doubleValue: "0.002"
4949
- key: sqlserver.total_grant_kb
5050
value:
5151
intValue: "3095"
@@ -59,6 +59,7 @@ resourceLogs:
5959
spanId: ""
6060
timeUnixNano: "1739690452135336000"
6161
traceId: ""
62+
eventName: "query event"
6263
scope:
6364
name: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver
6465
version: 0.0.1

0 commit comments

Comments
 (0)