# workflows.WithSpanResult

```go
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](/docs/workflows/run-and-inspect/tracing) using the current 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

**ctx**

`context.Context`

required: true

The task execution context.

**name**

`string`

required: true

The name of the span.

**f**

`func(context.Context) (Result, error)`

required: true

The function to wrap.

## Returns

The result and error returned by `f`.

```go title="Go"
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
}
```
