From 8ef3983fea180da154045a90f0018b6dbf589499 Mon Sep 17 00:00:00 2001 From: Amanda Tarafa Mas Date: Thu, 18 Mar 2021 14:05:59 +0000 Subject: [PATCH] fix: X-Cloud-Trace-Context trace mask values should be 0-1. See https://cloud.google.com/trace/docs/setup#force-trace --- .../Trace/TraceHeaderContext.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/TraceHeaderContext.cs b/apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/TraceHeaderContext.cs index 3e59ebe94d6e..2fe50af7e1c7 100644 --- a/apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/TraceHeaderContext.cs +++ b/apis/Google.Cloud.Diagnostics.Common/Google.Cloud.Diagnostics.Common/Trace/TraceHeaderContext.cs @@ -41,10 +41,11 @@ public sealed class TraceHeaderContext /// A regex to match the trace header. /// - ([A-Fa-f0-9]{32}): The trace id, a 32 character hex value. /// - ([0-9]+): The span id, a 64 bit integer. - /// - (?:;o=([0-3])): The trace mask, 1-3 denote it should be traced. (The ?: makes the outer group non-capturing.) + /// - (?:;o=([0-1])): The trace mask, 1 denotes it should be traced. (The ?: makes the outer group non-capturing.) /// + /// See here for format information: https://cloud.google.com/trace/docs/setup#force-trace. internal static readonly Regex TraceHeaderRegex = - new Regex(@"^([A-Fa-f0-9]{32})/([0-9]+)(?:;o=([0-3]))?$", RegexOptions.Compiled); + new Regex(@"^([A-Fa-f0-9]{32})/([0-9]+)(?:;o=([0-1]))?$", RegexOptions.Compiled); /// Gets the trace id or null if none is available. public string TraceId { get; } @@ -89,7 +90,7 @@ public static TraceHeaderContext FromHeader(string header) return InvalidTraceHeaderContext; } bool hasMask = match.Groups.Count > 3 && match.Groups[3].Success; - bool? shouldTrace = hasMask ? Convert.ToInt32(match.Groups[3].Value) > 0 : (bool?) null; + bool? shouldTrace = hasMask ? match.Groups[3].Value == "1" : (bool?) null; return new TraceHeaderContext(traceId, spanId, shouldTrace); }