Skip to content

Commit 6d78bdc

Browse files
authored
feat: Add cohere-ai instrumentation (#1781)
Fixes #1740
1 parent 9ad2d5c commit 6d78bdc

39 files changed

Lines changed: 4692 additions & 2 deletions

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ ANTHROPIC_API_KEY=
44
GEMINI_API_KEY=
55
OPENROUTER_API_KEY=
66
MISTRAL_API_KEY=
7+
COHERE_API_KEY=

.github/workflows/e2e-canary.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
BRAINTRUST_API_KEY: ${{ secrets.BRAINTRUST_API_KEY }}
3535
BRAINTRUST_E2E_PROJECT_NAME: ${{ vars.BRAINTRUST_E2E_PROJECT_NAME }}
3636
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
37+
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
3738
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
3839
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
3940
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}

.github/workflows/integration-tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
BRAINTRUST_E2E_PROJECT_NAME: ${{ vars.BRAINTRUST_E2E_PROJECT_NAME }}
5757
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
5858
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
59+
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
5960
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
6061
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
6162
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
@@ -105,6 +106,7 @@ jobs:
105106
BRAINTRUST_E2E_PROJECT_NAME: ${{ vars.BRAINTRUST_E2E_PROJECT_NAME }}
106107
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
107108
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
109+
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
108110
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
109111
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
110112
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}

e2e/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Non-hermetic scenarios require provider credentials in addition to the mock Brai
117117
- `GEMINI_API_KEY` or `GOOGLE_API_KEY`
118118
- `OPENROUTER_API_KEY`
119119
- `MISTRAL_API_KEY`
120+
- `COHERE_API_KEY`
120121

121122
`claude-agent-sdk-instrumentation` also uses `ANTHROPIC_API_KEY`, because it runs the real Claude Agent SDK against Anthropic in the same style as the existing live Anthropic wrapper coverage.
122123

e2e/config/pr-comment-scenarios.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
{ "variantKey": "mistral-v2", "label": "latest v2" }
4747
]
4848
},
49+
{
50+
"scenarioDirName": "cohere-instrumentation",
51+
"label": "Cohere Instrumentation",
52+
"metadataScenario": "cohere-instrumentation",
53+
"variants": [
54+
{ "variantKey": "cohere-v7-14-0", "label": "v7.14.0" },
55+
{ "variantKey": "cohere-v7-20-0", "label": "v7.20.0" },
56+
{ "variantKey": "cohere-v7-21-0", "label": "v7.21.0" },
57+
{ "variantKey": "cohere-v7", "label": "latest v7" },
58+
{ "variantKey": "cohere-v8", "label": "latest v8" }
59+
]
60+
},
4961
{
5062
"scenarioDirName": "openrouter-instrumentation",
5163
"label": "OpenRouter Instrumentation",

e2e/helpers/scenario-installer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const INSTALL_SECRET_ENV_VARS = [
2727
"OPENAI_API_KEY",
2828
"OPENROUTER_API_KEY",
2929
"MISTRAL_API_KEY",
30+
"COHERE_API_KEY",
3031
] as const;
3132

3233
const cleanupDirs = new Set<string>();
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
[
2+
{
3+
"has_input": false,
4+
"has_output": false,
5+
"metadata": {
6+
"scenario": "cohere-instrumentation"
7+
},
8+
"metric_keys": [],
9+
"name": "cohere-instrumentation-root",
10+
"root_span_id": "<span:1>",
11+
"span_id": "<span:1>",
12+
"span_parents": [],
13+
"type": "task"
14+
},
15+
{
16+
"has_input": false,
17+
"has_output": false,
18+
"metadata": {
19+
"operation": "chat"
20+
},
21+
"metric_keys": [],
22+
"name": "cohere-chat-operation",
23+
"root_span_id": "<span:1>",
24+
"span_id": "<span:2>",
25+
"span_parents": [
26+
"<span:1>"
27+
],
28+
"type": null
29+
},
30+
{
31+
"has_input": true,
32+
"has_output": true,
33+
"metadata": {
34+
"model": "command-a-03-2025",
35+
"provider": "cohere"
36+
},
37+
"metric_keys": [
38+
"completion_tokens",
39+
"prompt_cached_tokens",
40+
"prompt_tokens",
41+
"time_to_first_token",
42+
"tokens"
43+
],
44+
"name": "cohere.chat",
45+
"root_span_id": "<span:1>",
46+
"span_id": "<span:3>",
47+
"span_parents": [
48+
"<span:2>"
49+
],
50+
"type": "llm"
51+
},
52+
{
53+
"has_input": false,
54+
"has_output": false,
55+
"metadata": {
56+
"operation": "chat-stream"
57+
},
58+
"metric_keys": [],
59+
"name": "cohere-chat-stream-operation",
60+
"root_span_id": "<span:1>",
61+
"span_id": "<span:4>",
62+
"span_parents": [
63+
"<span:1>"
64+
],
65+
"type": null
66+
},
67+
{
68+
"has_input": true,
69+
"has_output": true,
70+
"metadata": {
71+
"model": "command-a-03-2025",
72+
"provider": "cohere"
73+
},
74+
"metric_keys": [
75+
"completion_tokens",
76+
"prompt_cached_tokens",
77+
"prompt_tokens",
78+
"time_to_first_token",
79+
"tokens"
80+
],
81+
"name": "cohere.chatStream",
82+
"root_span_id": "<span:1>",
83+
"span_id": "<span:5>",
84+
"span_parents": [
85+
"<span:4>"
86+
],
87+
"type": "llm"
88+
},
89+
{
90+
"has_input": false,
91+
"has_output": false,
92+
"metadata": {
93+
"operation": "embed"
94+
},
95+
"metric_keys": [],
96+
"name": "cohere-embed-operation",
97+
"root_span_id": "<span:1>",
98+
"span_id": "<span:6>",
99+
"span_parents": [
100+
"<span:1>"
101+
],
102+
"type": null
103+
},
104+
{
105+
"has_input": true,
106+
"has_output": true,
107+
"metadata": {
108+
"inputType": "search_document",
109+
"model": "embed-english-v3.0",
110+
"provider": "cohere"
111+
},
112+
"metric_keys": [
113+
"prompt_tokens"
114+
],
115+
"name": "cohere.embed",
116+
"root_span_id": "<span:1>",
117+
"span_id": "<span:7>",
118+
"span_parents": [
119+
"<span:6>"
120+
],
121+
"type": "llm"
122+
},
123+
{
124+
"has_input": false,
125+
"has_output": false,
126+
"metadata": {
127+
"operation": "rerank"
128+
},
129+
"metric_keys": [],
130+
"name": "cohere-rerank-operation",
131+
"root_span_id": "<span:1>",
132+
"span_id": "<span:8>",
133+
"span_parents": [
134+
"<span:1>"
135+
],
136+
"type": null
137+
},
138+
{
139+
"has_input": true,
140+
"has_output": true,
141+
"metadata": {
142+
"document_count": 3,
143+
"model": "rerank-english-v3.0",
144+
"provider": "cohere",
145+
"topN": 2
146+
},
147+
"metric_keys": [
148+
"search_units"
149+
],
150+
"name": "cohere.rerank",
151+
"root_span_id": "<span:1>",
152+
"span_id": "<span:9>",
153+
"span_parents": [
154+
"<span:8>"
155+
],
156+
"type": "llm"
157+
}
158+
]
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
[
2+
{
3+
"has_input": false,
4+
"has_output": false,
5+
"metadata": {
6+
"scenario": "cohere-instrumentation"
7+
},
8+
"metric_keys": [],
9+
"name": "cohere-instrumentation-root",
10+
"root_span_id": "<span:1>",
11+
"span_id": "<span:1>",
12+
"span_parents": [],
13+
"type": "task"
14+
},
15+
{
16+
"has_input": false,
17+
"has_output": false,
18+
"metadata": {
19+
"operation": "chat"
20+
},
21+
"metric_keys": [],
22+
"name": "cohere-chat-operation",
23+
"root_span_id": "<span:1>",
24+
"span_id": "<span:2>",
25+
"span_parents": [
26+
"<span:1>"
27+
],
28+
"type": null
29+
},
30+
{
31+
"has_input": true,
32+
"has_output": true,
33+
"metadata": {
34+
"model": "command-a-03-2025",
35+
"provider": "cohere"
36+
},
37+
"metric_keys": [
38+
"completion_tokens",
39+
"prompt_cached_tokens",
40+
"prompt_tokens",
41+
"time_to_first_token",
42+
"tokens"
43+
],
44+
"name": "cohere.chat",
45+
"root_span_id": "<span:1>",
46+
"span_id": "<span:3>",
47+
"span_parents": [
48+
"<span:2>"
49+
],
50+
"type": "llm"
51+
},
52+
{
53+
"has_input": false,
54+
"has_output": false,
55+
"metadata": {
56+
"operation": "chat-stream"
57+
},
58+
"metric_keys": [],
59+
"name": "cohere-chat-stream-operation",
60+
"root_span_id": "<span:1>",
61+
"span_id": "<span:4>",
62+
"span_parents": [
63+
"<span:1>"
64+
],
65+
"type": null
66+
},
67+
{
68+
"has_input": true,
69+
"has_output": true,
70+
"metadata": {
71+
"model": "command-a-03-2025",
72+
"provider": "cohere"
73+
},
74+
"metric_keys": [
75+
"completion_tokens",
76+
"prompt_cached_tokens",
77+
"prompt_tokens",
78+
"time_to_first_token",
79+
"tokens"
80+
],
81+
"name": "cohere.chatStream",
82+
"root_span_id": "<span:1>",
83+
"span_id": "<span:5>",
84+
"span_parents": [
85+
"<span:4>"
86+
],
87+
"type": "llm"
88+
},
89+
{
90+
"has_input": false,
91+
"has_output": false,
92+
"metadata": {
93+
"operation": "embed"
94+
},
95+
"metric_keys": [],
96+
"name": "cohere-embed-operation",
97+
"root_span_id": "<span:1>",
98+
"span_id": "<span:6>",
99+
"span_parents": [
100+
"<span:1>"
101+
],
102+
"type": null
103+
},
104+
{
105+
"has_input": true,
106+
"has_output": true,
107+
"metadata": {
108+
"inputType": "search_document",
109+
"model": "embed-english-v3.0",
110+
"provider": "cohere"
111+
},
112+
"metric_keys": [
113+
"prompt_tokens"
114+
],
115+
"name": "cohere.embed",
116+
"root_span_id": "<span:1>",
117+
"span_id": "<span:7>",
118+
"span_parents": [
119+
"<span:6>"
120+
],
121+
"type": "llm"
122+
},
123+
{
124+
"has_input": false,
125+
"has_output": false,
126+
"metadata": {
127+
"operation": "rerank"
128+
},
129+
"metric_keys": [],
130+
"name": "cohere-rerank-operation",
131+
"root_span_id": "<span:1>",
132+
"span_id": "<span:8>",
133+
"span_parents": [
134+
"<span:1>"
135+
],
136+
"type": null
137+
},
138+
{
139+
"has_input": true,
140+
"has_output": true,
141+
"metadata": {
142+
"document_count": 3,
143+
"model": "rerank-english-v3.0",
144+
"provider": "cohere",
145+
"topN": 2
146+
},
147+
"metric_keys": [
148+
"search_units"
149+
],
150+
"name": "cohere.rerank",
151+
"root_span_id": "<span:1>",
152+
"span_id": "<span:9>",
153+
"span_parents": [
154+
"<span:8>"
155+
],
156+
"type": "llm"
157+
}
158+
]

0 commit comments

Comments
 (0)