mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
* feat(tracing): add OpenTelemetry dependencies and --import preload flag * feat(enterprise): add distributed_tracing feature gate * feat(tracing): add SDK bootstrap with enterprise gating * fix(tracing): correct test coverage for enterprise-unavailable path and prevent double-init Test 2 now mocks @snapotter/enterprise to throw an import error, exercising the catch block in the preload. Test 3 imports with no endpoint so the preload is a no-op, avoiding leaked SDK from double-initialization. Added idempotency guard to initTracing() as a safety net. * feat(tracing): add Pino trace mixin and shared logger When OTel tracing is active, every Pino log line now includes traceId, spanId, and traceFlags fields for log-to-trace correlation. The mixin is a no-op when no SDK is registered (community users). * feat(tracing): add _otel to ToolJobData and inject trace context at enqueue Add optional _otel carrier field to ToolJobData for W3C trace context propagation across BullMQ job boundaries. When an active OTel span exists, propagation.inject() writes traceparent/tracestate into the job data before queue.add(). When no SDK is registered (community edition), the carrier stays empty and _otel remains undefined -- zero overhead. * feat(tracing): extract trace context and create spans in BullMQ worker * feat(tracing): inject trace context into Python sidecar calls * feat(tracing): add trace context extraction to Python sidecar * feat(tracing): add shutdownTracing to graceful shutdown sequence * feat(tracing): enrich HTTP spans with tool_id and user_id attributes * docs: add OpenTelemetry env var documentation to .env.example * test(tracing): add lifecycle integration tests for trace propagation * fix(tracing): inject trace context into pipeline and batch flow jobs * fix(tracing): add sidecar.execute Node-side span and remove unnecessary comment Wraps PythonDispatcher.run() with a sidecar.execute span on the Node side so traces show the full round-trip (Node span -> Python span). Also removes an obvious comment from logger.ts.
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
import json
|
|
import os
|
|
import pytest
|
|
|
|
|
|
def test_otel_stripped_from_request():
|
|
"""_otel should be popped from the request before reaching scripts."""
|
|
request = {
|
|
"id": "test-1",
|
|
"script": "remove_bg",
|
|
"args": ["input.png"],
|
|
"_otel": {"traceparent": "00-abc123-def456-01"},
|
|
}
|
|
otel_data = request.pop("_otel", None)
|
|
assert otel_data is not None
|
|
assert otel_data["traceparent"] == "00-abc123-def456-01"
|
|
assert "_otel" not in request
|
|
assert request["args"] == ["input.png"]
|
|
|
|
|
|
def test_no_otel_in_request():
|
|
"""Requests without _otel should work normally."""
|
|
request = {
|
|
"id": "test-2",
|
|
"script": "remove_bg",
|
|
"args": ["input.png"],
|
|
}
|
|
otel_data = request.pop("_otel", None)
|
|
assert otel_data is None
|
|
assert request["args"] == ["input.png"]
|
|
|
|
|
|
def test_tracing_init_without_endpoint(monkeypatch):
|
|
"""_init_tracing should be a no-op without OTEL_EXPORTER_OTLP_ENDPOINT."""
|
|
monkeypatch.delenv("OTEL_EXPORTER_OTLP_ENDPOINT", raising=False)
|
|
import sys
|
|
dispatcher_dir = os.path.join(os.path.dirname(__file__), "..")
|
|
if dispatcher_dir not in sys.path:
|
|
sys.path.insert(0, dispatcher_dir)
|
|
from dispatcher import _init_tracing, _tracer
|
|
_init_tracing()
|
|
from dispatcher import _tracer as tracer_after
|
|
assert tracer_after is None
|