Skip to content

Commit 758a2f1

Browse files
authored
Merge pull request #454 from nblumhardt/detect-zero-traceids
Detect and drop all-zero trace/span/parent ids
2 parents 98039e9 + 82fd409 commit 758a2f1

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/SeqCli/Apps/Hosting/AppContainer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System;
1616
using System.Globalization;
1717
using System.IO;
18+
using System.Linq;
1819
using System.Text.RegularExpressions;
1920
using System.Threading.Tasks;
2021
using Newtonsoft.Json;
@@ -35,7 +36,7 @@ partial class AppContainer : IAppHost, IDisposable
3536
readonly SeqApp _seqApp;
3637
readonly AppLoader _loader;
3738

38-
static readonly Regex HexDigits = HexDigitsRegex();
39+
static readonly Regex NonZeroHex = NonZeroHexRegex();
3940

4041
readonly JsonSerializer _serializer = JsonSerializer.Create(new JsonSerializerSettings
4142
{
@@ -183,7 +184,7 @@ static bool IsValidHexIdentifier(JToken? value, int requiredChars)
183184
if (value?.Value<string>() is not { } id)
184185
return false;
185186

186-
return id.Length == requiredChars && HexDigits.IsMatch(id);
187+
return id.Length == requiredChars && NonZeroHex.IsMatch(id);
187188
}
188189

189190
public void StartPublishing(TextWriter inputWriter)
@@ -198,7 +199,6 @@ public void StopPublishing()
198199
pjson.Stop();
199200
}
200201

201-
// Technically,
202-
[GeneratedRegex("^[0-9a-f]*$")]
203-
private static partial Regex HexDigitsRegex();
204-
}
202+
[GeneratedRegex("^0*[1-9a-f][0-9a-f]*$")]
203+
private static partial Regex NonZeroHexRegex();
204+
}

test/SeqCli.Tests/Apps/AppContainerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ public void RemovesShortTraceAndSpanIds()
6767
Assert.Empty(jo);
6868
}
6969

70+
[Fact]
71+
public void RemovesZeroTraceAndSpanIds()
72+
{
73+
var jo = new JObject
74+
{
75+
["@tr"] = "00000000000000000000000000000000",
76+
["@sp"] = "0000000000000000",
77+
["@ps"] = "0000000000000000"
78+
};
79+
Assert.NotEmpty(jo);
80+
AppContainer.SanitizeTraceIdentifiers(jo);
81+
Assert.Empty(jo);
82+
}
83+
7084
[Fact]
7185
public void PreservesValidTraceAndSpanIds()
7286
{

0 commit comments

Comments
 (0)