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

# Span Filtering

> Filter out noisy or unwanted spans from your traces using prefix-based rules.

## Why Filter Spans

When using third-party frameworks that emit their own OpenTelemetry spans (e.g., Google A2A, PydanticAI internals, LangChain sub-components), those spans can clutter your traces with low-level transport or framework details that aren't useful for debugging your application.

The `span_name_filters` parameter on `HoneyHiveTracer.init()` lets you control which spans are sent to HoneyHive. Filtered spans are dropped before any enrichment or export, so they have zero overhead.

<Note>
  For full parameter details, see the [`span_name_filters` parameter in the SDK reference](https://honeyhiveai.github.io/python-sdk/reference/api/tracer.html).
</Note>

***

## Exclude Filter

Drop spans whose name starts with a given prefix. All other spans are kept.

```python theme={null}
from honeyhive import HoneyHiveTracer
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
    span_name_filters={
        "exclude": [
            {"type": "prefix", "value": "a2a.client.transports"},
        ],
    },
)
```

This drops all spans with names starting with `a2a.client.transports` (e.g., `a2a.client.transports.jsonrpc.JsonRpcTransport.send_message`) while keeping useful spans like `agent run`, `chat gpt-4o-mini`, etc.

***

## Include Filter

Only keep spans whose name starts with one of the given prefixes. All other spans are dropped.

```python theme={null}
from honeyhive import HoneyHiveTracer
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
    span_name_filters={
        "include": [
            {"type": "prefix", "value": "pydantic-ai"},
            {"type": "prefix", "value": "chat"},
        ],
    },
)
```

This keeps only spans whose names start with `pydantic-ai` or `chat`, dropping everything else.

***

## Combining Include and Exclude

When both `include` and `exclude` are specified, a span must match at least one include prefix **and** not match any exclude prefix.

```python theme={null}
from honeyhive import HoneyHiveTracer
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
    span_name_filters={
        "include": [
            {"type": "prefix", "value": "a2a"},
        ],
        "exclude": [
            {"type": "prefix", "value": "a2a.client.transports"},
        ],
    },
)
```

This keeps all `a2a.*` spans except the noisy transport internals.

***

## Filter Entry Format

Each filter entry is a dictionary with two keys:

| Key     | Type                | Description                                                 |
| ------- | ------------------- | ----------------------------------------------------------- |
| `type`  | `Literal["prefix"]` | The matching strategy. Must be `"prefix"`.                  |
| `value` | `str`               | The string to match against the beginning of the span name. |

***

## Common Filters

| Framework  | Noisy span prefix       | Description                  |
| ---------- | ----------------------- | ---------------------------- |
| Google A2A | `a2a.client.transports` | JSON-RPC transport internals |

***

## Debugging

When `verbose=True` is set on `HoneyHiveTracer.init()`, filtered spans are logged at debug level so you can verify your filters are working as expected.

```python theme={null}
from honeyhive import HoneyHiveTracer
import os

tracer = HoneyHiveTracer.init(
    api_key=os.getenv("HH_API_KEY"),
    project=os.getenv("HH_PROJECT"),
    verbose=True,
    span_name_filters={
        "exclude": [
            {"type": "prefix", "value": "a2a.client.transports"},
        ],
    },
)
```

<Tip>
  To disable automatic HTTP request tracing entirely, set `HH_DISABLE_HTTP_TRACING=true` (or pass `disable_http_tracing=True` to `HoneyHiveTracer.init()`). See [Environment Variables](/v2/sdk-reference/environment-variables) for the full list of configuration options.
</Tip>

***

## Related

<CardGroup cols={2}>
  <Card title="Sampling" icon="filter" href="/v2/tracing/sampling">
    Control which requests get traced in high-volume applications
  </Card>

  <Card title="Tracer Initialization" icon="play" href="/v2/tracing/tracer-initialization">
    Where to initialize the tracer for scripts, Lambda, and web servers
  </Card>

  <Card title="Tracing Introduction" icon="book" href="/v2/tracing/introduction">
    Data model and architecture overview
  </Card>
</CardGroup>
