Skip to content

[receiver/sqlserver] Update event properties #39868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .chloggen/sqlserver-update-props.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: sqlserverreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update event properties

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [39868]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
This change only applies to top query events and query sample events:
* Update event name of top query event from `top query` to `db.server.top_query`
* Update event name of query sample event from `query sample` to `db.server.query_sample`
* Remove body of query sample event
* Rename `sqlserver.username` to `user.name` in query sample event

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
10 changes: 5 additions & 5 deletions receiver/sqlserverreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func (s *sqlServerScraperHelper) recordDatabaseStatusMetrics(ctx context.Context
func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Context, topQueryCount uint) (pcommon.Resource, error) {
// Constants are the column names of the database status
const (
eventName = "db.server.top_query"
dbPrefix = "sqlserver."
executionCount = "execution_count"
logicalReads = "total_logical_reads"
Expand Down Expand Up @@ -581,7 +582,7 @@ func (s *sqlServerScraperHelper) recordDatabaseQueryTextAndPlan(ctx context.Cont

record := plog.NewLogRecord()
record.SetTimestamp(timestamp)
record.SetEventName("top query")
record.SetEventName(eventName)

attributes := []internalAttribute{
{
Expand Down Expand Up @@ -868,6 +869,7 @@ func setDouble(attributes pcommon.Map, key string, value any) {
}

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

record := plog.NewLogRecord()
record.SetTimestamp(pcommon.NewTimestampFromTime(time.Now()))
record.SetEventName(eventName)

// Attributes sorted alphabetically by key
attributes := []internalAttribute{
Expand Down Expand Up @@ -1093,7 +1096,7 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
valueSetter: setInt,
},
{
key: dbPrefix + username,
key: "user.name",
columnName: username,
valueRetriever: vanillaRetriever,
valueSetter: setString,
Expand Down Expand Up @@ -1160,9 +1163,6 @@ func (s *sqlServerScraperHelper) recordDatabaseSampleQuery(ctx context.Context)
record.Attributes().PutStr("client.address", row[clientAddress])
}

record.SetEventName("query sample")

record.Body().SetStr("sample")
s.lb.AppendLogRecord(record)

if !resourcesAdded {
Expand Down
4 changes: 2 additions & 2 deletions receiver/sqlserverreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func TestQueryTextAndPlanQuery(t *testing.T) {
// golden.WriteLogs(t, expectedFile, actualLogs)
expectedLogs, _ := golden.ReadLogs(expectedFile)
errs := plogtest.CompareLogs(expectedLogs, actualLogs, plogtest.IgnoreTimestamp())
assert.Equal(t, "top query", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
assert.Equal(t, "db.server.top_query", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
assert.NoError(t, errs)
}

Expand Down Expand Up @@ -505,7 +505,7 @@ func TestRecordDatabaseSampleQuery(t *testing.T) {
expectedLogs, err := golden.ReadLogs(filepath.Join("testdata", tc.expectedFile))
assert.NoError(t, err)
errs := plogtest.CompareLogs(expectedLogs, actualLogs, plogtest.IgnoreTimestamp())
assert.Equal(t, "query sample", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
assert.Equal(t, "db.server.query_sample", actualLogs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).EventName())
assert.NoError(t, errs)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resourceLogs:
value:
intValue: "1433"
body: {}
eventName: top query
eventName: db.server.top_query
spanId: ""
timeUnixNano: "1746443457006291000"
traceId: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ resourceLogs:
- key: sqlserver.transaction_isolation_level
value:
intValue: "2"
- key: sqlserver.username
- key: user.name
value:
stringValue: sa
- key: sqlserver.wait_resource
Expand All @@ -109,9 +109,8 @@ resourceLogs:
- key: client.address
value:
stringValue: DESKTOP-GHAEGRD
body:
stringValue: sample
eventName: query sample
body: {}
eventName: db.server.query_sample
spanId: a7ad6a7169203331
timeUnixNano: "1746443501202499000"
traceId: 0af7651916cd43dd8448eb211c80319c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ resourceLogs:
- key: sqlserver.transaction_isolation_level
value:
intValue: "0"
- key: sqlserver.username
- key: user.name
value:
stringValue: sa
- key: sqlserver.wait_resource
Expand All @@ -112,9 +112,8 @@ resourceLogs:
- key: client.address
value:
stringValue: DESKTOP-GHAEGRD
body:
stringValue: sample
eventName: query sample
body: {}
eventName: db.server.query_sample
spanId: ""
timeUnixNano: "1746443501199160000"
traceId: ""
Expand Down
Loading