Skip to content

Commit 4b6a381

Browse files
authored
Add db.operation to Redis and MongoDB spans. (#2089)
* Set db.operation in Redis and MongoDB spans
1 parent e777e53 commit 4b6a381

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

sentry_sdk/consts.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ class SPANDATA:
5757
See: https://develop.sentry.dev/sdk/performance/span-data-conventions/
5858
"""
5959

60+
DB_OPERATION = "db.operation"
61+
"""
62+
The name of the operation being executed, e.g. the MongoDB command name such as findAndModify, or the SQL keyword.
63+
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
64+
Example: findAndModify, HMSET, SELECT
65+
"""
66+
6067
DB_SYSTEM = "db.system"
6168
"""
6269
An identifier for the database management system (DBMS) product being used.
63-
See: https://github.com/open-telemetry/opentelemetry-specification/blob/24de67b3827a4e3ab2515cd8ab62d5bcf837c586/specification/trace/semantic_conventions/database.md
70+
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
6471
Example: postgresql
6572
"""
6673

sentry_sdk/integrations/pymongo.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def started(self, event):
110110

111111
tags = {
112112
"db.name": event.database_name,
113-
"db.system": "mongodb",
114-
"db.operation": event.command_name,
113+
SPANDATA.DB_SYSTEM: "mongodb",
114+
SPANDATA.DB_OPERATION: event.command_name,
115115
}
116116

117117
try:

sentry_sdk/integrations/redis.py

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):
196196

197197
if name:
198198
span.set_tag("redis.command", name)
199+
span.set_tag(SPANDATA.DB_OPERATION, name)
199200

200201
if name and args:
201202
name_low = name.lower()

tests/integrations/redis/test_redis.py

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_basic(sentry_init, capture_events):
2727
"redis.key": "foobar",
2828
"redis.command": "GET",
2929
"redis.is_cluster": False,
30+
"db.operation": "GET",
3031
},
3132
"timestamp": crumb["timestamp"],
3233
"type": "redis",
@@ -207,6 +208,7 @@ def test_breadcrumbs(sentry_init, capture_events):
207208
"type": "redis",
208209
"category": "redis",
209210
"data": {
211+
"db.operation": "SET",
210212
"redis.is_cluster": False,
211213
"redis.command": "SET",
212214
"redis.key": "somekey1",
@@ -218,6 +220,7 @@ def test_breadcrumbs(sentry_init, capture_events):
218220
"type": "redis",
219221
"category": "redis",
220222
"data": {
223+
"db.operation": "SET",
221224
"redis.is_cluster": False,
222225
"redis.command": "SET",
223226
"redis.key": "somekey2",

tests/integrations/rediscluster/test_rediscluster.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_rediscluster_basic(rediscluster_cls, sentry_init, capture_events):
4343
"category": "redis",
4444
"message": "GET 'foobar'",
4545
"data": {
46+
"db.operation": "GET",
4647
"redis.key": "foobar",
4748
"redis.command": "GET",
4849
"redis.is_cluster": True,

0 commit comments

Comments
 (0)