def setUpClass(cls):
     cls.serialized_trace_id = b3_format.format_trace_id(
         trace.generate_trace_id())
     cls.serialized_span_id = b3_format.format_span_id(
         trace.generate_span_id())
     cls.serialized_parent_id = b3_format.format_span_id(
         trace.generate_span_id())
    def test_extract_multi_header(self):
        """Test the extraction of B3 headers."""
        child, parent, new_carrier = get_child_parent_new_carrier({
            FORMAT.TRACE_ID_KEY:
            self.serialized_trace_id,
            FORMAT.SPAN_ID_KEY:
            self.serialized_span_id,
            FORMAT.PARENT_SPAN_ID_KEY:
            self.serialized_parent_id,
            FORMAT.SAMPLED_KEY:
            "1",
        })

        self.assertEqual(
            new_carrier[FORMAT.TRACE_ID_KEY],
            b3_format.format_trace_id(child.context.trace_id),
        )
        self.assertEqual(
            new_carrier[FORMAT.SPAN_ID_KEY],
            b3_format.format_span_id(child.context.span_id),
        )
        self.assertEqual(
            new_carrier[FORMAT.PARENT_SPAN_ID_KEY],
            b3_format.format_span_id(parent.context.span_id),
        )
        self.assertEqual(new_carrier[FORMAT.SAMPLED_KEY], "1")
Exemple #3
0
    def test_extract_single_header(self):
        """Test the extraction from a single b3 header."""
        child, parent, new_carrier = get_child_parent_new_carrier({
            FORMAT.SINGLE_HEADER_KEY:
            "{}-{}".format(self.serialized_trace_id, self.serialized_span_id)
        })

        self.assertEqual(
            new_carrier[FORMAT.TRACE_ID_KEY],
            b3_format.format_trace_id(child.context.trace_id),
        )
        self.assertEqual(
            new_carrier[FORMAT.SPAN_ID_KEY],
            b3_format.format_span_id(child.context.span_id),
        )
        self.assertEqual(new_carrier[FORMAT.SAMPLED_KEY], "1")
        self.assertTrue(parent.context.is_remote)

        child, parent, new_carrier = get_child_parent_new_carrier({
            FORMAT.SINGLE_HEADER_KEY:
            "{}-{}-1-{}".format(
                self.serialized_trace_id,
                self.serialized_span_id,
                self.serialized_parent_id,
            )
        })

        self.assertEqual(
            new_carrier[FORMAT.TRACE_ID_KEY],
            b3_format.format_trace_id(child.context.trace_id),
        )
        self.assertEqual(
            new_carrier[FORMAT.SPAN_ID_KEY],
            b3_format.format_span_id(child.context.span_id),
        )
        self.assertEqual(
            new_carrier[FORMAT.PARENT_SPAN_ID_KEY],
            b3_format.format_span_id(parent.context.span_id),
        )
        self.assertTrue(parent.context.is_remote)
        self.assertEqual(new_carrier[FORMAT.SAMPLED_KEY], "1")
Exemple #4
0
 def test_full_path(self):
     trace_id = trace.generate_trace_id()
     # We need to use the Werkzeug test app because
     # The headers are injected at the wsgi layer.
     # The flask test app will not include these, and
     # result in the values not propagated.
     client = Client(self.app.wsgi_app, BaseResponse)
     # emulate b3 headers
     client.get(
         "/",
         headers={
             "x-b3-traceid": b3_format.format_trace_id(trace_id),
             "x-b3-spanid":
             b3_format.format_span_id(trace.generate_span_id()),
             "x-b3-sampled": "1",
         },
     )
     # assert the http request header was propagated through.
     prepared_request = self.send.call_args[0][1]
     headers = prepared_request.headers
     for required_header in {"x-b3-traceid", "x-b3-spanid", "x-b3-sampled"}:
         self.assertIn(required_header, headers)
     self.assertEqual(headers["x-b3-traceid"],
                      b3_format.format_trace_id(trace_id))