Skip to content

Commit 992c506

Browse files
committed
Add test for max_baggage_attributes limit
1 parent 391c2dd commit 992c506

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

processor/opentelemetry-processor-baggage/tests/test_baggage_log_processor.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ def test_no_baggage_not_added(self):
104104
attributes = logs[-1].log_record.attributes
105105
self.assertNotIn("queen", attributes)
106106

107-
@staticmethod
108-
def has_prefix(baggage_key: str) -> bool:
109-
return baggage_key.startswith("que")
110-
111-
@staticmethod
112-
def matches_regex(baggage_key: str) -> bool:
113-
return re.match(r"que.*", baggage_key) is not None
114107
def test_multiple_predicates(self):
115108
token1 = attach(set_baggage("queen", "bee"))
116109
token2 = attach(set_baggage("king", "cobra"))
@@ -135,7 +128,36 @@ def test_multiple_predicates(self):
135128
detach(token2)
136129
detach(token1)
137130

131+
def test_max_baggage_attributes_limit(self):
132+
token1 = attach(set_baggage("key1", "val1"))
133+
token2 = attach(set_baggage("key2", "val2"))
134+
token3 = attach(set_baggage("key3", "val3"))
135+
logger_provider = LoggerProvider()
136+
logger_provider.add_log_record_processor(
137+
BaggageLogProcessor(ALLOW_ALL_BAGGAGE_KEYS, max_baggage_attributes=2)
138+
)
139+
exporter = InMemoryLogRecordExporter()
140+
logger_provider.add_log_record_processor(
141+
BatchLogRecordProcessor(exporter)
142+
)
143+
logger = logger_provider.get_logger("test-logger")
144+
logger.emit(None)
145+
logger_provider.force_flush()
146+
logs = exporter.get_finished_logs()
147+
attributes = logs[-1].log_record.attributes
148+
self.assertEqual(len(attributes), 2)
149+
detach(token3)
150+
detach(token2)
151+
detach(token1)
152+
153+
@staticmethod
154+
def has_prefix(baggage_key: str) -> bool:
155+
return baggage_key.startswith("que")
156+
157+
@staticmethod
158+
def matches_regex(baggage_key: str) -> bool:
159+
return re.match(r"que.*", baggage_key) is not None
160+
138161

139162
if __name__ == "__main__":
140163
unittest.main()
141-

0 commit comments

Comments
 (0)