Skip to content

Commit 5371b7a

Browse files
authored
[receiver/sqlserver] Update event properties (#39868)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description * Update event name of top query event to `db.server.top_query` * Update event name of query sample event to `db.server.query_sample` * Remove body of query sample event * Rename `sqlserver.username` to `user.name` in query sample event <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue n/a <!--Describe what testing was performed and which tests were added.--> #### Testing Updated <!--Describe the documentation added.--> #### Documentation Added <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 73ec32b commit 5371b7a

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

.chloggen/sqlserver-update-props.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: sqlserverreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Update event properties
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39868]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This change only applies to top query events and query sample events:
20+
* Update event name of top query event from `top query` to `db.server.top_query`
21+
* Update event name of query sample event from `query sample` to `db.server.query_sample`
22+
* Remove body of query sample event
23+
* Rename `sqlserver.username` to `user.name` in query sample event
24+
25+
# If your change doesn't affect end users or the exported elements of any package,
26+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
27+
# Optional: The change log or logs in which this entry should be included.
28+
# e.g. '[user]' or '[user, api]'
29+
# Include 'user' if the change is relevant to end users.
30+
# Include 'api' if there is a change to a library API.
31+
# Default: '[user]'
32+
change_logs: [user]

receiver/sqlserverreceiver/scraper.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ func (s *sqlServerScraperHelper) recordDatabaseStatusMetrics(ctx context.Context
508508
func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Context, topQueryCount uint) (pcommon.Resource, error) {
509509
// Constants are the column names of the database status
510510
const (
511+
eventName = "db.server.top_query"
511512
dbPrefix = "sqlserver."
512513
executionCount = "execution_count"
513514
logicalReads = "total_logical_reads"
@@ -581,7 +582,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont
581582

582583
record := plog.NewLogRecord()
583584
record.SetTimestamp(timestamp)
584-
record.SetEventName("top query")
585+
record.SetEventName(eventName)
585586

586587
attributes := []internalAttribute{
587588
{
@@ -868,6 +869,7 @@ func setDouble(attributes pcommon.Map, key string, value any) {
868869
}
869870

870871
func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context) (pcommon.Resource, error) {
872+
const eventName = "db.server.query_sample"
871873
const blockingSessionID = "blocking_session_id"
872874
const clientAddress = "client_address"
873875
const clientPort = "client_port"
@@ -925,6 +927,7 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
925927

926928
record := plog.NewLogRecord()
927929
record.SetTimestamp(pcommon.NewTimestampFromTime(time.Now()))
930+
record.SetEventName(eventName)
928931

929932
// Attributes sorted alphabetically by key
930933
attributes := []internalAttribute{
@@ -1093,7 +1096,7 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
10931096
valueSetter: setInt,
10941097
},
10951098
{
1096-
key: dbPrefix + username,
1099+
key: "user.name",
10971100
columnName: username,
10981101
valueRetriever: vanillaRetriever,
10991102
valueSetter: setString,
@@ -1160,9 +1163,6 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
11601163
record.Attributes().PutStr("client.address", row[clientAddress])
11611164
}
11621165

1163-
record.SetEventName("query sample")
1164-
1165-
record.Body().SetStr("sample")
11661166
s.lb.AppendLogRecord(record)
11671167

11681168
if !resourcesAdded {

receiver/sqlserverreceiver/scraper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func TestQueryTextAndPlanQuery(t *testing.T) {
385385
// golden.WriteLogs(t, expectedFile, actualLogs)
386386
expectedLogs, _ := golden.ReadLogs(expectedFile)
387387
errs := plogtest.CompareLogs(expectedLogs, actualLogs, plogtest.IgnoreTimestamp())
388-
assert.Equal(t, "top query", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
388+
assert.Equal(t, "db.server.top_query", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
389389
assert.NoError(t, errs)
390390
}
391391

@@ -505,7 +505,7 @@ func TestRecordDatabaseSampleQuery(t *testing.T) {
505505
expectedLogs, err := golden.ReadLogs(filepath.Join("testdata", tc.expectedFile))
506506
assert.NoError(t, err)
507507
errs := plogtest.CompareLogs(expectedLogs, actualLogs, plogtest.IgnoreTimestamp())
508-
assert.Equal(t, "query sample", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
508+
assert.Equal(t, "db.server.query_sample", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
509509
assert.NoError(t, errs)
510510
})
511511
}

receiver/sqlserverreceiver/testdata/expectedQueryTextAndPlanQuery.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ resourceLogs:
5959
value:
6060
intValue: "1433"
6161
body: {}
62-
eventName: top query
62+
eventName: db.server.top_query
6363
spanId: ""
6464
timeUnixNano: "1746443457006291000"
6565
traceId: ""

receiver/sqlserverreceiver/testdata/expectedRecordDatabaseSampleQuery.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ resourceLogs:
9191
- key: sqlserver.transaction_isolation_level
9292
value:
9393
intValue: "2"
94-
- key: sqlserver.username
94+
- key: user.name
9595
value:
9696
stringValue: sa
9797
- key: sqlserver.wait_resource
@@ -109,9 +109,8 @@ resourceLogs:
109109
- key: client.address
110110
value:
111111
stringValue: DESKTOP-GHAEGRD
112-
body:
113-
stringValue: sample
114-
eventName: query sample
112+
body: {}
113+
eventName: db.server.query_sample
115114
spanId: a7ad6a7169203331
116115
timeUnixNano: "1746443501202499000"
117116
traceId: 0af7651916cd43dd8448eb211c80319c

receiver/sqlserverreceiver/testdata/expectedRecordDatabaseSampleQueryWithInvalidData.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ resourceLogs:
9191
- key: sqlserver.transaction_isolation_level
9292
value:
9393
intValue: "0"
94-
- key: sqlserver.username
94+
- key: user.name
9595
value:
9696
stringValue: sa
9797
- key: sqlserver.wait_resource
@@ -112,9 +112,8 @@ resourceLogs:
112112
- key: client.address
113113
value:
114114
stringValue: DESKTOP-GHAEGRD
115-
body:
116-
stringValue: sample
117-
eventName: query sample
115+
body: {}
116+
eventName: db.server.query_sample
118117
spanId: ""
119118
timeUnixNano: "1746443501199160000"
120119
traceId: ""

0 commit comments

Comments
 (0)