Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add key predicate to baggage span processor #2535

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more linter fixes
  • Loading branch information
MikeGoldsmith committed May 21, 2024
commit 832abc992de081b7d297dbfcceb6b146249b6f86
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# pylint: disable=import-error

from .processor import BaggageSpanProcessor
from .processor import ALLOW_ALL_BAGGAGE_KEYS, BaggageSpanProcessor
from .version import __version__

__all__ = ["BaggageSpanProcessor", "__version__"]
__all__ = ["ALLOW_ALL_BAGGAGE_KEYS", "BaggageSpanProcessor", "__version__"]
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@
from opentelemetry.sdk.trace.export import SpanProcessor
from opentelemetry.trace import Span

"""
A BaggageKeyPredicate is a function that takes a baggage key and returns a boolean
"""
type BaggageKeyPredicate = Callable[[str], bool]
# A BaggageKeyPredicate is a function that takes a baggage key and returns a boolean
BaggageKeyPredicateT = Callable[[str], bool]

"""
A BaggageKeyPredicate that always returns True, allowing all baggage keys to be added to spans
"""
ALLOW_ALL_BAGGAGE_KEYS: BaggageKeyPredicate = lambda baggageKey: True
# A BaggageKeyPredicate that always returns True, allowing all baggage keys to be added to spans
ALLOW_ALL_BAGGAGE_KEYS: BaggageKeyPredicateT = lambda _: True


class BaggageSpanProcessor(SpanProcessor):
Expand All @@ -54,9 +50,8 @@ class BaggageSpanProcessor(SpanProcessor):

"""

def __init__(self, baggage_key_predicate: BaggageKeyPredicate) -> None:
def __init__(self, baggage_key_predicate: BaggageKeyPredicateT) -> None:
self._baggage_key_predicate = baggage_key_predicate
pass

def on_start(
self, span: "Span", parent_context: Optional[Context] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@

class BaggageSpanProcessorTest(unittest.TestCase):
def test_check_the_baggage(self):
self.assertIsInstance(BaggageSpanProcessor(), SpanProcessor)
self.assertIsInstance(
BaggageSpanProcessor(ALLOW_ALL_BAGGAGE_KEYS), SpanProcessor
)

def test_set_baggage_attaches_to_child_spans_and_detaches_properly_with_context(
self,
Expand Down Expand Up @@ -156,8 +158,10 @@ def test_set_baggage_attaches_to_child_spans_and_detaches_properly_with_token(
detach(honey_token)
self.assertEqual(get_all_baggage(), {})

@staticmethod
def has_prefix(baggage_key: str) -> bool:
return baggage_key.startswith("que")

@staticmethod
def matches_regex(baggage_key: str) -> bool:
return re.match(r"que.*", baggage_key) is not None
Loading