# Class TraceDecisionPredicate (4.4.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [4.4.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/4.3.1/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate)

    public sealed class TraceDecisionPredicate

Used to determine if an [HttpRequest](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest) should be traced. This will not override
a decision by the trace header.

## Inheritance

[Object](https://learn.microsoft.com/dotnet/api/system.object) \> TraceDecisionPredicate

## Inherited Members

[Object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode#system-object-gethashcode) [Object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype#system-object-gettype) [Object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone#system-object-memberwiseclone) [Object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring#system-object-tostring)

## Namespace

[Google.Cloud.Diagnostics.AspNetCore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore)

## Assembly

Google.Cloud.Diagnostics.AspNetCore.dll

## Properties

### Default

    public static TraceDecisionPredicate Default { get; }

A default [TraceDecisionPredicate](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate) that only disables tracing health checks.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate` |   |

### DoNothing

    public static TraceDecisionPredicate DoNothing { get; }

A [TraceDecisionPredicate](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate) that does not have any effect on
trace decisions and does not disable tracing health checks.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate` |   |

## Methods

### Create(Func\<HttpRequest, Nullable\<Boolean\>\>, Boolean)

    public static TraceDecisionPredicate Create(Func<HttpRequest, bool?> traceDecisionPredicate, bool ignoreHealthChecks = true)

Creates a [TraceDecisionPredicate](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `traceDecisionPredicate` | `https://learn.microsoft.com/dotnet/api/system.func-2<https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest, https://learn.microsoft.com/dotnet/api/system.nullable-1<https://learn.microsoft.com/dotnet/api/system.boolean>>` Used to determine if a request should be traced. Takes an [HttpRequest](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest). It should return true if the request should be traced, false if the request should not be traced and null if the decision should be left to other sampling mechanisms. Must not be null. |
| `ignoreHealthChecks` | `https://learn.microsoft.com/dotnet/api/system.boolean` Optional. True if Google App Engine health check requests should not be traced. Defaults to true. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate` |   |

**Remarks** Ignoring of health checks (`ignoreHealthChecks`) takes precedence over the
predicate (`traceDecisionPredicate`). If `ignoreHealthChecks`
is true and the request is a health check `traceDecisionPredicate` will not
be called.

### ShouldTrace(HttpRequest)

    public bool? ShouldTrace(HttpRequest request)

Used to determine if a request should be traced. This will not override a trace header
decision.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest` The HTTP request to check. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.nullable-1<https://learn.microsoft.com/dotnet/api/system.boolean>` | True if the request should be traced, false if the request should not be traced and null if the decision should be left to other sampling mechanisms. |