Skip to content

Commit edc7ef4

Browse files
committed
Update TagListGenerator
1 parent b1f8279 commit edc7ef4

2 files changed

Lines changed: 24 additions & 94 deletions

File tree

tracer/src/Datadog.Trace.SourceGenerators/TagsListGenerator/Sources.cs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,11 @@ partial class ")
8989

9090
sb.Append(
9191
@"
92-
#if NETCOREAPP
9392
private static ReadOnlySpan<byte> ")
9493
.Append(property.PropertyName)
95-
.Append(@"Bytes => new byte[] { ")
94+
.Append(@"Bytes => [")
9695
.Append(tagByteArray)
97-
.Append(@" };")
98-
.Append(
99-
@"
100-
#else
101-
private static readonly byte[] ")
102-
.Append(property.PropertyName)
103-
.Append(@"Bytes = new byte[] { ")
104-
.Append(tagByteArray)
105-
.Append(@" };")
106-
.Append(
107-
@"
108-
#endif");
96+
.AppendLine(@"];");
10997
}
11098
}
11199

@@ -125,28 +113,15 @@ partial class ")
125113

126114
sb.Append(
127115
@"
128-
#if NETCOREAPP
129116
private static ReadOnlySpan<byte> ")
130117
.Append(property.PropertyName)
131-
.Append(@"Bytes => new byte[] { ")
132-
.Append(tagByteArray)
133-
.Append(@" };")
134-
.Append(
135-
@"
136-
#else
137-
private static readonly byte[] ")
138-
.Append(property.PropertyName)
139-
.Append(@"Bytes = new byte[] { ")
118+
.Append(@"Bytes => [")
140119
.Append(tagByteArray)
141-
.Append(@" };")
142-
.Append(
143-
@"
144-
#endif");
120+
.AppendLine(@"];");
145121
}
146122

147123
sb.Append(
148124
@"
149-
150125
public override string? GetTag(string key)
151126
{
152127
return key switch
@@ -283,11 +258,6 @@ protected override void WriteAdditionalTags(System.Text.StringBuilder sb)
283258

284259
if (tagList.MetricProperties.HasValues())
285260
{
286-
if (tagList.TagProperties.IsDefaultOrEmpty)
287-
{
288-
sb.AppendLine();
289-
}
290-
291261
sb.Append(
292262
@"
293263
public override double? GetMetric(string key)

tracer/test/Datadog.Trace.SourceGenerators.Tests/TagsListGeneratorTests.cs

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
44
// </copyright>
55

6+
using System.Collections.Immutable;
7+
using System.Text;
68
using Datadog.Trace.SourceGenerators.TagsListGenerator;
79
using Datadog.Trace.SourceGenerators.TagsListGenerator.Diagnostics;
810
using Xunit;
@@ -32,11 +34,7 @@ namespace MyTests.TestListNameSpace
3234
partial class TestList
3335
{
3436
// IdBytes = MessagePack.Serialize(""TestId"");
35-
#if NETCOREAPP
36-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 166, 84, 101, 115, 116, 73, 100 };
37-
#else
38-
private static readonly byte[] IdBytes = new byte[] { 166, 84, 101, 115, 116, 73, 100 };
39-
#endif
37+
private static ReadOnlySpan<byte> IdBytes => [166, 84, 101, 115, 116, 73, 100];
4038
4139
public override string? GetTag(string key)
4240
{
@@ -111,11 +109,7 @@ namespace MyTests.TestListNameSpace
111109
partial class TestList
112110
{
113111
// IdBytes = MessagePack.Serialize(""TestId"");
114-
#if NETCOREAPP
115-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 166, 84, 101, 115, 116, 73, 100 };
116-
#else
117-
private static readonly byte[] IdBytes = new byte[] { 166, 84, 101, 115, 116, 73, 100 };
118-
#endif
112+
private static ReadOnlySpan<byte> IdBytes => [166, 84, 101, 115, 116, 73, 100];
119113
120114
public override double? GetMetric(string key)
121115
{
@@ -193,17 +187,10 @@ namespace MyTests.TestListNameSpace
193187
partial class TestList
194188
{
195189
// IdBytes = MessagePack.Serialize(""IdTag"");
196-
#if NETCOREAPP
197-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 165, 73, 100, 84, 97, 103 };
198-
#else
199-
private static readonly byte[] IdBytes = new byte[] { 165, 73, 100, 84, 97, 103 };
200-
#endif
190+
private static ReadOnlySpan<byte> IdBytes => [165, 73, 100, 84, 97, 103];
191+
201192
// NameBytes = MessagePack.Serialize(""NameTag"");
202-
#if NETCOREAPP
203-
private static ReadOnlySpan<byte> NameBytes => new byte[] { 167, 78, 97, 109, 101, 84, 97, 103 };
204-
#else
205-
private static readonly byte[] NameBytes = new byte[] { 167, 78, 97, 109, 101, 84, 97, 103 };
206-
#endif
193+
private static ReadOnlySpan<byte> NameBytes => [167, 78, 97, 109, 101, 84, 97, 103];
207194
208195
public override string? GetTag(string key)
209196
{
@@ -296,17 +283,10 @@ namespace MyTests.TestListNameSpace
296283
partial class TestList
297284
{
298285
// IdBytes = MessagePack.Serialize(""IdMetric"");
299-
#if NETCOREAPP
300-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 168, 73, 100, 77, 101, 116, 114, 105, 99 };
301-
#else
302-
private static readonly byte[] IdBytes = new byte[] { 168, 73, 100, 77, 101, 116, 114, 105, 99 };
303-
#endif
286+
private static ReadOnlySpan<byte> IdBytes => [168, 73, 100, 77, 101, 116, 114, 105, 99];
287+
304288
// NameBytes = MessagePack.Serialize(""NameMetric"");
305-
#if NETCOREAPP
306-
private static ReadOnlySpan<byte> NameBytes => new byte[] { 170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99 };
307-
#else
308-
private static readonly byte[] NameBytes = new byte[] { 170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99 };
309-
#endif
289+
private static ReadOnlySpan<byte> NameBytes => [170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99];
310290
311291
public override double? GetMetric(string key)
312292
{
@@ -402,23 +382,13 @@ namespace MyTests.TestListNameSpace
402382
partial class TestList
403383
{
404384
// IdBytes = MessagePack.Serialize(""IdTag"");
405-
#if NETCOREAPP
406-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 165, 73, 100, 84, 97, 103 };
407-
#else
408-
private static readonly byte[] IdBytes = new byte[] { 165, 73, 100, 84, 97, 103 };
409-
#endif
385+
private static ReadOnlySpan<byte> IdBytes => [165, 73, 100, 84, 97, 103];
386+
410387
// TestBytes = MessagePack.Serialize(""TestId"");
411-
#if NETCOREAPP
412-
private static ReadOnlySpan<byte> TestBytes => new byte[] { 166, 84, 101, 115, 116, 73, 100 };
413-
#else
414-
private static readonly byte[] TestBytes = new byte[] { 166, 84, 101, 115, 116, 73, 100 };
415-
#endif
388+
private static ReadOnlySpan<byte> TestBytes => [166, 84, 101, 115, 116, 73, 100];
389+
416390
// NameBytes = MessagePack.Serialize(""NameTag"");
417-
#if NETCOREAPP
418-
private static ReadOnlySpan<byte> NameBytes => new byte[] { 167, 78, 97, 109, 101, 84, 97, 103 };
419-
#else
420-
private static readonly byte[] NameBytes = new byte[] { 167, 78, 97, 109, 101, 84, 97, 103 };
421-
#endif
391+
private static ReadOnlySpan<byte> NameBytes => [167, 78, 97, 109, 101, 84, 97, 103];
422392
423393
public override string? GetTag(string key)
424394
{
@@ -528,23 +498,13 @@ namespace MyTests.TestListNameSpace
528498
partial class TestList
529499
{
530500
// IdBytes = MessagePack.Serialize(""IdMetric"");
531-
#if NETCOREAPP
532-
private static ReadOnlySpan<byte> IdBytes => new byte[] { 168, 73, 100, 77, 101, 116, 114, 105, 99 };
533-
#else
534-
private static readonly byte[] IdBytes = new byte[] { 168, 73, 100, 77, 101, 116, 114, 105, 99 };
535-
#endif
501+
private static ReadOnlySpan<byte> IdBytes => [168, 73, 100, 77, 101, 116, 114, 105, 99];
502+
536503
// TestBytes = MessagePack.Serialize(""TestId"");
537-
#if NETCOREAPP
538-
private static ReadOnlySpan<byte> TestBytes => new byte[] { 166, 84, 101, 115, 116, 73, 100 };
539-
#else
540-
private static readonly byte[] TestBytes = new byte[] { 166, 84, 101, 115, 116, 73, 100 };
541-
#endif
504+
private static ReadOnlySpan<byte> TestBytes => [166, 84, 101, 115, 116, 73, 100];
505+
542506
// NameBytes = MessagePack.Serialize(""NameMetric"");
543-
#if NETCOREAPP
544-
private static ReadOnlySpan<byte> NameBytes => new byte[] { 170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99 };
545-
#else
546-
private static readonly byte[] NameBytes = new byte[] { 170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99 };
547-
#endif
507+
private static ReadOnlySpan<byte> NameBytes => [170, 78, 97, 109, 101, 77, 101, 116, 114, 105, 99];
548508
549509
public override double? GetMetric(string key)
550510
{

0 commit comments

Comments
 (0)