@@ -232,25 +232,6 @@ async function parseDocumentWithAI(
232232 `${ logPrefix } AI call start — provider: ${ selectedProvider } , model: ${ selectedModel ?? "default" } , text length: ${ text . length } chars` ,
233233 ) ;
234234
235- if ( DEBUG ) {
236- try {
237- const { updateObservation, updateTrace } = await import (
238- "@/lib/observability/telemetry-helpers"
239- ) ;
240- await updateObservation ( { input : { textLength : text . length } } ) ;
241- await updateTrace ( {
242- name : "superfill:document-parsing" ,
243- input : {
244- provider : selectedProvider ,
245- model : selectedModel ?? "default" ,
246- textLength : text . length ,
247- } ,
248- } ) ;
249- } catch ( telemetryError ) {
250- logger . warn ( "Telemetry error before document AI call:" , telemetryError ) ;
251- }
252- }
253-
254235 const aiStart = performance . now ( ) ;
255236 let object : ( typeof ExtractedInfoSchema ) [ "_output" ] ;
256237
@@ -275,50 +256,11 @@ async function parseDocumentWithAI(
275256 } ) ;
276257 object = result . object ;
277258 } catch ( error ) {
278- if ( DEBUG ) {
279- try {
280- const { updateObservation, updateTrace, endActiveSpan } = await import (
281- "@/lib/observability/telemetry-helpers"
282- ) ;
283- await updateObservation ( { output : error , level : "ERROR" } ) ;
284- await updateTrace ( { output : error } ) ;
285- await endActiveSpan ( ) ;
286- } catch ( telemetryError ) {
287- logger . warn ( "Telemetry error in document AI catch:" , telemetryError ) ;
288- }
289- }
290259 throw error ;
291- } finally {
292- if ( DEBUG ) {
293- try {
294- const { flushSpanProcessor } = await import (
295- "@/lib/observability/telemetry-helpers"
296- ) ;
297- await flushSpanProcessor ( ) ;
298- } catch ( telemetryError ) {
299- logger . warn (
300- "Telemetry flush error in document parsing:" ,
301- telemetryError ,
302- ) ;
303- }
304- }
305260 }
306261
307262 const aiElapsed = Math . round ( performance . now ( ) - aiStart ) ;
308263
309- if ( DEBUG ) {
310- try {
311- const { updateObservation, updateTrace, endActiveSpan } = await import (
312- "@/lib/observability/telemetry-helpers"
313- ) ;
314- await updateObservation ( { output : { itemCount : object . items . length } } ) ;
315- await updateTrace ( { output : { itemCount : object . items . length } } ) ;
316- await endActiveSpan ( ) ;
317- } catch ( telemetryError ) {
318- logger . warn ( "Telemetry error after document AI call:" , telemetryError ) ;
319- }
320- }
321-
322264 logger . debug (
323265 `${ logPrefix } AI call complete — ${ aiElapsed } ms, items extracted: ${ object . items . length } ` ,
324266 ) ;
0 commit comments