mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-01 17:34:38 +08:00
instrumentation/pymongo: Cast PyMongo commands as strings (#1132)
Replacement PR for #1015
This commit is contained in:
@ -2,6 +2,9 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Cast PyMongo commands as strings
|
||||
([#1132](https://github.com/open-telemetry/opentelemetry-python/pull/1132))
|
||||
|
||||
## Version 0.13b0
|
||||
|
||||
Released 2020-09-17
|
||||
|
@ -66,8 +66,8 @@ class CommandTracer(monitoring.CommandListener):
|
||||
name = DATABASE_TYPE + "." + event.command_name
|
||||
statement = event.command_name
|
||||
if command:
|
||||
name += "." + command
|
||||
statement += " " + command
|
||||
name += "." + str(command)
|
||||
statement += " " + str(command)
|
||||
|
||||
try:
|
||||
span = self._tracer.start_span(name, kind=SpanKind.CLIENT)
|
||||
|
@ -138,6 +138,23 @@ class TestPymongo(TestBase):
|
||||
trace_api.status.StatusCanonicalCode.UNKNOWN,
|
||||
)
|
||||
|
||||
def test_int_command(self):
|
||||
command_attrs = {
|
||||
"command_name": 123,
|
||||
}
|
||||
mock_event = MockEvent(command_attrs)
|
||||
|
||||
command_tracer = CommandTracer(self.tracer)
|
||||
command_tracer.started(event=mock_event)
|
||||
command_tracer.succeeded(event=mock_event)
|
||||
|
||||
spans_list = self.memory_exporter.get_finished_spans()
|
||||
|
||||
self.assertEqual(len(spans_list), 1)
|
||||
span = spans_list[0]
|
||||
|
||||
self.assertEqual(span.name, "mongodb.command_name.123")
|
||||
|
||||
|
||||
class MockCommand:
|
||||
def __init__(self, command_attrs):
|
||||
|
Reference in New Issue
Block a user