Example #1
0
    def test_inject_binary(self):
        """Test `inject()` method for Format.BINARY."""

        otel_context = trace.SpanContext(trace_id=1220,
                                         span_id=7478,
                                         is_remote=False)
        context = SpanContextShim(otel_context)

        # Verify exception for non supported binary format.
        with self.assertRaises(opentracing.UnsupportedFormatException):
            self.shim.inject(context, opentracing.Format.BINARY, bytearray())
Example #2
0
    def test_inject_http_headers(self):
        """Test `inject()` method for Format.HTTP_HEADERS."""

        otel_context = trace.SpanContext(
            trace_id=1220, span_id=7478, is_remote=False
        )
        context = SpanContextShim(otel_context)

        headers = {}
        self.shim.inject(context, opentracing.Format.HTTP_HEADERS, headers)
        self.assertEqual(headers[MockHTTPTextFormat.TRACE_ID_KEY], str(1220))
        self.assertEqual(headers[MockHTTPTextFormat.SPAN_ID_KEY], str(7478))
Example #3
0
    def test_inject_text_map(self):
        """Test `inject()` method for Format.TEXT_MAP."""

        otel_context = trace.SpanContext(
            trace_id=1220, span_id=7478, is_remote=False
        )
        context = SpanContextShim(otel_context)

        # Verify Format.TEXT_MAP
        text_map = {}
        self.shim.inject(context, opentracing.Format.TEXT_MAP, text_map)
        self.assertEqual(text_map[MockHTTPTextFormat.TRACE_ID_KEY], str(1220))
        self.assertEqual(text_map[MockHTTPTextFormat.SPAN_ID_KEY], str(7478))
    def test_baggage(self):

        span_context_shim = SpanContextShim(
            trace.SpanContext(1234, 5678, is_remote=False))

        baggage = span_context_shim.baggage

        with self.assertRaises(ValueError):
            baggage[1] = 3

        span_shim = SpanShim(Mock(), span_context_shim, Mock())

        span_shim.set_baggage_item(1, 2)

        self.assertTrue(span_shim.get_baggage_item(1), 2)