Skip to content

Commit 2834a11

Browse files
authored
Adjusting the llm span filter, to remove non-llm related fetch spans (#1043)
1 parent 79ed441 commit 2834a11

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

toolshed/routes/ai/llm/instrumentation.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import env from "@/env.ts";
1010

1111
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR);
1212

13+
const isLLMProviderFetch = (span: any) => {
14+
const aiProviderHostnames = [
15+
"openai.com",
16+
"anthropic.com",
17+
"claude.ai",
18+
"groq.com",
19+
"aiplatform.googleapis.com",
20+
];
21+
22+
return aiProviderHostnames.some((hostname) =>
23+
span.attributes["http.url"]?.toString().includes(hostname)
24+
);
25+
};
26+
1327
export function register() {
1428
registerOTel({
1529
serviceName: env.CTTS_AI_LLM_PHOENIX_PROJECT,
@@ -29,9 +43,9 @@ export function register() {
2943
spanFilter: (span) => {
3044
// console.log("SPAN", span);
3145
const includeSpanCriteria = [
32-
isOpenInferenceSpan(span),
3346
span.attributes["http.route"] == "/api/ai/llm", // Include the root span, which is in the hono app
34-
span.instrumentationLibrary.name.includes("@vercel/otel"), // Include the actual LLM API fetch span
47+
isOpenInferenceSpan(span),
48+
isLLMProviderFetch(span), // Include fetch spans to LLM providers
3549
];
3650
return includeSpanCriteria.some((c) => c);
3751
},

0 commit comments

Comments
 (0)