getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.85k stars 1.55k forks source link

Add LLM monitoring support for JavaScript #12981

Open AbhiPrasad opened 1 month ago

AbhiPrasad commented 1 month ago

Problem Statement

Add support for https://docs.sentry.io/product/insights/llm-monitoring/ in JavaScript

Solution Brainstorm

Things we can support:

colin-sentry commented 1 month ago

Currently difficult because we need to annotate the LLM spans with the pipeline span's name, and there is no nice way to pass context down in a runtime agnostic way

In python this is done with ContextVar

Maybe we can convert the pipeline span into a transaction, and pull down its name into the children that way?

AbhiPrasad commented 1 month ago

In python this is done with ContextVar

In Node.js we can use AsyncLocalStorage, which is what the SDK uses to maintain parent-child relationship between spans even with async behaviour.

In fact the Sentry scope lives on-top of async local storage in the Node SDK, so you can just store stuff on the scope to use.