Skip to main content
workflows.WithTaskSpanResult[Result any](
    ctx context.Context,
    name string,
    f func(ctx context.Context) (Result, error),
) (Result, error)
Wrap a function with a tracing span using the current runner’s tracer and return the function result. WithTaskSpanResult is an alias for WithSpanResult. 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) (Result, error)
required
The function to wrap.

Returns

The result and error returned by f.
type Task struct{}

func (t *Task) Execute(ctx context.Context) error {
  result, err := workflows.WithTaskSpanResult(ctx, "Expensive Compute", func(ctx context.Context) (int, error) {
		return 6 * 7, nil
	})
  if err != nil {
    return fmt.Errorf("failed to compute: %w", err)
  }

	return nil
}