Whether this request should be traced or not.
May be null, which means that there's not enough information to know
whether this request should be traced or not.
[[["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\u003eTraceHeaderContext\u003c/code\u003e is a class in the \u003ccode\u003eGoogle.Cloud.Diagnostics.Common\u003c/code\u003e namespace, designed to handle context from the Google Cloud Trace Header, and it implements the \u003ccode\u003eITraceContext\u003c/code\u003e interface.\u003c/p\u003e\n"],["\u003cp\u003eThe class can be used to manage trace IDs, span IDs, and whether a request should be traced using properties such as \u003ccode\u003eTraceId\u003c/code\u003e, \u003ccode\u003eSpanId\u003c/code\u003e, and \u003ccode\u003eShouldTrace\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eTraceHeaderContext\u003c/code\u003e class allows creating a trace context from a header string via \u003ccode\u003eFromHeader()\u003c/code\u003e or from individual trace and span IDs with the \u003ccode\u003eCreate()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eIt has a static constant field called \u003ccode\u003eTraceHeader\u003c/code\u003e which is equal to \u003ccode\u003e"X-Cloud-Trace-Context"\u003c/code\u003e that can be used to force a trace by passing information in the request header.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eToString()\u003c/code\u003e method is overridden to provide a formatted string representation of the trace header context, including the trace ID, span ID, and whether tracing is enabled.\u003c/p\u003e\n"]]],[],null,["# Google.Cloud.Diagnostics.Common - Class TraceHeaderContext (5.3.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.3.0 (latest)](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.TraceHeaderContext)\n- [5.2.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.TraceHeaderContext)\n- [5.1.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.TraceHeaderContext)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.TraceHeaderContext)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.TraceHeaderContext)\n- [4.3.1](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.TraceHeaderContext) \n\n public sealed class TraceHeaderContext : ITraceContext\n\nReference documentation and code samples for the Google.Cloud.Diagnostics.Common class TraceHeaderContext.\n\nContext from the Google Cloud Trace Header. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e TraceHeaderContext \n\nImplements\n----------\n\n[ITraceContext](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.ITraceContext) \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype)\n\nNamespace\n---------\n\n[Google.Cloud.Diagnostics.Common](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common)\n\nAssembly\n--------\n\nGoogle.Cloud.Diagnostics.Common.dll\n\nRemarks\n-------\n\nA trace can be forced by passing information along in the trace header (\"X-Cloud-Trace-Context\").\nThe trace id, parent span id and whether or not to trace can be set.\nSee: \u003chttps://cloud.google.com/trace/docs/faq#how_do_i_force_a_request_to_be_traced\u003e\n\nFields\n------\n\n### TraceHeader\n\n public const string TraceHeader = \"X-Cloud-Trace-Context\"\n\nThe trace header.\n\nProperties\n----------\n\n### ShouldTrace\n\n public bool? ShouldTrace { get; }\n\nWhether this request should be traced or not.\nMay be null, which means that there's not enough information to know\nwhether this request should be traced or not.\n\n### SpanId\n\n public ulong? SpanId { get; }\n\nThe span id or null if none is available.\n\n**Remarks** \nThis corresponds to the span_id field of the TraceSpan message in the API.\nSee \u003chttps://cloud.google.com/trace/docs/reference/v2/rpc/google.devtools.cloudtrace.v1#tracespan\u003e\nfor more information.\n\n### TraceId\n\n public string TraceId { get; }\n\nThe trace id or null if none is available.\n\n**Remarks** \nThis corresponds to the trace_id field of the Trace message in the API.\nSee \u003chttps://cloud.google.com/trace/docs/reference/v2/rpc/google.devtools.cloudtrace.v1#trace\u003e\nfor more information.\n\nMethods\n-------\n\n### Create(string, ulong?, bool?)\n\n public static TraceHeaderContext Create(string traceId, ulong? spanId, bool? shouldTrace)\n\nCreates a [TraceHeaderContext](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.TraceHeaderContext) from a trace and span id.\n\n### FromHeader(string)\n\n public static TraceHeaderContext FromHeader(string header)\n\nCreates a [TraceHeaderContext](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.TraceHeaderContext) from a header.\n\n### FromHeader(string, Func\\\u003cbool?\\\u003e)\n\n public static TraceHeaderContext FromHeader(string header, Func\u003cbool?\u003e traceFallbackPredicate)\n\nCreates a [TraceHeaderContext](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.TraceHeaderContext) from a header.\n\n### ToString()\n\n public override string ToString()\n\nGets the [TraceHeaderContext](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.TraceHeaderContext) as a string.\nFormatted as \"\\[trace-id\\]/\\[span-id\\];o=\\[should-trace\\]\"\nwhere \"should-trace\" is 1 to trace and 0 otherwise.\n\n**Overrides** \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)"]]