-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathW3CUtilities.cs
49 lines (41 loc) · 1.48 KB
/
W3CUtilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace Microsoft.ApplicationInsights.W3C.Internal
{
using System;
using System.Diagnostics;
#if DEPENDENCY_COLLECTOR
using Microsoft.ApplicationInsights.Common;
#else
using Microsoft.ApplicationInsights.Common.Internal;
#endif
internal static class W3CUtilities
{
internal static string GetRootId(string legacyId)
{
Debug.Assert(!string.IsNullOrEmpty(legacyId), "diagnosticId must not be null or empty");
if (legacyId[0] == '|')
{
var dot = legacyId.IndexOf('.');
return legacyId.Substring(1, dot - 1);
}
return StringUtilities.EnforceMaxLength(legacyId, InjectionGuardConstants.RequestHeaderMaxLength);
}
internal static bool TryGetTraceId(string legacyId, out ReadOnlySpan<char> traceId)
{
Debug.Assert(!string.IsNullOrEmpty(legacyId), "diagnosticId must not be null or empty");
traceId = default;
if (legacyId[0] == '|' && legacyId.Length > 33 && legacyId[33] == '.')
{
for (int i = 1; i < 33; i++)
{
if (!((legacyId[i] >= '0' && legacyId[i] <= '9') || (legacyId[i] >= 'a' && legacyId[i] <= 'f')))
{
return false;
}
}
traceId = legacyId.AsSpan().Slice(1, 32);
return true;
}
return false;
}
}
}