def test_modifying_correlations(self):
     ctx = cctx.set_correlation("test", "value")
     self.assertEqual(cctx.get_correlation("test", context=ctx), "value")
     correlations = cctx.get_correlations(context=ctx)
     with self.assertRaises(TypeError):
         correlations["test"] = "mess-this-up"
     self.assertEqual(cctx.get_correlation("test", context=ctx), "value")
Exemple #2
0
    def test_remove_correlations(self):
        self.assertEqual({}, cctx.get_correlations())

        ctx = cctx.set_correlation("test", "value")
        ctx = cctx.set_correlation("test2", "value2", context=ctx)
        ctx = cctx.remove_correlation("test", context=ctx)
        self.assertEqual(cctx.get_correlation("test", context=ctx), None)
        self.assertEqual(cctx.get_correlation("test2", context=ctx), "value2")
Exemple #3
0
 def test_set_multiple_correlations(self):
     ctx = cctx.set_correlation("test", "value")
     ctx = cctx.set_correlation("test2", "value2", context=ctx)
     self.assertEqual(cctx.get_correlation("test", context=ctx), "value")
     self.assertEqual(cctx.get_correlation("test2", context=ctx), "value2")
     self.assertEqual(
         cctx.get_correlations(context=ctx),
         {"test": "value", "test2": "value2"},
     )
Exemple #4
0
    def test_clear_correlations(self):
        self.assertEqual({}, cctx.get_correlations())

        ctx = cctx.set_correlation("test", "value")
        self.assertEqual(cctx.get_correlation("test", context=ctx), "value")

        ctx = cctx.clear_correlations(context=ctx)
        self.assertEqual(cctx.get_correlations(context=ctx), {})
    def get_baggage_item(self, key: str) -> Optional[object]:
        """Retrieves value of the baggage item with the given key.

        Args:
            key: A tag key.
        Returns:
            Returns this :class:`SpanShim` instance to allow call chaining.
        """
        # pylint: disable=protected-access
        return get_correlation(key, context=self._context._baggage)
Exemple #6
0
 def test_correlations_current_context(self):
     token = context.attach(cctx.set_correlation("test", "value"))
     self.assertEqual(cctx.get_correlation("test"), "value")
     context.detach(token)
     self.assertEqual(cctx.get_correlation("test"), None)
Exemple #7
0
 def get_baggage_item(self, key):
     """Implements the ``get_baggage_item`` method from the base class."""
     # pylint: disable=protected-access
     return get_correlation(key, context=self._context._baggage)