Skip to content

Commit c129aae

Browse files
authored
fix(langchain): instrument vector DB calls (#440)
1 parent 77fe2d5 commit c129aae

File tree

23 files changed

+24484
-18040
lines changed

23 files changed

+24484
-18040
lines changed

package-lock.json

+24,116-17,753
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/instrumentation-anthropic/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},
4747
"devDependencies": {
48-
"@anthropic-ai/sdk": "^0.20.1",
48+
"@anthropic-ai/sdk": "^0.27.1",
4949
"@pollyjs/adapter-node-http": "^6.0.6",
5050
"@pollyjs/core": "^6.0.6",
5151
"@pollyjs/persister-fs": "^6.0.6",

packages/instrumentation-anthropic/src/instrumentation.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,16 @@ export class AnthropicInstrumentation extends InstrumentationBase {
283283

284284
case "content_block_delta":
285285
if (chunk.index < result.content.length) {
286-
result.content[chunk.index] = {
287-
type: "text",
288-
text: result.content[chunk.index].text + chunk.delta.text,
289-
};
286+
const current = result.content[chunk.index];
287+
if (
288+
current.type === "text" &&
289+
chunk.delta.type === "text_delta"
290+
) {
291+
result.content[chunk.index] = {
292+
type: "text",
293+
text: current.text + chunk.delta.text,
294+
};
295+
}
290296
}
291297
}
292298
} catch (e) {

packages/instrumentation-azure/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},

packages/instrumentation-bedrock/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},

packages/instrumentation-chromadb/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},

packages/instrumentation-cohere/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},

packages/instrumentation-cohere/src/instrumentation.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,10 @@ export class CohereInstrumentation extends InstrumentationBase {
247247
params.chatHistory?.forEach((msg, index) => {
248248
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.role`] =
249249
msg.role;
250-
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.user`] =
251-
msg.message;
250+
if (msg.role !== "TOOL") {
251+
attributes[`${SpanAttributes.LLM_PROMPTS}.${index}.content`] =
252+
msg.message;
253+
}
252254
});
253255

254256
attributes[
@@ -452,10 +454,12 @@ export class CohereInstrumentation extends InstrumentationBase {
452454

453455
if (result.searchResults?.length) {
454456
result.searchResults.forEach((searchResult, index) => {
455-
span.setAttribute(
456-
`${SpanAttributes.LLM_COMPLETIONS}.0.searchResult.${index}.text`,
457-
searchResult.searchQuery.text,
458-
);
457+
if (searchResult.searchQuery) {
458+
span.setAttribute(
459+
`${SpanAttributes.LLM_COMPLETIONS}.0.searchResult.${index}.text`,
460+
searchResult.searchQuery.text,
461+
);
462+
}
459463
span.setAttribute(
460464
`${SpanAttributes.LLM_COMPLETIONS}.0.searchResult.${index}.connector`,
461465
searchResult.connector.id,

packages/instrumentation-langchain/package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,20 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"@opentelemetry/core": "^1.25.0",
42-
"@opentelemetry/instrumentation": "^0.52.0",
43-
"@opentelemetry/semantic-conventions": "^1.25.0",
41+
"@opentelemetry/core": "^1.26.0",
42+
"@opentelemetry/instrumentation": "^0.53.0",
43+
"@opentelemetry/semantic-conventions": "^1.26.0",
4444
"@traceloop/ai-semantic-conventions": "^0.11.0",
4545
"tslib": "^2.3.0"
4646
},
4747
"devDependencies": {
48-
"@langchain/community": "^0.0.34",
49-
"@langchain/openai": "^0.0.15",
48+
"@langchain/community": "^0.2.31",
49+
"@langchain/openai": "^0.2.8",
5050
"@pollyjs/adapter-node-http": "^6.0.6",
5151
"@pollyjs/core": "^6.0.6",
5252
"@pollyjs/persister-fs": "^6.0.6",
5353
"@types/mocha": "^10.0.6",
54-
"hnswlib-node": "^1.4.2",
55-
"langchain": "^0.1.25",
54+
"langchain": "^0.2.12",
5655
"mocha": "^10.2.0",
5756
"ts-mocha": "^10.0.0"
5857
},

0 commit comments

Comments
 (0)