Does openinference have an in memory span collector that I can use while running unit tests?
Yes, OpenInference uses the OpenTelemetry InMemorySpanExporter for in-memory span collection during unit tests. This is shown in multiple test setups, where InMemorySpanExporter is used to collect and inspect spans without exporting them externally. You can use this exporter with your tracer provider in your test fixtures or setup code to capture spans in memory for assertions and validation purposes. Example usage can be found in the OpenInference test files, such as: LBKSfrom opentelemetry.sdk.trace.export import InMemorySpanExporter, SimpleSpanProcessor from opentelemetry.sdk.trace import TracerProviderLBKSin_memory_span_exporter = InMemorySpanExporter() tracer_provider = TracerProvider() tracer_provider.add_span_processor(SimpleSpanProcessor(in_memory_span_exporter))LBKSAccording to conftest.py (litellm), conftest.py (openai), and conftest.py (openai-agents).Would you like more detail or a full test example?Sources:
- conftest.py (litellm)
- conftest.py (openai)
- conftest.py (openai-agents)
馃挕聽Hint: Mention RunLLM in the thread for followups.
You need to install the opentelemetry-sdk package directly, as arize-phoenix-otel does not include it as a dependency. The InMemorySpanExporter and SimpleSpanProcessor are provided by opentelemetry-sdk, not by arize-phoenix-otel itself. Install with: LBKSpip install opentelemetry-sdkLBKSThis will provide the necessary modules for in-memory span collection in your tests. See arize-phoenix-otel docs and OpenInference test setup.Would you like a full requirements list for a typical test environment?Sources:
- arize-phoenix-otel docs
馃挕聽Hint: Mention RunLLM in the thread for followups.
Unfortunately that doesn鈥檛 seem to work. I made sure that opentelemetry-sdk was the latest version according to pypi
Hey Ben M., it might be worth checking out our test suite for one our auto-instrumentors. https://github.com/Arize-ai/openinference/blob/72a6f06b4ea992a13ba0258ca593a1f7769[鈥n-openai/tests/openinference/instrumentation/openai/conftest.py
Thank you, Xander S.! That fixed me up. This is what I ended up with
if config.env != "test":
tracer = register(
project_name=config.phoenix_project_name,
endpoint=f"{config.phoenix_url}/v1/traces",
headers={"Authorization": f"Bearer {config.phoenix_api_key}"},
auto_instrument=True,
verbose=False,
batch=True,
).get_tracer(__name__)
else:
from opentelemetry.sdk.trace.export.in_memory_span_exporter import (
InMemorySpanExporter,
)
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from openinference.instrumentation import TracerProvider
in_memory_span_exporter = InMemorySpanExporter()
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(in_memory_span_exporter))
tracer = tracer_provider.get_tracer(__name__)