RunLLM how to get the span_id for a phoenix trace ?
To get the span_id for a Phoenix trace, you can use the get_active_span method from the openinference.instrumentation.helpers module. Here's an example: LBKSfrom openinference.instrumentation.helpers import get_active_spanLBKSdef get_span_id(): span = get_active_span() return span.context.span_idLBKSspan_id = get_span_id() print(f"Span ID: {span_id}")LBKSThis method retrieves the currently active span and extracts its span_id.Would you like more detail?Sources:
- GitHub Issue #3775
馃挕聽Hint: Mention RunLLM in the thread for followups.
RunLLM http://localhost:6006/projects/UHJvamVjdDo5NjI=/traces/6f54c0ae7acb71b1b2e207acb5c513ca?selectedSpanId=f95ff99ffb64ad1b This is an actual trace link. but for that the span_id returned was 17969355503744363803. I used this code.
# Function to get the active span ID
def get_span_id():
span = get_current_span()
return span.get_span_context().span_idThe span_id you retrieved (17969355503744363803) is in integer format, but Phoenix typically uses a hexadecimal string format for span_id in URLs. You need to convert the integer span_id to a hexadecimal string.Here's how you can modify your function to return the span_id in the correct format: LBKSfrom opentelemetry import traceLBKS# Function to get the active span ID in hexadecimal format def get_span_id(): span = trace.get_current_span() span_id = span.get_span_context().span_id return format(span_id, '016x') # Convert to hexadecimal stringLBKSspan_id = get_span_id() print(f"Span ID: {span_id}")LBKSThis will convert the integer span_id to a 16-character hexadecimal string, which should match the format used in Phoenix trace links.Would you like more detail?Sources:
- GitHub Issue #3775
馃挕聽Hint: Mention RunLLM in the thread for followups.
