Used to determine if a request should be traced.
Takes an 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.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003e\u003ccode\u003eTraceDecisionPredicate\u003c/code\u003e is used to determine whether an \u003ccode\u003eHttpRequest\u003c/code\u003e should be traced, without overriding a trace header's decision.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eDefault\u003c/code\u003e property disables tracing for health checks, while the \u003ccode\u003eDoNothing\u003c/code\u003e property has no effect on trace decisions and does not disable tracing for health checks.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eCreate\u003c/code\u003e method allows for the creation of a custom \u003ccode\u003eTraceDecisionPredicate\u003c/code\u003e using a function to determine if a request should be traced, and it can optionally ignore health checks.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eShouldTrace\u003c/code\u003e method is used to determine if a given \u003ccode\u003eHttpRequest\u003c/code\u003e should be traced, returning true, false, or null to defer to other mechanisms.\u003c/p\u003e\n"]]],[],null,["# Class TraceDecisionPredicate (4.4.0)\n\nVersion latestkeyboard_arrow_down\n\n- [4.4.0 (latest)](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate)\n- [4.3.1](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/4.3.1/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate) \n\n public sealed class TraceDecisionPredicate\n\nUsed to determine if an [HttpRequest](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.httprequest) should be traced. This will not override\na decision by the trace header. \n\nInheritance\n-----------\n\n[Object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e TraceDecisionPredicate \n\nInherited Members\n-----------------\n\n[Object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode#system-object-gethashcode) \n[Object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype#system-object-gettype) \n[Object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone#system-object-memberwiseclone) \n[Object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring#system-object-tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Diagnostics.AspNetCore](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore)\n\nAssembly\n--------\n\nGoogle.Cloud.Diagnostics.AspNetCore.dll\n\nProperties\n----------\n\n### Default\n\n public static TraceDecisionPredicate Default { get; }\n\nA default [TraceDecisionPredicate](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate) that only disables tracing health checks.\n\n### DoNothing\n\n public static TraceDecisionPredicate DoNothing { get; }\n\nA [TraceDecisionPredicate](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate) that does not have any effect on\ntrace decisions and does not disable tracing health checks.\n\nMethods\n-------\n\n### Create(Func\\\u003cHttpRequest, Nullable\\\u003cBoolean\\\u003e\\\u003e, Boolean)\n\n public static TraceDecisionPredicate Create(Func\u003cHttpRequest, bool?\u003e traceDecisionPredicate, bool ignoreHealthChecks = true)\n\nCreates a [TraceDecisionPredicate](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceDecisionPredicate).\n\n**Remarks** \nIgnoring of health checks (`ignoreHealthChecks`) takes precedence over the\npredicate (`traceDecisionPredicate`). If `ignoreHealthChecks`\nis true and the request is a health check `traceDecisionPredicate` will not\nbe called.\n\n### ShouldTrace(HttpRequest)\n\n public bool? ShouldTrace(HttpRequest request)\n\nUsed to determine if a request should be traced. This will not override a trace header\ndecision."]]