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

# workflows.WithTaskSpan

```go theme={"system"}
workflows.WithTaskSpan(
    ctx context.Context,
    name string,
    f func(ctx context.Context) error,
) error
```

Wrap a function with a [tracing span](https://docs-old.tilebox.com/workflows/run-and-inspect/tracing.md) using the current runner's tracer.

`WithTaskSpan` is an alias for [`WithSpan`](https://docs-old.tilebox.com/api-reference/go/workflows/WithSpan). Use it 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*

The task execution context.

**name** `string` *required*

The name of the span.

**f** `func(context.Context) error` *required*

The function to wrap.

## Returns

The error returned by `f`, if any.

```go Go theme={"system"}
type Task struct{}

func (t *Task) Execute(ctx context.Context) error {
	err := workflows.WithTaskSpan(ctx, "Database insert", func(ctx context.Context) error {
		// Do something
		return nil
	})
  if err != nil {
    return fmt.Errorf("failed to insert into database: %w", err)
  }

	return nil
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.