Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 37 additions & 38 deletions packages/sample-app/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions packages/traceloop-sdk/tests/test_sdk_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import pytest
from unittest.mock import patch
from openai import OpenAI
from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import workflow
from traceloop.sdk.tracing.tracing import TracerWrapper
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, BatchSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter


@pytest.fixture
Expand Down Expand Up @@ -223,3 +227,27 @@ def test_get_default_span_processor():
assert isinstance(processor, BatchSpanProcessor)
assert hasattr(processor, "_traceloop_processor")
assert getattr(processor, "_traceloop_processor") is True


def test_use_legacy_attributes_false_propagates_to_instrumentors():
"""use_legacy_attributes=False passed to Traceloop.init() must reach each
instrumentor's Config — otherwise users have no way to opt into the new
event-based format through the SDK."""
from opentelemetry.instrumentation.openai.shared.config import Config as OpenAIConfig

_instance = None
if hasattr(TracerWrapper, "instance"):
_instance = TracerWrapper.instance
del TracerWrapper.instance

exporter = InMemorySpanExporter()
Traceloop.init(
exporter=exporter,
disable_batch=True,
use_legacy_attributes=False,
)

assert OpenAIConfig.use_legacy_attributes is False

if _instance is not None:
TracerWrapper.instance = _instance
2 changes: 2 additions & 0 deletions packages/traceloop-sdk/traceloop/sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def init(
image_uploader: Optional[ImageUploader] = None,
span_postprocess_callback: Optional[Callable[[ReadableSpan], None]] = None,
endpoint_is_traceloop: Optional[bool] = False,
use_legacy_attributes: bool = True,
) -> Optional[Client]:
if not enabled:
TracerWrapper.set_disabled(True)
Expand Down Expand Up @@ -146,6 +147,7 @@ def init(
instruments=instruments,
block_instruments=block_instruments,
span_postprocess_callback=span_postprocess_callback,
use_legacy_attributes=use_legacy_attributes,
)

metrics_disabled_by_config = not is_metrics_enabled()
Expand Down
Loading
Loading