logfire icon indicating copy to clipboard operation
logfire copied to clipboard

Add Metadata to LLM Calls in Logfire

Open PierreColombo opened this issue 11 months ago • 6 comments

Description

Implement a feature in Logfire that allows users to attach custom metadata to each LLM API call. This enhancement would enable more detailed tracking, filtering, and analysis of LLM interactions within the Logfire observability platform and better understanding the tokens consumption.

PierreColombo avatar Dec 28 '24 13:12 PierreColombo

Usign spans allows you to do this, like this:

with logfire.span("ai_flow_1", prompt_id = 5, ... Here you can add as much fields as you need ):
    llm.call() # pseodocode of whatever llm you use.

And llms in logfire right now are traced by provider (openai, anthropic), I agree that it would be great if they gone deeper into the llm specific filtering apart from doing it from spans, but not clear how without disrupting the openai, anthropic apis.

Would be great if it can be done generally for all llm type traces.

antoni0z avatar Jan 02 '25 16:01 antoni0z

it would be great if they gone deeper into the llm specific filtering apart from doing it from spans

@antoni0z can you please clarify this?

alexmojaki avatar Jan 02 '25 18:01 alexmojaki

it would be great if they gone deeper into the llm specific filtering apart from doing it from spans

@antoni0z can you please clarify this?

Yes, I think that having special attributes for llms is needed.

Because right now, this is being done specific for openai traces and anthropic traces.

So if I want to do a dashboard for the tokens consumed is difficult to do It on a general way on the llms because I have to filter the anthropic way and the openai way.

If for each llm call some attributes are added, like tokens spent, function calls used, and other llm specific attributes this will help with better general llm filtering.

And also will help libraries like lanchain to be able to integrate better with logfire, if it follows this tracing abstractions.

Its just an idea so take it with a grain of salt, what do you think? Does logfire have some of this in mind to become even more helpful in the llms specific context?

antoni0z avatar Jan 02 '25 18:01 antoni0z

Yup, we should use the new semantics Otel attributes for GenAI, we're intending to work on this soon, but it's a big piece of work.

samuelcolvin avatar Jan 21 '25 08:01 samuelcolvin

Amazing to hear that

antoni0z avatar Jan 26 '25 14:01 antoni0z

Thanks, looking forward!

bhaveshpatel640 avatar May 06 '25 05:05 bhaveshpatel640

For attaching custom metadata directly to arbitrary spans that you don't control or have access to, see https://logfire.pydantic.dev/docs/reference/advanced/baggage/

alexmojaki avatar Jun 16 '25 13:06 alexmojaki