From de4d91514b0d29e16c504f6b3c93d97d113e7f90 Mon Sep 17 00:00:00 2001 From: Kevin Gosse Date: Fri, 8 Mar 2024 10:08:18 +0100 Subject: [PATCH] Warm up the query string obfuscator regex (#5266) --- .../Http/QueryStringObfuscation/Obfuscator.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tracer/src/Datadog.Trace/Util/Http/QueryStringObfuscation/Obfuscator.cs b/tracer/src/Datadog.Trace/Util/Http/QueryStringObfuscation/Obfuscator.cs index e57a6929ae81..3e3e1b55c1fd 100644 --- a/tracer/src/Datadog.Trace/Util/Http/QueryStringObfuscation/Obfuscator.cs +++ b/tracer/src/Datadog.Trace/Util/Http/QueryStringObfuscation/Obfuscator.cs @@ -1,11 +1,8 @@ -// +// // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // -// turns out strict formatting and optional compilation don't like each other -#pragma warning disable SA1001, SA1116, SA1118 - using System; using System.Text.RegularExpressions; using Datadog.Trace.Logging; @@ -29,6 +26,17 @@ internal Obfuscator(string pattern, TimeSpan timeout, IDatadogLogger logger) RegexOptions.IgnorePatternWhitespace; _regex = new Regex(pattern, options, _timeout); + + try + { + // Warmup the regex + // Can't use empty string, space, or dot, as they are optimized and don't actually trigger the compilation + _ = _regex.Match("o"); + } + catch + { + // Nothing to log here + } } ///