Hey guys! What is the best way to get the Span id ...
# koog-agentic-framework
f
Hey guys! What is the best way to get the Span id for a koog agent? I'm using OpenTelemetry and the LangfuseExporter. I'm trying to setup custom evaluations in langfuse. Thanks in advance!!
✅ 1
v
cc: @Sergei Dubov
s
Hi @Finn Jensen. Thank you for the question! Currently, it is a bit tricky question. You can use a custom span exporter that you can get a list of spans and find span Ids from collected spans. We have an ability to add
SpanAdapter
and get a span Id from it’s handler. However, there is an known issue, which does not allow you to set multiple `SpanAdapter`s (KG-265). Please stay tuned, we will fix this in future releases.
f
@Sergei Dubov thanks for the answer! I’m trying to find the trace that is produced from an agent run so i can link it to an evaluation in Langfuse. Is there any way to get the trace id or would a custom exporter be needed for that as well
Closing the loop here. I ended up using a custom SpanExporter like recommended above because I only need the trace id this is pretty straightforward though its a bit of a sloppy piece of code lol
Copy code
class TraceIdExporter(
    private val onTraceId: (String) -> Unit = {},
) : SpanExporter {
    override fun export(spans: Collection<SpanData?>): CompletableResultCode? {
        spans.forEach {
            if (it?.traceId != null) {
                onTraceId(it.traceId)
            }
        }
        return CompletableResultCode.ofSuccess()
    }
👍 1
s
Hi @Finn Jensen. Sorry for a long response. Yes, the solution with custom exporter should work here. I think we can add extracting trace id out from the feature in future if needed.
👍 1