Skip to content

Commit f189493

Browse files
nenadnoveljicrootJustin
authored
Add context_info to SQL Server activity samples (DBMON-4106) (#17648)
* Add context_info to activity samples * change log entry * removed change log entry * Update sqlserver/tests/test_activity.py Co-authored-by: Justin <justin.james.iso@gmail.com> * linter errors --------- Co-authored-by: root <root@ip-172-29-198-131.ec2.internal> Co-authored-by: Justin <justin.james.iso@gmail.com>
1 parent f4ce53a commit f189493

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

sqlserver/datadog_checks/sqlserver/activity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"row_count",
137137
"query_hash",
138138
"query_plan_hash",
139+
"context_info",
139140
]
140141

141142

@@ -333,6 +334,10 @@ def _sanitize_row(row, obfuscated_statement=None):
333334
# remove deobfuscated sql text from event
334335
if 'statement_text' in row:
335336
del row['statement_text']
337+
# convert `context_info` to string, since the default decoding format
338+
# for json is utf-8, and `context_info` need not comply to utf-8
339+
if 'context_info' in row:
340+
row['context_info'] = row['context_info'].hex()
336341
return row
337342

338343
@staticmethod

sqlserver/tests/test_activity.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ def test_collect_load_activity(
9999
def run_test_query(c, q):
100100
cur = c.cursor()
101101
cur.execute("USE {}".format(database))
102+
# 0xFF can't be decoded to Unicode, which makes it good test data,
103+
# since Unicode is a default format
104+
cur.execute("SET CONTEXT_INFO 0xff")
102105
cur.execute(q)
103106

104107
# run the test query once before the blocking test to ensure that if it's
@@ -164,6 +167,7 @@ def run_test_query(c, q):
164167
assert blocked_row['procedure_name'], "missing procedure name"
165168
assert re.match(match_pattern, blocked_row['text'], re.IGNORECASE), "incorrect blocked query"
166169
assert blocked_row['database_name'] == "datadog_test", "incorrect database_name"
170+
assert blocked_row['context_info'] == "ff", "incorrect context_info"
167171
assert blocked_row['id'], "missing session id"
168172
assert blocked_row['now'], "missing current timestamp"
169173
assert blocked_row['last_request_start_time'], "missing last_request_start_time"

0 commit comments

Comments
 (0)