@@ -20,7 +20,7 @@ import {
20
20
Span ,
21
21
Attributes ,
22
22
SpanKind ,
23
- SpanStatusCode ,
23
+ // SpanStatusCode,
24
24
} from "@opentelemetry/api" ;
25
25
import {
26
26
InstrumentationBase ,
@@ -535,60 +535,47 @@ export class OpenAIInstrumentation extends InstrumentationBase {
535
535
span : Span ,
536
536
promise : APIPromise < T > ,
537
537
) : APIPromise < T > {
538
- return new APIPromise < T > (
539
- promise
540
- . _thenUnwrap ( ( data , props ) => {
541
- if ( version === "v3" ) {
542
- if ( type === "chat" ) {
543
- this . _addLogProbsEvent (
544
- span ,
545
- ( data as ChatCompletion ) . choices [ 0 ] . logprobs ,
546
- ) ;
547
- this . _endSpan ( {
548
- type,
549
- span,
550
- result : data as ChatCompletion ,
551
- } ) ;
552
- } else {
553
- this . _addLogProbsEvent (
554
- span ,
555
- ( data as Completion ) . choices [ 0 ] . logprobs ,
556
- ) ;
557
- this . _endSpan ( {
558
- type,
559
- span,
560
- result : data as Completion ,
561
- } ) ;
562
- }
563
- } else {
564
- if ( type === "chat" ) {
565
- this . _addLogProbsEvent (
566
- span ,
567
- ( data as ChatCompletion ) . choices [ 0 ] . logprobs ,
568
- ) ;
569
- this . _endSpan ( { type, span, result : data as ChatCompletion } ) ;
570
- } else {
571
- this . _addLogProbsEvent (
572
- span ,
573
- ( data as Completion ) . choices [ 0 ] . logprobs ,
574
- ) ;
575
- this . _endSpan ( { type, span, result : data as Completion } ) ;
576
- }
577
- }
578
-
579
- return props ;
580
- } )
581
- . catch ( ( error : Error ) => {
582
- span . setStatus ( {
583
- code : SpanStatusCode . ERROR ,
584
- message : error . message ,
538
+ return promise . _thenUnwrap ( ( result ) => {
539
+ if ( version === "v3" ) {
540
+ if ( type === "chat" ) {
541
+ this . _addLogProbsEvent (
542
+ span ,
543
+ ( ( result as any ) . data as ChatCompletion ) . choices [ 0 ] . logprobs ,
544
+ ) ;
545
+ this . _endSpan ( {
546
+ type,
547
+ span,
548
+ result : ( result as any ) . data as ChatCompletion ,
549
+ } ) ;
550
+ } else {
551
+ this . _addLogProbsEvent (
552
+ span ,
553
+ ( ( result as any ) . data as Completion ) . choices [ 0 ] . logprobs ,
554
+ ) ;
555
+ this . _endSpan ( {
556
+ type,
557
+ span,
558
+ result : ( result as any ) . data as Completion ,
585
559
} ) ;
586
- span . recordException ( error ) ;
587
- span . end ( ) ;
560
+ }
561
+ } else {
562
+ if ( type === "chat" ) {
563
+ this . _addLogProbsEvent (
564
+ span ,
565
+ ( result as ChatCompletion ) . choices [ 0 ] . logprobs ,
566
+ ) ;
567
+ this . _endSpan ( { type, span, result : result as ChatCompletion } ) ;
568
+ } else {
569
+ this . _addLogProbsEvent (
570
+ span ,
571
+ ( result as Completion ) . choices [ 0 ] . logprobs ,
572
+ ) ;
573
+ this . _endSpan ( { type, span, result : result as Completion } ) ;
574
+ }
575
+ }
588
576
589
- throw error ;
590
- } )
591
- ) ;
577
+ return result ;
578
+ } ) ;
592
579
}
593
580
594
581
private _endSpan ( {
0 commit comments