> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tilebox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# workflows.WithSpanResult

```go theme={"system"}
func WithSpanResult[Result any](
    ctx context.Context,
    name string,
    f func(ctx context.Context) (Result, error),
) (Result, error)
```

Wrap a function with a [tracing span](/workflows/observability/tracing) using the current task runner's tracer and return the function result.

Use `WithSpanResult` inside a task `Execute` method. If the context is not a task execution context, the function runs without creating a span.

## Parameters

<ParamField path="ctx" type="context.Context" required>
  The task execution context.
</ParamField>

<ParamField path="name" type="string" required>
  The name of the span.
</ParamField>

<ParamField path="f" type="func(context.Context) (Result, error)" required>
  The function to wrap.
</ParamField>

## Returns

The result and error returned by `f`.

<RequestExample>
  ```go Go theme={"system"}
  import (
      "context"
      "fmt"
      "log/slog"

      "github.com/tilebox/tilebox-go/workflows/v1"
  )

  type ProcessScene struct{}

  func (t *ProcessScene) Execute(ctx context.Context) error {
      pixels, err := workflows.WithSpanResult(ctx, "compute-index", func(ctx context.Context) (int, error) {
          // Compute an index here.
          return 42, nil
      })
      if err != nil {
          return fmt.Errorf("failed to compute index: %w", err)
      }

      slog.InfoContext(ctx, "index computed", slog.Int("pixels", pixels))
      return nil
  }
  ```
</RequestExample>
