Capturing Span ID for Feedback in Phoenix Traces Integration
Hey I am using Phoenix for saving traces on my langgraph application, I set up the instrumentation on the fastapi server with this
async def on_start_up() -> None:
if settings.ENABLE_PHOENIX_TRACES:
from openinference.instrumentation.langchain import (
LangChainInstrumentor,
)
from phoenix.otel import register
PHOENIX_API_KEY = settings.PHOENIX_API_KEY
tracer_provider = register(
project_name=settings.PHOENIX_PROJECT_NAME,
endpoint=settings.ARISE_PHOENIX_URL,
headers={"api_key": PHOENIX_API_KEY},
verbose=settings.PHOENIX_VEBOSE,
)
LangChainInstrumentor().instrument(tracer_provider=tracer_provider)I want to capture feedback from the ui for each of the traces, but for that I would need the span id. How do I get the span id in the code?
from opentelemetry.trace import format_span_id
from openinference.instrumentation.langchain import get_current_span
span = get_current_span()
if span is not None:
span_id = format_span_id(span.get_span_context().span_id)I have tried calling this code in the async for loop of my langgraph graph (.astream_events) but the variable span is always null for all events. Am I missing something?
