observa-sdk 0.0.1 → 0.0.2

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.
package/README.md CHANGED
@@ -15,6 +15,7 @@ npm install observa-sdk
15
15
  Get your API key by signing up at [https://app.observa.ai/signup](https://app.observa.ai/signup) (or your Observa API endpoint).
16
16
 
17
17
  The signup process automatically:
18
+
18
19
  - Creates your tenant account
19
20
  - Sets up a default "Production" project
20
21
  - Provisions your Tinybird token
@@ -53,12 +54,15 @@ const observa = init({
53
54
  });
54
55
 
55
56
  // Track AI interactions with simple wrapping
56
- const response = await observa.track(
57
- { query: "What is the weather?" },
58
- () => fetch("https://api.openai.com/v1/chat/completions", {
57
+ const response = await observa.track({ query: "What is the weather?" }, () =>
58
+ fetch("https://api.openai.com/v1/chat/completions", {
59
59
  method: "POST",
60
- headers: { /* ... */ },
61
- body: JSON.stringify({ /* ... */ }),
60
+ headers: {
61
+ /* ... */
62
+ },
63
+ body: JSON.stringify({
64
+ /* ... */
65
+ }),
62
66
  })
63
67
  );
64
68
  ```
@@ -116,6 +120,7 @@ The SDK supports JWT-formatted API keys that encode tenant context:
116
120
  ```
117
121
 
118
122
  **JWT Structure**:
123
+
119
124
  - `tenantId` (required): Unique identifier for the tenant/organization
120
125
  - `projectId` (required): Project identifier within the tenant
121
126
  - `environment` (optional): `"dev"` or `"prod"` (defaults to `"dev"`)
@@ -163,6 +168,7 @@ Initialize the Observa SDK instance.
163
168
  Track an AI interaction.
164
169
 
165
170
  **Parameters**:
171
+
166
172
  - `event.query` (required): The user query/prompt
167
173
  - `event.context` (optional): Additional context
168
174
  - `event.model` (optional): Model identifier
@@ -172,6 +178,7 @@ Track an AI interaction.
172
178
  **Returns**: `Promise<Response>` (the original response, unmodified)
173
179
 
174
180
  **Example**:
181
+
175
182
  ```typescript
176
183
  const response = await observa.track(
177
184
  {
@@ -179,17 +186,18 @@ const response = await observa.track(
179
186
  model: "gpt-4",
180
187
  metadata: { userId: "123" },
181
188
  },
182
- () => fetch("https://api.openai.com/v1/chat/completions", {
183
- method: "POST",
184
- headers: {
185
- "Authorization": `Bearer ${openaiKey}`,
186
- "Content-Type": "application/json",
187
- },
188
- body: JSON.stringify({
189
- model: "gpt-4",
190
- messages: [{ role: "user", content: "What is machine learning?" }],
191
- }),
192
- })
189
+ () =>
190
+ fetch("https://api.openai.com/v1/chat/completions", {
191
+ method: "POST",
192
+ headers: {
193
+ Authorization: `Bearer ${openaiKey}`,
194
+ "Content-Type": "application/json",
195
+ },
196
+ body: JSON.stringify({
197
+ model: "gpt-4",
198
+ messages: [{ role: "user", content: "What is machine learning?" }],
199
+ }),
200
+ })
193
201
  );
194
202
  ```
195
203
 
@@ -248,4 +256,3 @@ The entire onboarding process takes less than 5 minutes, and you can start track
248
256
  ## License
249
257
 
250
258
  MIT
251
-
package/dist/index.cjs CHANGED
@@ -427,6 +427,10 @@ var Observa = class {
427
427
  }
428
428
  try {
429
429
  const url = `${this.apiUrl}/api/v1/traces/ingest`;
430
+ console.log(`[Observa] Sending trace to: ${url}`);
431
+ console.log(`[Observa] Trace ID: ${trace.traceId}`);
432
+ console.log(`[Observa] Tenant: ${trace.tenantId}, Project: ${trace.projectId}`);
433
+ console.log(`[Observa] API Key present: ${this.apiKey ? "Yes" : "No"} (length: ${this.apiKey?.length || 0})`);
430
434
  const response = await fetch(url, {
431
435
  method: "POST",
432
436
  headers: {
@@ -435,6 +439,7 @@ var Observa = class {
435
439
  },
436
440
  body: JSON.stringify(trace)
437
441
  });
442
+ console.log(`[Observa] Response status: ${response.status} ${response.statusText}`);
438
443
  if (!response.ok) {
439
444
  const errorText = await response.text().catch(() => "Unknown error");
440
445
  let errorJson;
@@ -447,12 +452,18 @@ var Observa = class {
447
452
  `[Observa] Backend API error: ${response.status} ${response.statusText}`,
448
453
  errorJson.error || errorText
449
454
  );
450
- } else if (!this.isProduction) {
451
- console.log(`\u2705 [Observa] Trace sent successfully`);
452
- console.log(` Trace ID: ${trace.traceId}`);
455
+ } else {
456
+ console.log(`\u2705 [Observa] Trace sent successfully - Trace ID: ${trace.traceId}`);
453
457
  }
454
458
  } catch (error) {
455
459
  console.error("[Observa] Failed to send trace:", error);
460
+ if (error instanceof Error) {
461
+ console.error("[Observa] Error message:", error.message);
462
+ console.error("[Observa] Error name:", error.name);
463
+ if (error.stack) {
464
+ console.error("[Observa] Error stack:", error.stack);
465
+ }
466
+ }
456
467
  }
457
468
  }
458
469
  };
package/dist/index.js CHANGED
@@ -402,6 +402,10 @@ var Observa = class {
402
402
  }
403
403
  try {
404
404
  const url = `${this.apiUrl}/api/v1/traces/ingest`;
405
+ console.log(`[Observa] Sending trace to: ${url}`);
406
+ console.log(`[Observa] Trace ID: ${trace.traceId}`);
407
+ console.log(`[Observa] Tenant: ${trace.tenantId}, Project: ${trace.projectId}`);
408
+ console.log(`[Observa] API Key present: ${this.apiKey ? "Yes" : "No"} (length: ${this.apiKey?.length || 0})`);
405
409
  const response = await fetch(url, {
406
410
  method: "POST",
407
411
  headers: {
@@ -410,6 +414,7 @@ var Observa = class {
410
414
  },
411
415
  body: JSON.stringify(trace)
412
416
  });
417
+ console.log(`[Observa] Response status: ${response.status} ${response.statusText}`);
413
418
  if (!response.ok) {
414
419
  const errorText = await response.text().catch(() => "Unknown error");
415
420
  let errorJson;
@@ -422,12 +427,18 @@ var Observa = class {
422
427
  `[Observa] Backend API error: ${response.status} ${response.statusText}`,
423
428
  errorJson.error || errorText
424
429
  );
425
- } else if (!this.isProduction) {
426
- console.log(`\u2705 [Observa] Trace sent successfully`);
427
- console.log(` Trace ID: ${trace.traceId}`);
430
+ } else {
431
+ console.log(`\u2705 [Observa] Trace sent successfully - Trace ID: ${trace.traceId}`);
428
432
  }
429
433
  } catch (error) {
430
434
  console.error("[Observa] Failed to send trace:", error);
435
+ if (error instanceof Error) {
436
+ console.error("[Observa] Error message:", error.message);
437
+ console.error("[Observa] Error name:", error.name);
438
+ if (error.stack) {
439
+ console.error("[Observa] Error stack:", error.stack);
440
+ }
441
+ }
431
442
  }
432
443
  }
433
444
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "observa-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Enterprise-grade observability SDK for AI applications. Track and monitor LLM interactions with zero friction.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",