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

# harnest.tracing

> Public Python signatures, fields, and methods.

[All Python modules](https://usefused.com/docs/harnest/reference/api/overview.md) · [Import and compatibility guidance](https://usefused.com/docs/harnest/build/python-imports.md)

## Exports

| Name | Kind |
| - | - |
| [`Tracer`](#tracer) | Class |
| [`current_trace_ids`](#current_trace_ids) | Function |
| [`get_tracer`](#get_tracer) | Function |
| [`span`](#span) | Function |
| [`traced`](#traced) | Function |

## Tracer

Dynamic tracer that remains valid before runtime configuration.

```python theme={null}
Tracer(name: str, version: str | None = None) -> None
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `version` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.tracing import Tracer
>
> tracer = Tracer(name=...)
> ```

### Tracer.start\_as\_current\_span

```python theme={null}
Tracer.start_as_current_span(name: str, **kwargs: Any) -> Any
```

Start and activate a span using the current telemetry provider.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `**kwargs` | `Any` | Optional |
>
> ```python theme={null}
> from harnest.tracing import Tracer
>
> tracer: Tracer
> result = tracer.start_as_current_span(name=...)
> ```

### Tracer.start\_span

```python theme={null}
Tracer.start_span(name: str, **kwargs: Any) -> Any
```

Start a span without making it current in this execution context.

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `**kwargs` | `Any` | Optional |
>
> ```python theme={null}
> from harnest.tracing import Tracer
>
> tracer: Tracer
> result = tracer.start_span(name=...)
> ```

## current\_trace\_ids

Return zero-padded W3C trace and span identifiers when recording.

```python theme={null}
current_trace_ids() -> tuple[str | None, str | None]
```

> [accordion] Example
>
> ```python theme={null}
> from harnest.tracing import current_trace_ids
>
> result = current_trace_ids()
> ```

## get\_tracer

Return a dynamic tracer safe to create at module import time.

```python theme={null}
get_tracer(name: str = 'agent', version: str | None = None) -> Tracer
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | `'agent'` |
> | `version` | `str \| None` | `None` |
>
> ```python theme={null}
> from harnest.tracing import get_tracer
>
> tracer = get_tracer()
> ```

## span

Start a current agent span carrying structured attributes.

```python theme={null}
span(
    name: str,
    *,
    attributes: Mapping[str, Any] | None = None,
    kind: Any | None = None,
    **attribute_values: Any,
) -> Iterator[Any]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str` | Required |
> | `attributes` | `Mapping[str, Any] \| None` | `None` |
> | `kind` | `Any \| None` | `None` |
> | `**attribute_values` | `Any` | Optional |
>
> ```python theme={null}
> from harnest.tracing import span
>
> with span(name=...):
>     ...
> ```

## traced

Trace a synchronous or asynchronous authored function.

```python theme={null}
traced(
    name: str | None = None,
    *,
    attributes: Mapping[str, Any] | None = None,
    kind: Any | None = None,
    **attribute_values: Any,
) -> Callable[[_T], _T]
```

> [accordion] Parameters and example
>
> | Parameter | Type | Default |
> | - | - | - |
> | `name` | `str \| None` | `None` |
> | `attributes` | `Mapping[str, Any] \| None` | `None` |
> | `kind` | `Any \| None` | `None` |
> | `**attribute_values` | `Any` | Optional |
>
> ```python theme={null}
> from harnest.tracing import traced
>
> @traced()
> def my_function():
>     ...
> ```


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