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

# Attributes

> Span attributes available to callbacks in the Apitally SDK for .NET.

In the Apitally SDK, each API request is represented by a span. Span attributes contain metadata about the request and response, such as the request path, HTTP method, and response status code.

You can use this metadata to make decisions in [sampling](/sdk-reference/dotnet/v1/sampling#custom-sampling) and [masking](/sdk-reference/dotnet/v1/masking#body-masking-callbacks) callbacks, which receive the `span` object as an argument. Access attributes through `span.Attributes`. Individual attributes might be missing, so use `GetValueOrDefault()`:

```csharp {3-4} theme={null}
void Callback(SpanSnapshot span)
{
    var attributes = span.Attributes;
    var path = attributes.GetValueOrDefault("url.path") as string;
    // ...
}
```

## Default attributes

The following attributes are useful for common callback decisions. The list is not exhaustive.

| Attribute | Type | Description |
| :- | :- | :- |
| `http.request.method` | `string` | HTTP method, e.g. `GET` or `POST`. |
| `url.path` | `string` | Request path, e.g. `/users/123`. |
| `url.query` | `string` | Query string without `?`, e.g. `page=2`. |
| `user_agent.original` | `string` | Value of the `User-Agent` header. |
| `http.route` | `string` | Matched endpoint route pattern, e.g. `/users/{id}`. |
| `http.response.status_code` | `long` | HTTP response status code, e.g. `200` or `404`. |
| `apitally.consumer.identifier` | `string` | Consumer identifier supplied via `SetConsumer()`. |

Note that `http.response.status_code` is a `long`, not an `int`. Pattern matching with `is int` doesn't match it.

## Set custom attributes

Use the `SetRequestAttribute()` method of the `IApitally` service in your request handling code to attach custom metadata to the current request span. These attributes are included in the request trace and available to response-stage sampling and masking callbacks.

```csharp theme={null}
apitally.SetRequestAttribute("tenant.id", tenantId);
```


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