@@ -63,7 +63,39 @@ describe('OpenAITracingExporter', () => {
6363 ...HEADERS ,
6464 } ) ,
6565 ) ;
66- expect ( JSON . parse ( opts . body as string ) ) . toEqual ( { data : [ item . toJSON ( ) ] } ) ;
66+ const body = Buffer . isBuffer ( opts . body )
67+ ? opts . body . toString ( )
68+ : ( opts . body as string ) ;
69+ expect ( JSON . parse ( body ) ) . toEqual ( { data : [ item . toJSON ( ) ] } ) ;
70+ } ) ;
71+
72+ it ( 'exports unicode payload via fetch' , async ( ) => {
73+ const unicodeSpan = createCustomSpan ( {
74+ data : {
75+ name : 'unicode' ,
76+ } ,
77+ } ) ;
78+ unicodeSpan . toJSON = ( ) => ( {
79+ object : 'trace.span' ,
80+ id : 'u123' ,
81+ trace_id : 'u123' ,
82+ parent_id : 'u123' ,
83+ started_at : '1' ,
84+ ended_at : '2' ,
85+ span_data : { prompt : 'Hello “world”' } ,
86+ error : null ,
87+ } ) ;
88+
89+ const fetchMock = vi . fn ( ) . mockResolvedValue ( { ok : true } ) ;
90+ vi . stubGlobal ( 'fetch' , fetchMock ) ;
91+
92+ const exporter = new OpenAITracingExporter ( { apiKey : 'key1' } ) ;
93+ await exporter . export ( [ unicodeSpan ] ) ;
94+
95+ const [ , opts ] = fetchMock . mock . calls [ 0 ] ;
96+ expect ( Buffer . isBuffer ( opts . body ) ) . toBe ( true ) ;
97+ const body = ( opts . body as Buffer ) . toString ( ) ;
98+ expect ( JSON . parse ( body ) ) . toEqual ( { data : [ unicodeSpan . toJSON ( ) ] } ) ;
6799 } ) ;
68100
69101 it ( 'retries on server errors' , async ( ) => {
@@ -91,9 +123,15 @@ describe('OpenAITracingExporter', () => {
91123
92124 it ( 'stops on client error' , async ( ) => {
93125 const item = fakeSpan ;
94- const fetchMock = vi . fn ( ) . mockResolvedValue ( { ok : false , status : 400 , text : async ( ) => 'bad' } ) ;
126+ const fetchMock = vi
127+ . fn ( )
128+ . mockResolvedValue ( { ok : false , status : 400 , text : async ( ) => 'bad' } ) ;
95129 vi . stubGlobal ( 'fetch' , fetchMock ) ;
96- const exporter = new OpenAITracingExporter ( { apiKey : 'key3' , endpoint : 'u' , maxRetries : 2 } ) ;
130+ const exporter = new OpenAITracingExporter ( {
131+ apiKey : 'key3' ,
132+ endpoint : 'u' ,
133+ maxRetries : 2 ,
134+ } ) ;
97135 await exporter . export ( [ item ] ) ;
98136 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
99137 } ) ;
0 commit comments