Exemple #1
0
    def test_started(self):
        command_attrs = {
            "filter": "filter",
            "sort": "sort",
            "limit": "limit",
            "pipeline": "pipeline",
            "command_name": "find",
        }
        command_tracer = CommandTracer(self.tracer)
        mock_event = MockEvent(command_attrs, ("test.com", "1234"),
                               "test_request_id")
        command_tracer.started(event=mock_event)
        # the memory exporter can't be used here because the span isn't ended
        # yet
        # pylint: disable=protected-access
        span = command_tracer._pop_span(mock_event)
        self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
        self.assertEqual(span.name, "mongodb.command_name.find")
        self.assertEqual(span.attributes["component"], "mongodb")
        self.assertEqual(span.attributes["db.type"], "mongodb")
        self.assertEqual(span.attributes["db.instance"], "database_name")
        self.assertEqual(span.attributes["db.statement"], "command_name find")
        self.assertEqual(span.attributes["net.peer.name"], "test.com")
        self.assertEqual(span.attributes["net.peer.port"], "1234")
        self.assertEqual(span.attributes["db.mongo.operation_id"],
                         "operation_id")
        self.assertEqual(span.attributes["db.mongo.request_id"],
                         "test_request_id")

        self.assertEqual(span.attributes["db.mongo.filter"], "filter")
        self.assertEqual(span.attributes["db.mongo.sort"], "sort")
        self.assertEqual(span.attributes["db.mongo.limit"], "limit")
        self.assertEqual(span.attributes["db.mongo.pipeline"], "pipeline")
 def test_started(self):
     command_attrs = {
         "command_name": "find",
     }
     command_tracer = CommandTracer(self.tracer)
     mock_event = MockEvent(command_attrs, ("test.com", "1234"),
                            "test_request_id")
     command_tracer.started(event=mock_event)
     # the memory exporter can't be used here because the span isn't ended
     # yet
     # pylint: disable=protected-access
     span = command_tracer._pop_span(mock_event)
     self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
     self.assertEqual(span.name, "command_name.find")
     self.assertEqual(span.attributes["db.system"], "mongodb")
     self.assertEqual(span.attributes["db.name"], "database_name")
     self.assertEqual(span.attributes["db.statement"], "command_name find")
     self.assertEqual(span.attributes["net.peer.name"], "test.com")
     self.assertEqual(span.attributes["net.peer.port"], "1234")
 def test_started(self):
     command_attrs = {
         "command_name": "find",
     }
     command_tracer = CommandTracer(self.tracer,
                                    request_hook=self.start_callback)
     mock_event = MockEvent(command_attrs, ("test.com", "1234"),
                            "test_request_id")
     command_tracer.started(event=mock_event)
     # the memory exporter can't be used here because the span isn't ended
     # yet
     # pylint: disable=protected-access
     span = command_tracer._pop_span(mock_event)
     self.assertIs(span.kind, trace_api.SpanKind.CLIENT)
     self.assertEqual(span.name, "command_name.find")
     self.assertEqual(span.attributes[SpanAttributes.DB_SYSTEM], "mongodb")
     self.assertEqual(span.attributes[SpanAttributes.DB_NAME],
                      "database_name")
     self.assertEqual(span.attributes[SpanAttributes.DB_STATEMENT],
                      "command_name find")
     self.assertEqual(span.attributes[SpanAttributes.NET_PEER_NAME],
                      "test.com")
     self.assertEqual(span.attributes[SpanAttributes.NET_PEER_PORT], "1234")
     self.start_callback.assert_called_once_with(span, mock_event)