observa-sdk 0.0.2 → 0.0.3
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/dist/index.cjs +38 -26
- package/dist/index.js +38 -26
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -427,39 +427,51 @@ var Observa = class {
|
|
|
427
427
|
}
|
|
428
428
|
try {
|
|
429
429
|
const url = `${this.apiUrl}/api/v1/traces/ingest`;
|
|
430
|
-
console.log(`[Observa] Sending trace
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
errorJson
|
|
448
|
-
|
|
449
|
-
|
|
430
|
+
console.log(`[Observa] Sending trace - URL: ${url}, TraceID: ${trace.traceId}, Tenant: ${trace.tenantId}, Project: ${trace.projectId}, APIKey: ${this.apiKey ? `Yes(${this.apiKey.length} chars)` : "No"}`);
|
|
431
|
+
const controller = new AbortController();
|
|
432
|
+
const timeoutId = setTimeout(() => controller.abort(), 1e4);
|
|
433
|
+
try {
|
|
434
|
+
const response = await fetch(url, {
|
|
435
|
+
method: "POST",
|
|
436
|
+
headers: {
|
|
437
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
438
|
+
"Content-Type": "application/json"
|
|
439
|
+
},
|
|
440
|
+
body: JSON.stringify(trace),
|
|
441
|
+
signal: controller.signal
|
|
442
|
+
});
|
|
443
|
+
clearTimeout(timeoutId);
|
|
444
|
+
console.log(`[Observa] Response status: ${response.status} ${response.statusText}`);
|
|
445
|
+
if (!response.ok) {
|
|
446
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
447
|
+
let errorJson;
|
|
448
|
+
try {
|
|
449
|
+
errorJson = JSON.parse(errorText);
|
|
450
|
+
} catch {
|
|
451
|
+
errorJson = { error: errorText };
|
|
452
|
+
}
|
|
453
|
+
console.error(
|
|
454
|
+
`[Observa] Backend API error: ${response.status} ${response.statusText}`,
|
|
455
|
+
errorJson.error || errorText
|
|
456
|
+
);
|
|
457
|
+
} else {
|
|
458
|
+
console.log(`\u2705 [Observa] Trace sent successfully - Trace ID: ${trace.traceId}`);
|
|
450
459
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
460
|
+
} catch (fetchError) {
|
|
461
|
+
clearTimeout(timeoutId);
|
|
462
|
+
if (fetchError instanceof Error && fetchError.name === "AbortError") {
|
|
463
|
+
console.error("[Observa] Request timeout after 10 seconds");
|
|
464
|
+
}
|
|
465
|
+
throw fetchError;
|
|
457
466
|
}
|
|
458
467
|
} catch (error) {
|
|
459
468
|
console.error("[Observa] Failed to send trace:", error);
|
|
460
469
|
if (error instanceof Error) {
|
|
461
470
|
console.error("[Observa] Error message:", error.message);
|
|
462
471
|
console.error("[Observa] Error name:", error.name);
|
|
472
|
+
if (error.name === "AbortError") {
|
|
473
|
+
console.error("[Observa] Request timed out - check network connectivity and API URL");
|
|
474
|
+
}
|
|
463
475
|
if (error.stack) {
|
|
464
476
|
console.error("[Observa] Error stack:", error.stack);
|
|
465
477
|
}
|
package/dist/index.js
CHANGED
|
@@ -402,39 +402,51 @@ var Observa = class {
|
|
|
402
402
|
}
|
|
403
403
|
try {
|
|
404
404
|
const url = `${this.apiUrl}/api/v1/traces/ingest`;
|
|
405
|
-
console.log(`[Observa] Sending trace
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
errorJson
|
|
423
|
-
|
|
424
|
-
|
|
405
|
+
console.log(`[Observa] Sending trace - URL: ${url}, TraceID: ${trace.traceId}, Tenant: ${trace.tenantId}, Project: ${trace.projectId}, APIKey: ${this.apiKey ? `Yes(${this.apiKey.length} chars)` : "No"}`);
|
|
406
|
+
const controller = new AbortController();
|
|
407
|
+
const timeoutId = setTimeout(() => controller.abort(), 1e4);
|
|
408
|
+
try {
|
|
409
|
+
const response = await fetch(url, {
|
|
410
|
+
method: "POST",
|
|
411
|
+
headers: {
|
|
412
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
413
|
+
"Content-Type": "application/json"
|
|
414
|
+
},
|
|
415
|
+
body: JSON.stringify(trace),
|
|
416
|
+
signal: controller.signal
|
|
417
|
+
});
|
|
418
|
+
clearTimeout(timeoutId);
|
|
419
|
+
console.log(`[Observa] Response status: ${response.status} ${response.statusText}`);
|
|
420
|
+
if (!response.ok) {
|
|
421
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
422
|
+
let errorJson;
|
|
423
|
+
try {
|
|
424
|
+
errorJson = JSON.parse(errorText);
|
|
425
|
+
} catch {
|
|
426
|
+
errorJson = { error: errorText };
|
|
427
|
+
}
|
|
428
|
+
console.error(
|
|
429
|
+
`[Observa] Backend API error: ${response.status} ${response.statusText}`,
|
|
430
|
+
errorJson.error || errorText
|
|
431
|
+
);
|
|
432
|
+
} else {
|
|
433
|
+
console.log(`\u2705 [Observa] Trace sent successfully - Trace ID: ${trace.traceId}`);
|
|
425
434
|
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
435
|
+
} catch (fetchError) {
|
|
436
|
+
clearTimeout(timeoutId);
|
|
437
|
+
if (fetchError instanceof Error && fetchError.name === "AbortError") {
|
|
438
|
+
console.error("[Observa] Request timeout after 10 seconds");
|
|
439
|
+
}
|
|
440
|
+
throw fetchError;
|
|
432
441
|
}
|
|
433
442
|
} catch (error) {
|
|
434
443
|
console.error("[Observa] Failed to send trace:", error);
|
|
435
444
|
if (error instanceof Error) {
|
|
436
445
|
console.error("[Observa] Error message:", error.message);
|
|
437
446
|
console.error("[Observa] Error name:", error.name);
|
|
447
|
+
if (error.name === "AbortError") {
|
|
448
|
+
console.error("[Observa] Request timed out - check network connectivity and API URL");
|
|
449
|
+
}
|
|
438
450
|
if (error.stack) {
|
|
439
451
|
console.error("[Observa] Error stack:", error.stack);
|
|
440
452
|
}
|
package/package.json
CHANGED