Skip to content

Add db.operation to Redis and MongoDB spans. #2089

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 9, 2023
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
9 changes: 8 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ class SPANDATA:
See: https://develop.sentry.dev/sdk/performance/span-data-conventions/
"""

DB_OPERATION = "db.operation"
"""
The name of the operation being executed, e.g. the MongoDB command name such as findAndModify, or the SQL keyword.
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
Example: findAndModify, HMSET, SELECT
"""

DB_SYSTEM = "db.system"
"""
An identifier for the database management system (DBMS) product being used.
See: https://github.com/open-telemetry/opentelemetry-specification/blob/24de67b3827a4e3ab2515cd8ab62d5bcf837c586/specification/trace/semantic_conventions/database.md
See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/database.md
Example: postgresql
"""

Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/integrations/pymongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def started(self, event):

tags = {
"db.name": event.database_name,
"db.system": "mongodb",
"db.operation": event.command_name,
SPANDATA.DB_SYSTEM: "mongodb",
SPANDATA.DB_OPERATION: event.command_name,
}

try:
Expand Down
1 change: 1 addition & 0 deletions sentry_sdk/integrations/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):

if name:
span.set_tag("redis.command", name)
span.set_tag(SPANDATA.DB_OPERATION, name)

if name and args:
name_low = name.lower()
Expand Down
3 changes: 3 additions & 0 deletions tests/integrations/redis/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_basic(sentry_init, capture_events):
"redis.key": "foobar",
"redis.command": "GET",
"redis.is_cluster": False,
"db.operation": "GET",
},
"timestamp": crumb["timestamp"],
"type": "redis",
Expand Down Expand Up @@ -207,6 +208,7 @@ def test_breadcrumbs(sentry_init, capture_events):
"type": "redis",
"category": "redis",
"data": {
"db.operation": "SET",
"redis.is_cluster": False,
"redis.command": "SET",
"redis.key": "somekey1",
Expand All @@ -218,6 +220,7 @@ def test_breadcrumbs(sentry_init, capture_events):
"type": "redis",
"category": "redis",
"data": {
"db.operation": "SET",
"redis.is_cluster": False,
"redis.command": "SET",
"redis.key": "somekey2",
Expand Down
1 change: 1 addition & 0 deletions tests/integrations/rediscluster/test_rediscluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_rediscluster_basic(rediscluster_cls, sentry_init, capture_events):
"category": "redis",
"message": "GET 'foobar'",
"data": {
"db.operation": "GET",
"redis.key": "foobar",
"redis.command": "GET",
"redis.is_cluster": True,
Expand Down