Перенести реализацию мессенджера из ЛР 6

Файлы скопированы без изменений из solution/BPI2301-Vozzhin
репозитория mtusi2026lab6. Доработки ЛР 7 идут отдельными коммитами.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-12-03 19:48:41 +05:00
co-authored by Claude Opus 5.5
parent 20afc2c790
commit 31d441184b
92 changed files with 6153 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
from __future__ import annotations
from collections.abc import Mapping
from opentelemetry import propagate
_ALLOWED = {'traceparent', 'tracestate'}
def inject_trace_context(context=None) -> dict[str, str]:
carrier: dict[str, str] = {}
propagate.inject(carrier, context=context)
return {key: str(value) for key, value in carrier.items() if key in _ALLOWED}
def extract_trace_context(carrier: Mapping[str, object] | None):
normalized: dict[str, str] = {}
for key, value in (carrier or {}).items():
lowered = str(key).lower()
if lowered not in _ALLOWED or value is None:
continue
if isinstance(value, bytes):
value = value.decode('ascii', errors='ignore')
normalized[lowered] = str(value)
return propagate.extract(normalized)