Files
zavrsni-rad-otel-app/backend/microservices/common/http.py

20 lines
541 B
Python

from __future__ import annotations
from opentelemetry import trace
def current_trace_headers() -> dict[str, str]:
span_context = trace.get_current_span().get_span_context()
if not span_context.is_valid:
return {}
return {
"x-trace-id": f"{span_context.trace_id:032x}",
"x-span-id": f"{span_context.span_id:016x}",
}
def with_internal_service_token(headers: dict[str, str], token: str) -> dict[str, str]:
merged = dict(headers)
merged["x-internal-service-token"] = token
return merged