Пофиксила проблемы OTel
This commit is contained in:
+19
-26
@@ -12,8 +12,6 @@ import os
|
||||
import signal
|
||||
import sys
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
import pika
|
||||
from PIL import Image, ImageOps
|
||||
@@ -30,11 +28,9 @@ from .storage.rabbit import (
|
||||
)
|
||||
from .telemetry import init_telemetry, meter
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s %(levelname)s %(name)s %(message)s",
|
||||
stream=sys.stdout,
|
||||
)
|
||||
# Базовый логгер настраивается в telemetry.install_log_format() при старте
|
||||
# init_telemetry: trace_id/span_id подставляются фильтром.
|
||||
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
||||
log = logging.getLogger("worker")
|
||||
|
||||
PIPELINE_VERSION = 1
|
||||
@@ -53,14 +49,10 @@ init_telemetry("messenger-worker", "1.6.0")
|
||||
_tracer = trace.get_tracer("worker")
|
||||
_meter = meter("messenger-worker")
|
||||
_jobs_counter = _meter.create_counter(
|
||||
"jobs_processed_total",
|
||||
description="Jobs processed by outcome",
|
||||
unit="1",
|
||||
"jobs_processed_total", description="Jobs processed by outcome", unit="1",
|
||||
)
|
||||
_jobs_hist = _meter.create_histogram(
|
||||
"job_processing_duration_seconds",
|
||||
description="Job processing duration",
|
||||
unit="s",
|
||||
"job_processing_duration_seconds", description="Job processing duration", unit="s",
|
||||
)
|
||||
|
||||
|
||||
@@ -71,6 +63,7 @@ def _handle_sigterm(signum, frame):
|
||||
|
||||
|
||||
def _now_iso() -> str:
|
||||
from datetime import datetime, timezone
|
||||
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
||||
|
||||
|
||||
@@ -217,20 +210,20 @@ def process_job(payload: dict) -> None:
|
||||
|
||||
|
||||
def _extract_trace_context(properties) -> otel_context.Context:
|
||||
"""Достаём W3C traceparent/tracestate из headers сообщения.
|
||||
|
||||
Трейс API-upload → outbox publish → worker consume получает одну общую
|
||||
цепочку. При отсутствии headers возвращаем пустой контекст.
|
||||
"""
|
||||
headers = dict(properties.headers or {})
|
||||
if "traceparent" not in headers and "tracestate" not in headers:
|
||||
"""Извлекаем W3C traceparent/tracestate из headers. Ошибки → пустой контекст."""
|
||||
try:
|
||||
headers = dict(properties.headers or {})
|
||||
carrier = {
|
||||
k.lower(): str(v)
|
||||
for k, v in headers.items()
|
||||
if k.lower() in ("traceparent", "tracestate")
|
||||
}
|
||||
if not carrier:
|
||||
return otel_context.Context()
|
||||
return _propagator.extract(carrier=carrier)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
log.warning("event=trace_extract_failed type=%s", type(exc).__name__)
|
||||
return otel_context.Context()
|
||||
carrier = {
|
||||
k.lower(): str(v)
|
||||
for k, v in headers.items()
|
||||
if k.lower() in ("traceparent", "tracestate")
|
||||
}
|
||||
return _propagator.extract(carrier=carrier)
|
||||
|
||||
|
||||
def _on_message(ch, method, properties, body):
|
||||
|
||||
Reference in New Issue
Block a user