Skip to content

Commit

Permalink
instrumentation/pymongo: Cast PyMongo commands as strings (#1132)
Browse files Browse the repository at this point in the history
Replacement PR for #1015
  • Loading branch information
alrex authored and codeboten committed Oct 23, 2020
1 parent 4bb0af9 commit 358a977
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def started(self, event: monitoring.CommandStartedEvent):
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,23 @@ def test_multiple_commands(self):
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):
Expand Down

0 comments on commit 358a977

Please sign in to comment.