@arizeai/openinference-instrumentation-openai 4.4.0 → 4.4.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.
- package/dist/esm/instrumentation.d.ts.map +1 -1
- package/dist/esm/instrumentation.js +32 -33
- package/dist/esm/instrumentation.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esnext/instrumentation.d.ts.map +1 -1
- package/dist/esnext/instrumentation.js +32 -33
- package/dist/esnext/instrumentation.js.map +1 -1
- package/dist/esnext/tsconfig.esnext.tsbuildinfo +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.js +32 -33
- package/dist/src/instrumentation.js.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/instrumentation.ts +33 -34
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/instrumentation.ts
CHANGED
|
@@ -327,6 +327,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
327
327
|
},
|
|
328
328
|
});
|
|
329
329
|
const execContext = getExecContext(span);
|
|
330
|
+
const recordError = (error: unknown) => endSpanWithError(span, error);
|
|
330
331
|
const execPromise = safeExecuteInTheMiddle(
|
|
331
332
|
() => {
|
|
332
333
|
return context.with(trace.setSpan(execContext, span), () => {
|
|
@@ -336,12 +337,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
336
337
|
(error) => {
|
|
337
338
|
// Push the error to the span
|
|
338
339
|
if (error) {
|
|
339
|
-
|
|
340
|
-
span.setStatus({
|
|
341
|
-
code: SpanStatusCode.ERROR,
|
|
342
|
-
message: error.message,
|
|
343
|
-
});
|
|
344
|
-
span.end();
|
|
340
|
+
recordError(error);
|
|
345
341
|
}
|
|
346
342
|
},
|
|
347
343
|
);
|
|
@@ -375,6 +371,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
375
371
|
|
|
376
372
|
return result;
|
|
377
373
|
};
|
|
374
|
+
observeRejection(execPromise, recordError);
|
|
378
375
|
const wrappedPromise = invokeMaybeAPIPromise(execPromise, wrappedPromiseThen);
|
|
379
376
|
return context.bind(execContext, wrappedPromise);
|
|
380
377
|
};
|
|
@@ -404,7 +401,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
404
401
|
},
|
|
405
402
|
});
|
|
406
403
|
const execContext = getExecContext(span);
|
|
407
|
-
|
|
404
|
+
const recordError = (error: unknown) => endSpanWithError(span, error);
|
|
408
405
|
const execPromise = safeExecuteInTheMiddle(
|
|
409
406
|
() => {
|
|
410
407
|
return context.with(trace.setSpan(execContext, span), () => {
|
|
@@ -414,12 +411,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
414
411
|
(error) => {
|
|
415
412
|
// Push the error to the span
|
|
416
413
|
if (error) {
|
|
417
|
-
|
|
418
|
-
span.setStatus({
|
|
419
|
-
code: SpanStatusCode.ERROR,
|
|
420
|
-
message: error.message,
|
|
421
|
-
});
|
|
422
|
-
span.end();
|
|
414
|
+
recordError(error);
|
|
423
415
|
}
|
|
424
416
|
},
|
|
425
417
|
);
|
|
@@ -439,6 +431,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
439
431
|
}
|
|
440
432
|
return result;
|
|
441
433
|
};
|
|
434
|
+
observeRejection(execPromise, recordError);
|
|
442
435
|
const wrappedPromise = invokeMaybeAPIPromise(execPromise, wrappedPromiseThen);
|
|
443
436
|
return context.bind(execContext, wrappedPromise);
|
|
444
437
|
};
|
|
@@ -472,6 +465,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
472
465
|
},
|
|
473
466
|
});
|
|
474
467
|
const execContext = getExecContext(span);
|
|
468
|
+
const recordError = (error: unknown) => endSpanWithError(span, error);
|
|
475
469
|
const execPromise = safeExecuteInTheMiddle(
|
|
476
470
|
() => {
|
|
477
471
|
return context.with(trace.setSpan(execContext, span), () => {
|
|
@@ -481,12 +475,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
481
475
|
(error) => {
|
|
482
476
|
// Push the error to the span
|
|
483
477
|
if (error) {
|
|
484
|
-
|
|
485
|
-
span.setStatus({
|
|
486
|
-
code: SpanStatusCode.ERROR,
|
|
487
|
-
message: error.message,
|
|
488
|
-
});
|
|
489
|
-
span.end();
|
|
478
|
+
recordError(error);
|
|
490
479
|
}
|
|
491
480
|
},
|
|
492
481
|
);
|
|
@@ -502,6 +491,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
502
491
|
span.end();
|
|
503
492
|
return result;
|
|
504
493
|
};
|
|
494
|
+
observeRejection(execPromise, recordError);
|
|
505
495
|
const wrappedPromise = invokeMaybeAPIPromise(execPromise, wrappedPromiseThen);
|
|
506
496
|
return context.bind(execContext, wrappedPromise);
|
|
507
497
|
};
|
|
@@ -536,6 +526,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
536
526
|
},
|
|
537
527
|
});
|
|
538
528
|
const execContext = getExecContext(span);
|
|
529
|
+
const recordError = (error: unknown) => endSpanWithError(span, error);
|
|
539
530
|
const execPromise = safeExecuteInTheMiddle(
|
|
540
531
|
() => {
|
|
541
532
|
return context.with(trace.setSpan(execContext, span), () => {
|
|
@@ -545,12 +536,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
545
536
|
(error) => {
|
|
546
537
|
// Push the error to the span
|
|
547
538
|
if (error) {
|
|
548
|
-
|
|
549
|
-
span.setStatus({
|
|
550
|
-
code: SpanStatusCode.ERROR,
|
|
551
|
-
message: error.message,
|
|
552
|
-
});
|
|
553
|
-
span.end();
|
|
539
|
+
recordError(error);
|
|
554
540
|
}
|
|
555
541
|
},
|
|
556
542
|
);
|
|
@@ -588,6 +574,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
588
574
|
|
|
589
575
|
return result;
|
|
590
576
|
};
|
|
577
|
+
observeRejection(execPromise, recordError);
|
|
591
578
|
const wrappedPromise = invokeMaybeAPIPromise(execPromise, wrappedPromiseThen);
|
|
592
579
|
return context.bind(execContext, wrappedPromise);
|
|
593
580
|
};
|
|
@@ -616,14 +603,7 @@ export class OpenAIInstrumentation extends InstrumentationBase<typeof openai> {
|
|
|
616
603
|
},
|
|
617
604
|
});
|
|
618
605
|
const execContext = getExecContext(span);
|
|
619
|
-
const recordError = (error: unknown) =>
|
|
620
|
-
span.recordException(error instanceof Error ? error : String(error));
|
|
621
|
-
span.setStatus({
|
|
622
|
-
code: SpanStatusCode.ERROR,
|
|
623
|
-
message: error instanceof Error ? error.message : String(error),
|
|
624
|
-
});
|
|
625
|
-
span.end();
|
|
626
|
-
};
|
|
606
|
+
const recordError = (error: unknown) => endSpanWithError(span, error);
|
|
627
607
|
const execPromise = safeExecuteInTheMiddle(
|
|
628
608
|
() => {
|
|
629
609
|
return context.with(trace.setSpan(execContext, span), () => {
|
|
@@ -1114,7 +1094,8 @@ function isAPIPromise<T>(promise: unknown): promise is APIPromise<T> {
|
|
|
1114
1094
|
* failed request would leave its span open. For an APIPromise the rejection is
|
|
1115
1095
|
* observed through `asResponse()`, which settles with the underlying HTTP
|
|
1116
1096
|
* promise and never parses the body: parsing it here as well would consume the
|
|
1117
|
-
* body before the caller reads it.
|
|
1097
|
+
* body before the caller reads it. So only a failed request is observed, not a
|
|
1098
|
+
* response body that fails to parse.
|
|
1118
1099
|
*
|
|
1119
1100
|
* @param promise - The value returned by the original SDK method
|
|
1120
1101
|
* @param onRejected - Called with the rejection reason
|
|
@@ -1127,6 +1108,24 @@ function observeRejection(promise: unknown, onRejected: (error: unknown) => void
|
|
|
1127
1108
|
}
|
|
1128
1109
|
}
|
|
1129
1110
|
|
|
1111
|
+
/**
|
|
1112
|
+
* Records the error on the span, sets its status to ERROR, and ends it.
|
|
1113
|
+
*
|
|
1114
|
+
* Used both when the SDK method throws synchronously and, through
|
|
1115
|
+
* {@link observeRejection}, when its promise rejects (#3845).
|
|
1116
|
+
*
|
|
1117
|
+
* @param span - The span to end
|
|
1118
|
+
* @param error - The thrown or rejected value, which need not be an Error
|
|
1119
|
+
*/
|
|
1120
|
+
function endSpanWithError(span: Span, error: unknown): void {
|
|
1121
|
+
span.recordException(error instanceof Error ? error : String(error));
|
|
1122
|
+
span.setStatus({
|
|
1123
|
+
code: SpanStatusCode.ERROR,
|
|
1124
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1125
|
+
});
|
|
1126
|
+
span.end();
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1130
1129
|
/**
|
|
1131
1130
|
* Invokes the thennable of a promise or an APIPromise.
|
|
1132
1131
|
*
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// this is an auto-generated file. see js/scripts/version-update.js
|
|
2
|
-
export const VERSION = "4.4.
|
|
2
|
+
export const VERSION = "4.4.1";
|