> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/traceable/agent-docs/common/sampling.md).

# Sampling

The agents support 4 types of rules related to sampling of spans:

* [API Exclusion](https://github.com/harness/harness-developer-hub/tree/main/traceable-dc-agent/agent-docs/common/sampling/api-exclusion.md)
* [Span Protection](https://github.com/harness/harness-developer-hub/tree/main/traceable-dc-agent/agent-docs/common/sampling/span-protection.md)
* [Rate-Limiting](https://github.com/harness/harness-developer-hub/tree/main/traceable-dc-agent/agent-docs/common/sampling/rate-limiting.md)
* [Percent-Limiting](https://github.com/harness/harness-developer-hub/tree/main/traceable-dc-agent/agent-docs/common/sampling/percent-limiting.md)

The rules are configured via graphql and are applied at libtraceable (sits alongside language agents, iis, nginx, ebpf and mirroring agent). Specifically for API Exclusion, it can be applied at TPA as well incase the span wasn't dropped by the agent.

Sampling rules need the `SERVICE_NAME` and `ENVIRONMENT_NAME` filter for these rules to be applied at the agents.

## How to call GraphQL?

Any graphql client like Altair or Postman would suffice. The endpoint should be `https://app.traceable.ai/graphql` or the corresponding one for the cluster. `Authorization` header needs to be populated with value `Bearer <jwt>`

## Where's dropping done?

A span can be designated to be dropped because of 2 reasons:

1. API Exclusion - When an exclude rule matched with the span.
2. Rate Limiting - No protection rules matched for this span, hence we sample using the ratelimiting rules configured and a span got rate limited.

On agent, both the above will result in libtraceable adding a span attribute `traceableai.span_type` with value `nospan`. Later it will be dropped by tracing agents before they are exported to TPA or by TPA incase TA doesnt have that capability.

### Tracing Agents which can drop spans

* eBPF
* Mirroring Agent
* Java
* Python
* Nodejs
* Go
* Dotnet
* IIS
* Nginx
* TME/ExtCap based agents.

### What are spans with attribute traceableai.span\_type = barespan?

These are spans which got rate limited according to the rate limiting rules configured with the rateLimitStrategy set as `BARESPAN`. A barespan is mostly similar to an opentelemetry native span without the additional attributes populated by traceable agents. This means that there wont be any request or response headers or bodies.

#### Who is responsible for stripping a normal span to a barespan?

Some tracing agents can do it while others rely on TPA to do that.

### Tracing Agents which can convert spans to barespans

* eBPF
* Mirroring Agent
* Java
* Go
* IIS
* Nginx
* TME/ExtCap based agents.
