---
title: "workflows.WithSpan"
description: "Wrap a function with a tracing span using the current runner's tracer."
image: "https://tilebox.com/images/tilebox-docs-social-preview.png"
---

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

# workflows.WithSpan

import { Fragment } from "astro/jsx-runtime";

import ApiReference from "@docs/components/ApiReference.astro";

import ParamField from "@docs/components/ParamField.astro";

```go
func WithSpan(
    ctx context.Context,
    name string,
    f func(ctx context.Context) error,
) error
```

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

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

## Parameters

**ctx**

type: context.Context

required: true

The task execution context.
**name**

type: string

required: true

The name of the span.
**f**

type: func(context.Context) error

required: true

The function to wrap.

## Returns

The error returned by `f`, if any.

<h2 id="request-example">Usage example</h2>

```go
import (
    "context"
    "fmt"

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

type ProcessScene struct{}

func (t *ProcessScene) Execute(ctx context.Context) error {
    err := workflows.WithSpan(
        ctx,
        "write-output",
        func(ctx context.Context) error {
            // Write output here.
            return nil
        },
    )
    if err != nil {
        return fmt.Errorf("failed to write output: %w", err)
    }

    return nil
}
```

Source: https://tilebox.com/docs/api-reference/go/workflows/WithSpan/index.mdx
