Skip to content

Commit 44627a7

Browse files
author
alrex
authored
instrumentation/pymongo: Cast PyMongo commands as strings (#1132)
Replacement PR for #1015
1 parent ac35858 commit 44627a7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

instrumentation/opentelemetry-instrumentation-pymongo/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Cast PyMongo commands as strings
6+
([#1132](https://github.com/open-telemetry/opentelemetry-python/pull/1132))
7+
58
## Version 0.13b0
69

710
Released 2020-09-17

instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def started(self, event: monitoring.CommandStartedEvent):
6666
name = DATABASE_TYPE + "." + event.command_name
6767
statement = event.command_name
6868
if command:
69-
name += "." + command
70-
statement += " " + command
69+
name += "." + str(command)
70+
statement += " " + str(command)
7171

7272
try:
7373
span = self._tracer.start_span(name, kind=SpanKind.CLIENT)

instrumentation/opentelemetry-instrumentation-pymongo/tests/test_pymongo.py

+17
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,23 @@ def test_multiple_commands(self):
138138
trace_api.status.StatusCanonicalCode.UNKNOWN,
139139
)
140140

141+
def test_int_command(self):
142+
command_attrs = {
143+
"command_name": 123,
144+
}
145+
mock_event = MockEvent(command_attrs)
146+
147+
command_tracer = CommandTracer(self.tracer)
148+
command_tracer.started(event=mock_event)
149+
command_tracer.succeeded(event=mock_event)
150+
151+
spans_list = self.memory_exporter.get_finished_spans()
152+
153+
self.assertEqual(len(spans_list), 1)
154+
span = spans_list[0]
155+
156+
self.assertEqual(span.name, "mongodb.command_name.123")
157+
141158

142159
class MockCommand:
143160
def __init__(self, command_attrs):

0 commit comments

Comments
 (0)