Skip to content

Commit

Permalink
Use vendored spans in tags generation (#5298)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingosse authored Mar 13, 2024
1 parent c2d8654 commit 7813100
Show file tree
Hide file tree
Showing 244 changed files with 16 additions and 4,672 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,11 @@ partial class ")

sb.Append(
@"
#if NETCOREAPP
private static ReadOnlySpan<byte> ")
.Append(property.PropertyName)
.Append(@"Bytes => new byte[] { ")
.Append(tagByteArray)
.Append(@" };
#else
private static readonly byte[] ")
.Append(property.PropertyName)
.Append(@"Bytes = new byte[] { ")
.Append(tagByteArray)
.Append(@" };
#endif");
.Append(@" };");
}
}

Expand All @@ -121,19 +113,11 @@ partial class ")

sb.Append(
@"
#if NETCOREAPP
private static ReadOnlySpan<byte> ")
.Append(property.PropertyName)
.Append(@"Bytes => new byte[] { ")
.Append(tagByteArray)
.Append(@" };
#else
private static readonly byte[] ")
.Append(property.PropertyName)
.Append(@"Bytes = new byte[] { ")
.Append(tagByteArray)
.Append(@" };
#endif");
.Append(@" };");
}

sb.Append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,7 @@ private void WriteTag(ref byte[] bytes, ref int offset, string key, string value
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if !NETCOREAPP
private void WriteTag(ref byte[] bytes, ref int offset, byte[] keyBytes, string value, ITagProcessor[] tagProcessors)
#else
private void WriteTag(ref byte[] bytes, ref int offset, ReadOnlySpan<byte> keyBytes, string value, ITagProcessor[] tagProcessors)
#endif
{
if (tagProcessors is not null)
{
Expand Down Expand Up @@ -525,11 +521,7 @@ private void WriteMetric(ref byte[] bytes, ref int offset, string key, double va
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if !NETCOREAPP
private void WriteMetric(ref byte[] bytes, ref int offset, byte[] keyBytes, double value, ITagProcessor[] tagProcessors)
#else
private void WriteMetric(ref byte[] bytes, ref int offset, ReadOnlySpan<byte> keyBytes, double value, ITagProcessor[] tagProcessors)
#endif
{
if (tagProcessors is not null)
{
Expand Down Expand Up @@ -591,11 +583,7 @@ internal TagWriter(SpanMessagePackFormatter formatter, ITagProcessor[] tagProces
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Process(TagItem<string> item)
{
#if NETCOREAPP
if (item.SerializedKey.IsEmpty)
#else
if (item.SerializedKey is null)
#endif
{
_formatter.WriteTag(ref Bytes, ref Offset, item.Key, item.Value, _tagProcessors);
}
Expand All @@ -610,11 +598,7 @@ public void Process(TagItem<string> item)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Process(TagItem<double> item)
{
#if NETCOREAPP
if (item.SerializedKey.IsEmpty)
#else
if (item.SerializedKey is null)
#endif
{
_formatter.WriteMetric(ref Bytes, ref Offset, item.Key, item.Value, _tagProcessors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,7 @@ private void WriteTag(ref byte[] bytes, ref int offset, string key, string value
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if !NETCOREAPP
private void WriteTag(ref byte[] bytes, ref int offset, byte[] keyBytes, string value, ITagProcessor[] tagProcessors)
#else
private void WriteTag(ref byte[] bytes, ref int offset, ReadOnlySpan<byte> keyBytes, string value, ITagProcessor[] tagProcessors)
#endif
{
if (tagProcessors is not null)
{
Expand Down Expand Up @@ -404,11 +400,7 @@ private void WriteMetric(ref byte[] bytes, ref int offset, string key, double va
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
#if !NETCOREAPP
private void WriteMetric(ref byte[] bytes, ref int offset, byte[] keyBytes, double value, ITagProcessor[] tagProcessors)
#else
private void WriteMetric(ref byte[] bytes, ref int offset, ReadOnlySpan<byte> keyBytes, double value, ITagProcessor[] tagProcessors)
#endif
{
if (tagProcessors is not null)
{
Expand Down Expand Up @@ -451,11 +443,7 @@ internal TagWriter(SpanMessagePackFormatter formatter, ITagProcessor[] tagProces
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Process(TagItem<string> item)
{
#if NETCOREAPP
if (item.SerializedKey.IsEmpty)
#else
if (item.SerializedKey is null)
#endif
{
_formatter.WriteTag(ref Bytes, ref Offset, item.Key, item.Value, _tagProcessors);
}
Expand All @@ -470,11 +458,7 @@ public void Process(TagItem<string> item)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Process(TagItem<double> item)
{
#if NETCOREAPP
if (item.SerializedKey.IsEmpty)
#else
if (item.SerializedKey is null)
#endif
{
_formatter.WriteMetric(ref Bytes, ref Offset, item.Key, item.Value, _tagProcessors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

#if NETCOREAPP
using System;

namespace Datadog.Trace.Vendors.MessagePack
Expand Down Expand Up @@ -106,4 +105,3 @@ public static int WriteStringBytes(ref byte[] bytes, int offset, ReadOnlySpan<by
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,17 @@ namespace Datadog.Trace.Tagging
partial class AerospikeTags
{
// SpanKindBytes = MessagePack.Serialize("span.kind");
#if NETCOREAPP
private static ReadOnlySpan<byte> SpanKindBytes => new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#else
private static readonly byte[] SpanKindBytes = new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#endif
// InstrumentationNameBytes = MessagePack.Serialize("component");
#if NETCOREAPP
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
#else
private static readonly byte[] InstrumentationNameBytes = new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
#endif
// KeyBytes = MessagePack.Serialize("aerospike.key");
#if NETCOREAPP
private static ReadOnlySpan<byte> KeyBytes => new byte[] { 173, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 107, 101, 121 };
#else
private static readonly byte[] KeyBytes = new byte[] { 173, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 107, 101, 121 };
#endif
// NamespaceBytes = MessagePack.Serialize("aerospike.namespace");
#if NETCOREAPP
private static ReadOnlySpan<byte> NamespaceBytes => new byte[] { 179, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 110, 97, 109, 101, 115, 112, 97, 99, 101 };
#else
private static readonly byte[] NamespaceBytes = new byte[] { 179, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 110, 97, 109, 101, 115, 112, 97, 99, 101 };
#endif
// SetNameBytes = MessagePack.Serialize("aerospike.setname");
#if NETCOREAPP
private static ReadOnlySpan<byte> SetNameBytes => new byte[] { 177, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 115, 101, 116, 110, 97, 109, 101 };
#else
private static readonly byte[] SetNameBytes = new byte[] { 177, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 115, 101, 116, 110, 97, 109, 101 };
#endif
// UserKeyBytes = MessagePack.Serialize("aerospike.userkey");
#if NETCOREAPP
private static ReadOnlySpan<byte> UserKeyBytes => new byte[] { 177, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 117, 115, 101, 114, 107, 101, 121 };
#else
private static readonly byte[] UserKeyBytes = new byte[] { 177, 97, 101, 114, 111, 115, 112, 105, 107, 101, 46, 117, 115, 101, 114, 107, 101, 121 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ namespace Datadog.Trace.Tagging
partial class AerospikeV1Tags
{
// PeerServiceBytes = MessagePack.Serialize("peer.service");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceBytes => new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#else
private static readonly byte[] PeerServiceBytes = new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#endif
// PeerServiceSourceBytes = MessagePack.Serialize("_dd.peer.service.source");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceSourceBytes => new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#else
private static readonly byte[] PeerServiceSourceBytes = new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ namespace Datadog.Trace.Tagging
partial class AspNetCoreEndpointTags
{
// AspNetCoreEndpointBytes = MessagePack.Serialize("aspnet_core.endpoint");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCoreEndpointBytes => new byte[] { 180, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 101, 110, 100, 112, 111, 105, 110, 116 };
#else
private static readonly byte[] AspNetCoreEndpointBytes = new byte[] { 180, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 101, 110, 100, 112, 111, 105, 110, 116 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,13 @@ namespace Datadog.Trace.Tagging
partial class AspNetCoreMvcTags
{
// AspNetCoreControllerBytes = MessagePack.Serialize("aspnet_core.controller");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCoreControllerBytes => new byte[] { 182, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 99, 111, 110, 116, 114, 111, 108, 108, 101, 114 };
#else
private static readonly byte[] AspNetCoreControllerBytes = new byte[] { 182, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 99, 111, 110, 116, 114, 111, 108, 108, 101, 114 };
#endif
// AspNetCoreActionBytes = MessagePack.Serialize("aspnet_core.action");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCoreActionBytes => new byte[] { 178, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 97, 99, 116, 105, 111, 110 };
#else
private static readonly byte[] AspNetCoreActionBytes = new byte[] { 178, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 97, 99, 116, 105, 111, 110 };
#endif
// AspNetCoreAreaBytes = MessagePack.Serialize("aspnet_core.area");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCoreAreaBytes => new byte[] { 176, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 97, 114, 101, 97 };
#else
private static readonly byte[] AspNetCoreAreaBytes = new byte[] { 176, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 97, 114, 101, 97 };
#endif
// AspNetCorePageBytes = MessagePack.Serialize("aspnet_core.page");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCorePageBytes => new byte[] { 176, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 112, 97, 103, 101 };
#else
private static readonly byte[] AspNetCorePageBytes = new byte[] { 176, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 112, 97, 103, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,11 @@ namespace Datadog.Trace.Tagging
partial class AspNetCoreTags
{
// InstrumentationNameBytes = MessagePack.Serialize("component");
#if NETCOREAPP
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
#else
private static readonly byte[] InstrumentationNameBytes = new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
#endif
// AspNetCoreRouteBytes = MessagePack.Serialize("aspnet_core.route");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetCoreRouteBytes => new byte[] { 177, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 114, 111, 117, 116, 101 };
#else
private static readonly byte[] AspNetCoreRouteBytes = new byte[] { 177, 97, 115, 112, 110, 101, 116, 95, 99, 111, 114, 101, 46, 114, 111, 117, 116, 101 };
#endif
// HttpRouteBytes = MessagePack.Serialize("http.route");
#if NETCOREAPP
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
#else
private static readonly byte[] HttpRouteBytes = new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,15 @@ namespace Datadog.Trace.Tagging
partial class AspNetTags
{
// AspNetRouteBytes = MessagePack.Serialize("aspnet.route");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetRouteBytes => new byte[] { 172, 97, 115, 112, 110, 101, 116, 46, 114, 111, 117, 116, 101 };
#else
private static readonly byte[] AspNetRouteBytes = new byte[] { 172, 97, 115, 112, 110, 101, 116, 46, 114, 111, 117, 116, 101 };
#endif
// AspNetControllerBytes = MessagePack.Serialize("aspnet.controller");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetControllerBytes => new byte[] { 177, 97, 115, 112, 110, 101, 116, 46, 99, 111, 110, 116, 114, 111, 108, 108, 101, 114 };
#else
private static readonly byte[] AspNetControllerBytes = new byte[] { 177, 97, 115, 112, 110, 101, 116, 46, 99, 111, 110, 116, 114, 111, 108, 108, 101, 114 };
#endif
// AspNetActionBytes = MessagePack.Serialize("aspnet.action");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetActionBytes => new byte[] { 173, 97, 115, 112, 110, 101, 116, 46, 97, 99, 116, 105, 111, 110 };
#else
private static readonly byte[] AspNetActionBytes = new byte[] { 173, 97, 115, 112, 110, 101, 116, 46, 97, 99, 116, 105, 111, 110 };
#endif
// AspNetAreaBytes = MessagePack.Serialize("aspnet.area");
#if NETCOREAPP
private static ReadOnlySpan<byte> AspNetAreaBytes => new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
#else
private static readonly byte[] AspNetAreaBytes = new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
#endif
// HttpRouteBytes = MessagePack.Serialize("http.route");
#if NETCOREAPP
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
#else
private static readonly byte[] HttpRouteBytes = new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ namespace Datadog.Trace.Tagging
partial class AwsDynamoDbTags
{
// TableNameBytes = MessagePack.Serialize("tablename");
#if NETCOREAPP
private static ReadOnlySpan<byte> TableNameBytes => new byte[] { 169, 116, 97, 98, 108, 101, 110, 97, 109, 101 };
#else
private static readonly byte[] TableNameBytes = new byte[] { 169, 116, 97, 98, 108, 101, 110, 97, 109, 101 };
#endif
// SpanKindBytes = MessagePack.Serialize("span.kind");
#if NETCOREAPP
private static ReadOnlySpan<byte> SpanKindBytes => new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#else
private static readonly byte[] SpanKindBytes = new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ namespace Datadog.Trace.Tagging
partial class AwsDynamoDbV1Tags
{
// PeerServiceBytes = MessagePack.Serialize("peer.service");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceBytes => new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#else
private static readonly byte[] PeerServiceBytes = new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#endif
// PeerServiceSourceBytes = MessagePack.Serialize("_dd.peer.service.source");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceSourceBytes => new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#else
private static readonly byte[] PeerServiceSourceBytes = new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ namespace Datadog.Trace.Tagging
partial class AwsKinesisTags
{
// StreamNameBytes = MessagePack.Serialize("streamname");
#if NETCOREAPP
private static ReadOnlySpan<byte> StreamNameBytes => new byte[] { 170, 115, 116, 114, 101, 97, 109, 110, 97, 109, 101 };
#else
private static readonly byte[] StreamNameBytes = new byte[] { 170, 115, 116, 114, 101, 97, 109, 110, 97, 109, 101 };
#endif
// SpanKindBytes = MessagePack.Serialize("span.kind");
#if NETCOREAPP
private static ReadOnlySpan<byte> SpanKindBytes => new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#else
private static readonly byte[] SpanKindBytes = new byte[] { 169, 115, 112, 97, 110, 46, 107, 105, 110, 100 };
#endif

public override string? GetTag(string key)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ namespace Datadog.Trace.Tagging
partial class AwsKinesisV1Tags
{
// PeerServiceBytes = MessagePack.Serialize("peer.service");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceBytes => new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#else
private static readonly byte[] PeerServiceBytes = new byte[] { 172, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101 };
#endif
// PeerServiceSourceBytes = MessagePack.Serialize("_dd.peer.service.source");
#if NETCOREAPP
private static ReadOnlySpan<byte> PeerServiceSourceBytes => new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#else
private static readonly byte[] PeerServiceSourceBytes = new byte[] { 183, 95, 100, 100, 46, 112, 101, 101, 114, 46, 115, 101, 114, 118, 105, 99, 101, 46, 115, 111, 117, 114, 99, 101 };
#endif

public override string? GetTag(string key)
{
Expand Down
Loading

0 comments on commit 7813100

Please sign in to comment.