@jenova-marie/wonder-logger - v1.0.12
    Preparing search index...

    Function withSpan

    • Wraps an async function with an OpenTelemetry span

      Creates a new span, executes the provided function within the span context, and automatically handles span lifecycle (status, exceptions, ending).

      Type Parameters

      • T

      Parameters

      • name: string

        Name of the span

      • fn: () => Promise<T>

        Async function to wrap with span

      • tracerName: string = 'default'

        Name of the tracer (default: 'default')

      Returns Promise<T>

      Promise resolving to the function result

      const result = await withSpan('database-query', async () => {
      return await db.query('SELECT * FROM users')
      })

      // With custom tracer name
      const result = await withSpan(
      'api-call',
      async () => fetch('https://api.example.com'),
      'my-service'
      )