Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

MockTracer cannot start span with a parent span #132

Open
moonshine-fish opened this issue May 20, 2020 · 1 comment
Open

MockTracer cannot start span with a parent span #132

moonshine-fish opened this issue May 20, 2020 · 1 comment
Labels

Comments

@moonshine-fish
Copy link

if parent_ctx._baggage is not None:

If I want to test with MockTracer, and in my business code it calls start_span with child_of parameter, an error will occur as original SpanContext doesn't have _baggage property

        # Assemble the child ctx
        ctx = SpanContext(span_id=self._generate_id())
        if parent_ctx is not None:
>           if parent_ctx._baggage is not None:
E           AttributeError: 'SpanContext' object has no attribute '_baggage'

opentracing.mocktracer.SpanContext has _baggage property, but how can I use it in my business code?

@yurishkuro
Copy link
Member

Please refer to the API and not to private fields of implementation classes.

def set_baggage_item(self, key, value):
"""Stores a Baggage item in the :class:`Span` as a key/value pair.
Enables powerful distributed context propagation functionality where
arbitrary application data can be carried along the full path of
request execution throughout the system.
Note 1: Baggage is only propagated to the future (recursive) children
of this :class:`Span`.
Note 2: Baggage is sent in-band with every subsequent local and remote
calls, so this feature must be used with care.
:param key: Baggage item key
:type key: str
:param value: Baggage item value
:type value: str
:rtype: Span
:return: itself, for chaining the calls.
"""
return self

def get_baggage_item(self, key):
"""Retrieves value of the baggage item with the given key.
:param key: key of the baggage item
:type key: str
:rtype: str
:return: value of the baggage item with given key, or ``None``.
"""
return None

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants