@traceai/cohere 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +78 -369
  2. package/dist/esm/attributes.d.ts +11 -0
  3. package/dist/esm/attributes.d.ts.map +1 -0
  4. package/dist/esm/attributes.js +240 -0
  5. package/dist/esm/attributes.js.map +1 -0
  6. package/dist/esm/instrumentation.d.ts +11 -20
  7. package/dist/esm/instrumentation.d.ts.map +1 -1
  8. package/dist/esm/instrumentation.js +175 -344
  9. package/dist/esm/instrumentation.js.map +1 -1
  10. package/dist/esm/stream.d.ts +6 -0
  11. package/dist/esm/stream.d.ts.map +1 -0
  12. package/dist/esm/stream.js +215 -0
  13. package/dist/esm/stream.js.map +1 -0
  14. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  15. package/dist/esm/version.d.ts +1 -1
  16. package/dist/esm/version.js +1 -1
  17. package/dist/esm/version.js.map +1 -1
  18. package/dist/esnext/attributes.d.ts +11 -0
  19. package/dist/esnext/attributes.d.ts.map +1 -0
  20. package/dist/esnext/attributes.js +248 -0
  21. package/dist/esnext/attributes.js.map +1 -0
  22. package/dist/esnext/instrumentation.d.ts +11 -20
  23. package/dist/esnext/instrumentation.d.ts.map +1 -1
  24. package/dist/esnext/instrumentation.js +178 -331
  25. package/dist/esnext/instrumentation.js.map +1 -1
  26. package/dist/esnext/stream.d.ts +6 -0
  27. package/dist/esnext/stream.d.ts.map +1 -0
  28. package/dist/esnext/stream.js +203 -0
  29. package/dist/esnext/stream.js.map +1 -0
  30. package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
  31. package/dist/esnext/version.d.ts +1 -1
  32. package/dist/esnext/version.js +1 -1
  33. package/dist/esnext/version.js.map +1 -1
  34. package/dist/src/__tests__/attributes.test.d.ts +2 -0
  35. package/dist/src/__tests__/attributes.test.d.ts.map +1 -0
  36. package/dist/src/__tests__/attributes.test.js +50 -0
  37. package/dist/src/__tests__/attributes.test.js.map +1 -0
  38. package/dist/src/__tests__/auto.test.d.ts +2 -0
  39. package/dist/src/__tests__/auto.test.d.ts.map +1 -0
  40. package/dist/src/__tests__/auto.test.js +70 -0
  41. package/dist/src/__tests__/auto.test.js.map +1 -0
  42. package/dist/src/__tests__/instrumentation.test.js +1 -1
  43. package/dist/src/__tests__/instrumentation.test.js.map +1 -1
  44. package/dist/src/__tests__/lifecycle.test.d.ts +2 -0
  45. package/dist/src/__tests__/lifecycle.test.d.ts.map +1 -0
  46. package/dist/src/__tests__/lifecycle.test.js +232 -0
  47. package/dist/src/__tests__/lifecycle.test.js.map +1 -0
  48. package/dist/src/__tests__/metadata.test.d.ts +2 -0
  49. package/dist/src/__tests__/metadata.test.d.ts.map +1 -0
  50. package/dist/src/__tests__/metadata.test.js +320 -0
  51. package/dist/src/__tests__/metadata.test.js.map +1 -0
  52. package/dist/src/__tests__/sdk.test.d.ts +2 -0
  53. package/dist/src/__tests__/sdk.test.d.ts.map +1 -0
  54. package/dist/src/__tests__/sdk.test.js +883 -0
  55. package/dist/src/__tests__/sdk.test.js.map +1 -0
  56. package/dist/src/__tests__/timing.test.d.ts +2 -0
  57. package/dist/src/__tests__/timing.test.d.ts.map +1 -0
  58. package/dist/src/__tests__/timing.test.js +158 -0
  59. package/dist/src/__tests__/timing.test.js.map +1 -0
  60. package/dist/src/attributes.d.ts +11 -0
  61. package/dist/src/attributes.d.ts.map +1 -0
  62. package/dist/src/attributes.js +257 -0
  63. package/dist/src/attributes.js.map +1 -0
  64. package/dist/src/instrumentation.d.ts +11 -20
  65. package/dist/src/instrumentation.d.ts.map +1 -1
  66. package/dist/src/instrumentation.js +176 -329
  67. package/dist/src/instrumentation.js.map +1 -1
  68. package/dist/src/stream.d.ts +6 -0
  69. package/dist/src/stream.d.ts.map +1 -0
  70. package/dist/src/stream.js +215 -0
  71. package/dist/src/stream.js.map +1 -0
  72. package/dist/src/version.d.ts +1 -1
  73. package/dist/src/version.js +1 -1
  74. package/dist/src/version.js.map +1 -1
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +18 -11
package/README.md CHANGED
@@ -1,436 +1,145 @@
1
1
  # @traceai/cohere
2
2
 
3
- OpenTelemetry instrumentation for the [Cohere](https://cohere.com/) TypeScript/JavaScript SDK.
3
+ Trace Cohere chat, streaming chat, embeddings and reranking in Future AGI with the maintained Cohere SDK instrumentor.
4
4
 
5
- ## Installation
5
+ ## Install
6
6
 
7
7
  ```bash
8
- npm install @traceai/cohere
9
- # or
10
- pnpm add @traceai/cohere
11
- # or
12
- yarn add @traceai/cohere
8
+ npm install @traceai/cohere @traceai/fi-core cohere-ai
13
9
  ```
14
10
 
15
- ## Features
11
+ Use Node.js 18 or later and `cohere-ai` 7.x or 8.x. Use `cohere-ai` 8.3.0 for the v2 examples below. The 7.0.0 SDK only exposes the older v1 operations; streaming requires a version with `chatStream`.
16
12
 
17
- - Automatic instrumentation of Cohere API calls
18
- - Supports chat, embed, and rerank APIs
19
- - Captures request parameters, model information, and responses
20
- - Configurable input/output hiding for privacy
21
- - Compatible with OpenTelemetry ecosystem
13
+ ## Configure tracing
22
14
 
23
- ## Usage
15
+ Set `FI_API_KEY`, `FI_SECRET_KEY` and `COHERE_API_KEY` in your environment. Get your Future AGI credentials from your organization's settings.
24
16
 
25
- ### Basic Setup
17
+ Initialize tracing **before constructing any Cohere clients**. Explicit module instrumentation works with both CommonJS and native ESM, without an import hook or copied tracing helpers.
26
18
 
27
19
  ```typescript
20
+ import { register, ProjectType } from "@traceai/fi-core";
28
21
  import { CohereInstrumentation } from "@traceai/cohere";
29
- import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
30
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
31
-
32
- // Set up the tracer provider
33
- const provider = new NodeTracerProvider();
34
- provider.register();
35
-
36
- // Register the Cohere instrumentation
37
- registerInstrumentations({
38
- instrumentations: [new CohereInstrumentation()],
39
- });
40
-
41
- // Now use the Cohere SDK as normal
42
- import { CohereClient } from "cohere-ai";
43
-
44
- const cohere = new CohereClient({
45
- token: process.env.COHERE_API_KEY,
46
- });
47
-
48
- // Chat example
49
- const chatResponse = await cohere.chat({
50
- message: "Hello, how are you?",
51
- model: "command-r-08-2024",
52
- });
53
-
54
- // Embed example
55
- const embedResponse = await cohere.embed({
56
- texts: ["hello", "goodbye"],
57
- model: "embed-english-v3.0",
58
- inputType: "search_document",
59
- });
22
+ import * as Cohere from "cohere-ai";
60
23
 
61
- // Rerank example
62
- const rerankResponse = await cohere.rerank({
63
- query: "What is the capital of France?",
64
- documents: [
65
- "Paris is the capital of France.",
66
- "Berlin is the capital of Germany.",
67
- "London is the capital of the United Kingdom.",
68
- ],
69
- model: "rerank-english-v3.0",
24
+ const provider = register({
25
+ projectName: "cohere-app",
26
+ projectType: ProjectType.OBSERVE,
70
27
  });
71
- ```
72
-
73
- ### Manual Instrumentation
74
-
75
- If automatic instrumentation doesn't work (e.g., with bundlers), you can manually instrument:
76
-
77
- ```typescript
78
- import { CohereInstrumentation } from "@traceai/cohere";
79
- import * as CohereModule from "cohere-ai";
80
28
 
81
- const instrumentation = new CohereInstrumentation();
82
- instrumentation.manuallyInstrument(CohereModule);
83
- ```
84
-
85
- ### Configuration Options
86
-
87
- ```typescript
88
29
  const instrumentation = new CohereInstrumentation({
89
- // OpenTelemetry instrumentation config
90
- instrumentationConfig: {
91
- enabled: true,
92
- },
93
- // TraceAI-specific config
94
30
  traceConfig: {
95
- hideInputs: false, // Set to true to hide input content in traces
96
- hideOutputs: false, // Set to true to hide output content in traces
31
+ hideInputs: true,
32
+ hideOutputs: true,
33
+ hideEmbeddingVectors: true,
97
34
  },
98
35
  });
99
- ```
100
-
101
- ### With TraceAI Core
36
+ instrumentation.setTracerProvider(provider);
37
+ instrumentation.manuallyInstrument(Cohere);
102
38
 
103
- ```typescript
104
- import { register, ProjectType } from "@traceai/fi-core";
105
- import { CohereInstrumentation } from "@traceai/cohere";
106
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
107
-
108
- // 1. Register TraceAI Core TracerProvider
109
- const tracerProvider = register({
110
- projectName: "my-cohere-app",
111
- projectType: ProjectType.OBSERVE,
112
- sessionName: "cohere-session-" + Date.now(),
113
- });
114
-
115
- // 2. Register instrumentation BEFORE importing Cohere SDK
116
- registerInstrumentations({
117
- tracerProvider: tracerProvider,
118
- instrumentations: [new CohereInstrumentation()],
119
- });
120
-
121
- // 3. NOW import and use Cohere
122
- const { CohereClient } = await import("cohere-ai");
123
- const client = new CohereClient({ token: process.env.COHERE_API_KEY });
124
-
125
- // 4. Use normally - all calls are traced
126
- const response = await client.chat({
127
- message: "Hello!",
128
- model: "command-r-08-2024",
39
+ const client = new Cohere.CohereClientV2({
40
+ token: process.env.COHERE_API_KEY,
129
41
  });
130
42
 
131
- // 5. Shutdown when done
132
- await tracerProvider.shutdown();
133
- ```
134
-
135
- ## Real-World Use Cases
136
-
137
- ### 1. Conversational AI with Chat History
138
-
139
- ```typescript
140
- const { CohereClient } = await import("cohere-ai");
141
- const client = new CohereClient({ token: process.env.COHERE_API_KEY });
142
-
143
- async function chat(message: string, history: Array<{ role: string; message: string }>) {
43
+ try {
144
44
  const response = await client.chat({
145
- message,
146
45
  model: "command-r-08-2024",
147
- chatHistory: history,
148
- preamble: "You are a helpful customer support agent for an e-commerce platform.",
46
+ messages: [{ role: "user", content: "Explain semantic search in one sentence." }],
149
47
  });
150
-
151
- // Add to history
152
- history.push({ role: "USER", message });
153
- history.push({ role: "CHATBOT", message: response.text });
154
-
155
- return response.text;
48
+ console.log(response.message);
49
+ } finally {
50
+ instrumentation.disable();
51
+ await provider.shutdown();
156
52
  }
157
-
158
- // Usage
159
- const history: Array<{ role: string; message: string }> = [];
160
- const answer1 = await chat("I have a problem with my order", history);
161
- const answer2 = await chat("Order ID is 12345", history);
162
53
  ```
163
54
 
164
- ### 2. Semantic Search with Embeddings
165
-
166
- ```typescript
167
- async function semanticSearch(query: string, documents: string[]) {
168
- // Get query embedding (use 'search_query' for queries)
169
- const queryEmbedding = await client.embed({
170
- texts: [query],
171
- model: "embed-english-v3.0",
172
- inputType: "search_query",
173
- });
55
+ Open the **cohere-app** project in Future AGI to inspect the `Cohere Chat` span, model and token usage. This example hides request/response content, embedding vectors and error details. To inspect content in traces, explicitly turn off the corresponding hiding options only when it is safe for your application.
174
56
 
175
- // Get document embeddings (use 'search_document' for documents)
176
- const docEmbeddings = await client.embed({
177
- texts: documents,
178
- model: "embed-english-v3.0",
179
- inputType: "search_document",
180
- });
57
+ If you already have an OpenTelemetry tracer provider, pass it to `setTracerProvider` instead of creating a second provider. For CommonJS auto-instrumentation, register `CohereInstrumentation` with OpenTelemetry before requiring `cohere-ai`; do not also install another Cohere instrumentor.
181
58
 
182
- // Calculate cosine similarities
183
- const queryVector = queryEmbedding.embeddings[0] as number[];
184
- const similarities = (docEmbeddings.embeddings as number[][]).map((docVector, i) => ({
185
- document: documents[i],
186
- score: cosineSimilarity(queryVector, docVector),
187
- }));
59
+ ## Stream a response
188
60
 
189
- return similarities.sort((a, b) => b.score - a.score);
190
- }
191
- ```
192
-
193
- ### 3. Document Reranking for RAG
61
+ With the same initialized client, replace the chat call with:
194
62
 
195
63
  ```typescript
196
- async function rerankDocuments(query: string, documents: string[]) {
197
- const response = await client.rerank({
198
- query,
199
- documents,
200
- model: "rerank-english-v3.0",
201
- topN: 5,
202
- returnDocuments: true,
203
- });
204
-
205
- return response.results.map((result) => ({
206
- document: result.document?.text,
207
- score: result.relevanceScore,
208
- originalIndex: result.index,
209
- }));
210
- }
211
-
212
- // Usage in RAG pipeline
213
- const retrievedDocs = await vectorSearch(userQuery, 20); // Get top 20 from vector DB
214
- const rerankedDocs = await rerankDocuments(userQuery, retrievedDocs);
215
- const topDocs = rerankedDocs.slice(0, 3); // Use top 3 for context
216
- ```
217
-
218
- ### 4. Tool-Augmented Chatbot
219
-
220
- ```typescript
221
- async function chatWithTools(message: string) {
222
- const response = await client.chat({
223
- message,
224
- model: "command-r-08-2024",
225
- tools: [
226
- {
227
- name: "search_database",
228
- description: "Search the product database",
229
- parameterDefinitions: {
230
- query: { type: "str", description: "Search query", required: true },
231
- category: { type: "str", description: "Product category", required: false },
232
- },
233
- },
234
- {
235
- name: "get_order_status",
236
- description: "Get status of a customer order",
237
- parameterDefinitions: {
238
- orderId: { type: "str", description: "Order ID", required: true },
239
- },
240
- },
241
- ],
242
- });
64
+ const stream = await client.chatStream({
65
+ model: "command-r-08-2024",
66
+ messages: [{ role: "user", content: "Explain semantic search in one sentence." }],
67
+ });
243
68
 
244
- if (response.toolCalls && response.toolCalls.length > 0) {
245
- // Execute tool calls and continue conversation
246
- for (const toolCall of response.toolCalls) {
247
- console.log(`Tool: ${toolCall.name}, Args:`, toolCall.parameters);
248
- }
69
+ for await (const event of stream) {
70
+ if (event.type === "content-start" || event.type === "content-delta") {
71
+ process.stdout.write(event.delta?.message?.content?.text ?? "");
249
72
  }
250
-
251
- return response;
252
73
  }
253
74
  ```
254
75
 
255
- ### 5. Multilingual Embeddings
76
+ The span stays open while you consume the stream. It finishes at the terminal event, iterator completion, failure, early return or controller abort. Breaking or returning from the iterator, aborting its controller, or receiving `USER_CANCEL` sets `cohere.stream.cancelled` and leaves the span status unset. A stream that ends without a terminal event is an error, not a cancellation.
256
77
 
257
- ```typescript
258
- async function multilingualSearch(query: string, documents: string[]) {
259
- // Use multilingual model for cross-language search
260
- const queryEmbedding = await client.embed({
261
- texts: [query],
262
- model: "embed-multilingual-v3.0",
263
- inputType: "search_query",
264
- });
78
+ For both chat and streaming chat, `ERROR`, `ERROR_TOXIC`, `ERROR_LIMIT` and `TIMEOUT` finish reasons mark the span as an error. A nonstreaming `USER_CANCEL` response sets `cohere.request.cancelled` with an unset status. Partial generated output is retained when content capture is enabled; token counts are available only if Cohere sends usage. These telemetry statuses do not change SDK results or turn resolved responses into exceptions.
265
79
 
266
- const docEmbeddings = await client.embed({
267
- texts: documents,
268
- model: "embed-multilingual-v3.0",
269
- inputType: "search_document",
270
- });
271
-
272
- // Works across languages!
273
- // Query in English can match documents in French, German, Spanish, etc.
274
- return calculateSimilarities(queryEmbedding, docEmbeddings);
275
- }
276
- ```
80
+ Consume the stream or explicitly close/abort it rather than abandoning it. SDK stream controllers, events and `withRawResponse()` remain available.
277
81
 
278
- ### 6. Streaming Chat Responses
82
+ ## Embed and rerank
279
83
 
280
84
  ```typescript
281
- async function streamChat(message: string) {
282
- const stream = await client.chatStream({
283
- message,
284
- model: "command-r-08-2024",
285
- });
286
-
287
- let fullText = "";
288
- for await (const event of stream) {
289
- if (event.eventType === "text-generation") {
290
- process.stdout.write(event.text);
291
- fullText += event.text;
292
- } else if (event.eventType === "stream-end") {
293
- console.log("\n--- Stream complete ---");
294
- console.log("Token usage:", event.response?.meta?.tokens);
295
- }
296
- }
85
+ await client.embed({
86
+ model: "embed-english-v3.0",
87
+ texts: ["Paris is the capital of France."],
88
+ inputType: "search_document",
89
+ embeddingTypes: ["float"],
90
+ });
297
91
 
298
- return fullText;
299
- }
92
+ await client.rerank({
93
+ model: "rerank-v3.5",
94
+ query: "What is the capital of France?",
95
+ documents: ["Paris is the capital of France.", "Berlin is the capital of Germany."],
96
+ topN: 1,
97
+ });
300
98
  ```
301
99
 
302
- ## Traced Operations
100
+ Embeddings use the `EMBEDDING` span kind; reranking uses `RERANKER`, including result indices and relevance scores. Chat uses `LLM`. The instrumentor reads the SDK's camelCase properties, including `chatHistory`, `toolCalls`, `inputTokens` and `relevanceScore`, and retains support for v1 payloads.
303
101
 
304
- ### Chat API
102
+ ## Usage, provenance and streaming timing
305
103
 
306
- The instrumentation captures:
104
+ The following numeric attributes are captured independently of input/output hiding:
307
105
 
308
- - Model name
309
- - Input messages and chat history
310
- - Preamble and connectors
311
- - Temperature and other generation parameters
312
- - Response text and metadata
313
- - Token usage (prompt and completion tokens)
106
+ | Attribute | Meaning |
107
+ | --- | --- |
108
+ | `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`, `gen_ai.usage.total_tokens` | Actual tokens when supplied. For older responses without `tokens`, input/output billed units remain the fallback. |
109
+ | `gen_ai.usage.cache_read_tokens` | Cohere's supplied `cachedTokens` (cached prompt tokens); not added to the total again. |
110
+ | `cohere.usage.billed_units.input_tokens`, `cohere.usage.billed_units.output_tokens` | Separately supplied billable tokens, which can differ from actual tokens. |
111
+ | `cohere.usage.billed_units.search_units`, `cohere.usage.billed_units.classifications` | Supplied billable operation units, not token counts. |
112
+ | `cohere.usage.billed_units.images`, `cohere.usage.billed_units.image_tokens` | Supplied billable image counts and image tokens, respectively. |
113
+ | `cohere.stream.time_to_first_token_ms` | Monotonic elapsed milliseconds from SDK request invocation until the first consumed nonempty generated text, reasoning, tool plan, or tool name/argument fragment. |
314
114
 
315
- ### Embed API
115
+ Missing usage is not synthesized. First-token timing includes request/headers latency and any delay before the consumer reads the first content event; it is not server-side inference timing. Metadata-only, empty, or cancelled-before-content streams have no timing value. A recorded value survives later cancellation or failure and is not replaced by subsequent chunks.
316
116
 
317
- The instrumentation captures:
117
+ `gen_ai.response.id` retains the provider generation/response ID, including IDs delivered at stream start, even when content is hidden or the stream later fails or is cancelled.
318
118
 
319
- - Model name
320
- - Input texts
321
- - Input type
322
- - Truncation settings
323
- - Output embeddings (unless hidden)
324
- - Token usage
119
+ With output capture enabled, v2 streamed citations are accumulated by index in `gen_ai.output.messages` and `raw.output`, including partial streams. Input hiding retains citation offsets, generated citation text and source IDs/types but removes source document/tool bodies. Output hiding omits citations along with the rest of the generated content. These projections never change the SDK events or responses delivered to your application.
325
120
 
326
- ### Rerank API
121
+ ## Existing v1 applications
327
122
 
328
- The instrumentation captures:
123
+ Keep using `CohereClient`, `CohereInstrumentation` and `manuallyInstrument` with the same setup. Calls through `CohereClient.v2` and `CohereClientV2` are also traced when available in your SDK. Disable/enable applies to subsequent calls, including already-bound v2 methods; in-flight calls finish their spans normally.
329
124
 
330
- - Model name
331
- - Query text
332
- - Documents to rerank
333
- - Top N parameter
334
- - Reranked results with relevance scores
125
+ This integration covers `chat`, `chatStream`, `embed` and `rerank`, not every endpoint on the Cohere SDK. It does not infer a default model when no model was supplied.
335
126
 
336
- ## Semantic Conventions
127
+ ## Troubleshooting
337
128
 
338
- This instrumentation follows OpenTelemetry semantic conventions and FutureAGI conventions for LLM observability:
129
+ - **No v2 spans:** initialize instrumentation before constructing the client. V2 binds its methods in the constructor; recreate clients constructed before setup.
130
+ - **Duplicate spans:** use one Cohere instrumentor per application and remove overlapping instrumentation.
131
+ - **A stream span never finishes:** consume the stream, break/return from its iterator, or abort its controller before shutting down the provider.
132
+ - **Missing content or vectors:** check your `traceConfig` and `FI_HIDE_*` environment settings. Input/output hiding also applies to Cohere-specific fields and raw payloads; vector hiding excludes the raw embedding response. Connector access tokens are always omitted from telemetry, regardless of content settings; requests to Cohere retain them.
339
133
 
340
- - Span names follow the pattern: `cohere.{operation}` (e.g., `cohere.chat`, `cohere.embed`, `cohere.rerank`)
341
- - Uses `LLM` span kind for chat operations
342
- - Uses `EMBEDDING` span kind for embed operations
343
- - Uses `RERANKER` span kind for rerank operations
134
+ ## Development
344
135
 
345
- ## Supported Models
346
-
347
- ### Chat Models
348
-
349
- - command
350
- - command-r
351
- - command-r-08-2024
352
- - command-light
353
- - command-nightly
354
-
355
- ### Embedding Models
356
-
357
- - embed-english-v3.0
358
- - embed-multilingual-v3.0
359
- - embed-english-light-v3.0
360
- - embed-multilingual-light-v3.0
361
-
362
- ### Rerank Models
363
-
364
- - rerank-english-v3.0
365
- - rerank-multilingual-v3.0
366
- - rerank-english-v2.0
367
- - rerank-multilingual-v2.0
368
-
369
- ## Requirements
370
-
371
- - Node.js >= 18
372
- - cohere-ai SDK
373
-
374
- ## Running Examples
375
-
376
- The `examples/` directory contains real-world examples:
136
+ From the TypeScript workspace, build shared packages and the instrumentor before running its offline suite:
377
137
 
378
138
  ```bash
379
- cd examples
380
- cp .env.example .env
381
- # Edit .env with your API keys
382
-
383
- pnpm install
384
- pnpm run example
385
- ```
386
-
387
- ## E2E Testing
388
-
389
- Run E2E tests with real API keys:
390
-
391
- ```bash
392
- COHERE_API_KEY=your_key pnpm test -- --testPathPattern=e2e
393
- ```
394
-
395
- ## Integration with TraceAI Platform
396
-
397
- ```typescript
398
- import { CohereInstrumentation } from "@traceai/cohere";
399
- import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
400
- import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
401
- import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
402
- import { Resource } from "@opentelemetry/resources";
403
-
404
- const provider = new NodeTracerProvider({
405
- resource: new Resource({
406
- "service.name": "my-cohere-app",
407
- "deployment.environment": "production",
408
- }),
409
- });
410
-
411
- const exporter = new OTLPTraceExporter({
412
- url: "https://api.traceai.com/v1/traces",
413
- headers: {
414
- Authorization: `Bearer ${process.env.TRACEAI_API_KEY}`,
415
- },
416
- });
417
-
418
- provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
419
- provider.register();
420
-
421
- const instrumentation = new CohereInstrumentation();
422
- instrumentation.manuallyInstrument(require("cohere-ai"));
139
+ pnpm --filter '@traceai/cohere...' --workspace-concurrency=1 run build
140
+ pnpm --filter '@traceai/cohere' exec jest --runInBand
423
141
  ```
424
142
 
425
143
  ## License
426
144
 
427
145
  Apache-2.0
428
-
429
- ## Related Packages
430
-
431
- - [@traceai/openai](../traceai_openai) - OpenAI instrumentation
432
- - [@traceai/anthropic](../traceai_anthropic) - Anthropic instrumentation
433
- - [@traceai/groq](../traceai_groq) - Groq instrumentation
434
- - [@traceai/mistral](../traceai_mistral) - Mistral instrumentation
435
- - [@traceai/google-genai](../traceai_google_genai) - Google GenAI instrumentation
436
- - [@traceai/fi-core](../fi-core) - Core tracing utilities
@@ -0,0 +1,11 @@
1
+ import { Attributes } from "@opentelemetry/api";
2
+ import { TraceConfig } from "@traceai/fi-core";
3
+ export type Operation = "chat" | "chatStream" | "embed" | "rerank";
4
+ export type Data = Record<string, unknown>;
5
+ export declare const object: (value: unknown) => Data;
6
+ export declare const list: (value: unknown) => unknown[];
7
+ export declare const hideInput: (config: TraceConfig) => boolean;
8
+ export declare const hideOutput: (config: TraceConfig) => boolean;
9
+ export declare function inputAttributes(operation: Operation, request: Data, config: TraceConfig): Attributes;
10
+ export declare function outputAttributes(operation: Operation, response: Data, config: TraceConfig): Attributes;
11
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/attributes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAuB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AACnE,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3C,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,KAAG,IAAwE,CAAC;AACjH,eAAO,MAAM,IAAI,GAAI,OAAO,OAAO,KAAG,OAAO,EAAuC,CAAC;AAGrF,eAAO,MAAM,SAAS,GAAI,QAAQ,WAAW,YAAoG,CAAC;AAClJ,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,YAA6E,CAAC;AAgB5H,wBAAgB,eAAe,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,GAAG,UAAU,CA2DpG;AAyDD,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,GAAG,UAAU,CAkDtG"}