Esempio n. 1
0
    def test_drop_reason_encoding_error(self):
        n_traces = 10
        statsd = mock.Mock()
        writer_encoder = mock.Mock()
        writer_encoder.__len__ = (
            lambda *args: n_traces).__get__(writer_encoder)
        writer_metrics_reset = mock.Mock()
        writer_encoder.encode.side_effect = Exception
        writer = AgentWriter(agent_url="http://asdf:1234",
                             dogstatsd=statsd,
                             report_metrics=False)
        writer._encoder = writer_encoder
        writer._metrics_reset = writer_metrics_reset
        for i in range(n_traces):
            writer.write([
                Span(tracer=None,
                     name="name",
                     trace_id=i,
                     span_id=j,
                     parent_id=j - 1 or None) for j in range(5)
            ])

        writer.stop()
        writer.join()

        writer_metrics_reset.assert_called_once()

        assert 10 == writer._metrics["encoder.dropped.traces"]["count"]
Esempio n. 2
0
    def test_drop_reason_encoding_error(self):
        statsd = mock.Mock()
        writer_encoder = mock.Mock()
        writer_metrics_reset = mock.Mock()
        writer_encoder.encode_trace.side_effect = Exception
        writer = AgentWriter(dogstatsd=statsd, report_metrics=False, hostname="asdf", port=1234)
        writer._encoder = writer_encoder
        writer._metrics_reset = writer_metrics_reset
        for i in range(10):
            writer.write(
                [Span(tracer=None, name="name", trace_id=i, span_id=j, parent_id=j - 1 or None) for j in range(5)]
            )

        writer.stop()
        writer.join()

        writer_metrics_reset.assert_called_once()

        assert 10 == writer._metrics["encoder.dropped.traces"]["count"]