Skip to content

Commit 33fb8a5

Browse files
authored
Set "component" tag for ASP.NET (#6010)
## Summary of changes Sets `component` tag for `ASP.NET` to `aspnet` ## Reason for change `component` tag was missing. ## Implementation details Add missing tag. ## Test coverage Lots of snapshots ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
1 parent 2ab9203 commit 33fb8a5

File tree

830 files changed

+2507
-69
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

830 files changed

+2507
-69
lines changed

tracer/src/Datadog.Trace/AspNet/TracingHttpModule.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ private void OnBeginRequest(object sender, EventArgs eventArgs)
188188
string httpMethod = httpRequest.HttpMethod.ToUpperInvariant();
189189
var url = httpContext.Request.GetUrlForSpan(tracer.TracerManager.QueryStringManager, tracer.Settings.BypassHttpRequestUrlCachingEnabled);
190190
var tags = new WebTags();
191+
// FIXME: InstrumentationName should be added to InstrumentationTags
192+
tags.SetTag("component", "aspnet");
191193
scope = tracer.StartActiveInternal(_requestOperationName, extractedContext.SpanContext, tags: tags);
192194
// Attempt to set Resource Name to something that will be close to what is expected
193195
// Note: we will go and re-do it in OnEndRequest, but doing it here will allow for resource-based sampling

tracer/src/Datadog.Trace/Generated/net461/Datadog.Trace.SourceGenerators/TagListGenerator/AspNetTags.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ partial class AspNetTags
2424
private static ReadOnlySpan<byte> AspNetAreaBytes => new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
2525
// HttpRouteBytes = MessagePack.Serialize("http.route");
2626
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
27+
// InstrumentationNameBytes = MessagePack.Serialize("component");
28+
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
2729

2830
public override string? GetTag(string key)
2931
{
@@ -34,6 +36,7 @@ partial class AspNetTags
3436
"aspnet.action" => AspNetAction,
3537
"aspnet.area" => AspNetArea,
3638
"http.route" => HttpRoute,
39+
"component" => InstrumentationName,
3740
_ => base.GetTag(key),
3841
};
3942
}
@@ -57,6 +60,9 @@ public override void SetTag(string key, string value)
5760
case "http.route":
5861
HttpRoute = value;
5962
break;
63+
case "component":
64+
InstrumentationName = value;
65+
break;
6066
default:
6167
base.SetTag(key, value);
6268
break;
@@ -90,6 +96,11 @@ public override void EnumerateTags<TProcessor>(ref TProcessor processor)
9096
processor.Process(new TagItem<string>("http.route", HttpRoute, HttpRouteBytes));
9197
}
9298

99+
if (InstrumentationName is not null)
100+
{
101+
processor.Process(new TagItem<string>("component", InstrumentationName, InstrumentationNameBytes));
102+
}
103+
93104
base.EnumerateTags(ref processor);
94105
}
95106

@@ -130,6 +141,13 @@ protected override void WriteAdditionalTags(System.Text.StringBuilder sb)
130141
.Append(',');
131142
}
132143

144+
if (InstrumentationName is not null)
145+
{
146+
sb.Append("component (tag):")
147+
.Append(InstrumentationName)
148+
.Append(',');
149+
}
150+
133151
base.WriteAdditionalTags(sb);
134152
}
135153
}

tracer/src/Datadog.Trace/Generated/net6.0/Datadog.Trace.SourceGenerators/TagListGenerator/AspNetTags.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ partial class AspNetTags
2424
private static ReadOnlySpan<byte> AspNetAreaBytes => new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
2525
// HttpRouteBytes = MessagePack.Serialize("http.route");
2626
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
27+
// InstrumentationNameBytes = MessagePack.Serialize("component");
28+
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
2729

2830
public override string? GetTag(string key)
2931
{
@@ -34,6 +36,7 @@ partial class AspNetTags
3436
"aspnet.action" => AspNetAction,
3537
"aspnet.area" => AspNetArea,
3638
"http.route" => HttpRoute,
39+
"component" => InstrumentationName,
3740
_ => base.GetTag(key),
3841
};
3942
}
@@ -57,6 +60,9 @@ public override void SetTag(string key, string value)
5760
case "http.route":
5861
HttpRoute = value;
5962
break;
63+
case "component":
64+
InstrumentationName = value;
65+
break;
6066
default:
6167
base.SetTag(key, value);
6268
break;
@@ -90,6 +96,11 @@ public override void EnumerateTags<TProcessor>(ref TProcessor processor)
9096
processor.Process(new TagItem<string>("http.route", HttpRoute, HttpRouteBytes));
9197
}
9298

99+
if (InstrumentationName is not null)
100+
{
101+
processor.Process(new TagItem<string>("component", InstrumentationName, InstrumentationNameBytes));
102+
}
103+
93104
base.EnumerateTags(ref processor);
94105
}
95106

@@ -130,6 +141,13 @@ protected override void WriteAdditionalTags(System.Text.StringBuilder sb)
130141
.Append(',');
131142
}
132143

144+
if (InstrumentationName is not null)
145+
{
146+
sb.Append("component (tag):")
147+
.Append(InstrumentationName)
148+
.Append(',');
149+
}
150+
133151
base.WriteAdditionalTags(sb);
134152
}
135153
}

tracer/src/Datadog.Trace/Generated/netcoreapp3.1/Datadog.Trace.SourceGenerators/TagListGenerator/AspNetTags.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ partial class AspNetTags
2424
private static ReadOnlySpan<byte> AspNetAreaBytes => new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
2525
// HttpRouteBytes = MessagePack.Serialize("http.route");
2626
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
27+
// InstrumentationNameBytes = MessagePack.Serialize("component");
28+
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
2729

2830
public override string? GetTag(string key)
2931
{
@@ -34,6 +36,7 @@ partial class AspNetTags
3436
"aspnet.action" => AspNetAction,
3537
"aspnet.area" => AspNetArea,
3638
"http.route" => HttpRoute,
39+
"component" => InstrumentationName,
3740
_ => base.GetTag(key),
3841
};
3942
}
@@ -57,6 +60,9 @@ public override void SetTag(string key, string value)
5760
case "http.route":
5861
HttpRoute = value;
5962
break;
63+
case "component":
64+
InstrumentationName = value;
65+
break;
6066
default:
6167
base.SetTag(key, value);
6268
break;
@@ -90,6 +96,11 @@ public override void EnumerateTags<TProcessor>(ref TProcessor processor)
9096
processor.Process(new TagItem<string>("http.route", HttpRoute, HttpRouteBytes));
9197
}
9298

99+
if (InstrumentationName is not null)
100+
{
101+
processor.Process(new TagItem<string>("component", InstrumentationName, InstrumentationNameBytes));
102+
}
103+
93104
base.EnumerateTags(ref processor);
94105
}
95106

@@ -130,6 +141,13 @@ protected override void WriteAdditionalTags(System.Text.StringBuilder sb)
130141
.Append(',');
131142
}
132143

144+
if (InstrumentationName is not null)
145+
{
146+
sb.Append("component (tag):")
147+
.Append(InstrumentationName)
148+
.Append(',');
149+
}
150+
133151
base.WriteAdditionalTags(sb);
134152
}
135153
}

tracer/src/Datadog.Trace/Generated/netstandard2.0/Datadog.Trace.SourceGenerators/TagListGenerator/AspNetTags.g.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ partial class AspNetTags
2424
private static ReadOnlySpan<byte> AspNetAreaBytes => new byte[] { 171, 97, 115, 112, 110, 101, 116, 46, 97, 114, 101, 97 };
2525
// HttpRouteBytes = MessagePack.Serialize("http.route");
2626
private static ReadOnlySpan<byte> HttpRouteBytes => new byte[] { 170, 104, 116, 116, 112, 46, 114, 111, 117, 116, 101 };
27+
// InstrumentationNameBytes = MessagePack.Serialize("component");
28+
private static ReadOnlySpan<byte> InstrumentationNameBytes => new byte[] { 169, 99, 111, 109, 112, 111, 110, 101, 110, 116 };
2729

2830
public override string? GetTag(string key)
2931
{
@@ -34,6 +36,7 @@ partial class AspNetTags
3436
"aspnet.action" => AspNetAction,
3537
"aspnet.area" => AspNetArea,
3638
"http.route" => HttpRoute,
39+
"component" => InstrumentationName,
3740
_ => base.GetTag(key),
3841
};
3942
}
@@ -57,6 +60,9 @@ public override void SetTag(string key, string value)
5760
case "http.route":
5861
HttpRoute = value;
5962
break;
63+
case "component":
64+
InstrumentationName = value;
65+
break;
6066
default:
6167
base.SetTag(key, value);
6268
break;
@@ -90,6 +96,11 @@ public override void EnumerateTags<TProcessor>(ref TProcessor processor)
9096
processor.Process(new TagItem<string>("http.route", HttpRoute, HttpRouteBytes));
9197
}
9298

99+
if (InstrumentationName is not null)
100+
{
101+
processor.Process(new TagItem<string>("component", InstrumentationName, InstrumentationNameBytes));
102+
}
103+
93104
base.EnumerateTags(ref processor);
94105
}
95106

@@ -130,6 +141,13 @@ protected override void WriteAdditionalTags(System.Text.StringBuilder sb)
130141
.Append(',');
131142
}
132143

144+
if (InstrumentationName is not null)
145+
{
146+
sb.Append("component (tag):")
147+
.Append(InstrumentationName)
148+
.Append(',');
149+
}
150+
133151
base.WriteAdditionalTags(sb);
134152
}
135153
}

tracer/src/Datadog.Trace/Tagging/AspNetTags.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Datadog.Trace.Tagging
99
{
1010
internal partial class AspNetTags : WebTags
1111
{
12+
private const string ComponentName = "aspnet";
13+
1214
[Tag(Trace.Tags.AspNetRoute)]
1315
public string AspNetRoute { get; set; }
1416

@@ -23,5 +25,8 @@ internal partial class AspNetTags : WebTags
2325

2426
[Tag(Tags.HttpRoute)]
2527
public string HttpRoute { get; set; }
28+
29+
[Tag(Trace.Tags.InstrumentationName)]
30+
public string InstrumentationName { get; set; } = ComponentName;
2631
}
2732
}

tracer/test/Datadog.Trace.TestHelpers/SpanMetadataV0Rules.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public static Result IsAspNetV0(this MockSpan span, ISet<string> excludeTags = n
4848
.IsPresent("http.useragent")
4949
.IsPresent("http.url")
5050
.IsOptional("_dd.base_service")
51-
// BUG: component tag is not set
52-
// .Matches("component", "aspnet")
51+
.Matches("component", "aspnet")
5352
.Matches("span.kind", "server"));
5453

5554
public static Result IsAspNetMvcV0(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)
@@ -67,8 +66,7 @@ public static Result IsAspNetMvcV0(this MockSpan span, ISet<string> excludeTags
6766
.IsPresent("http.useragent")
6867
.IsPresent("http.url")
6968
.IsOptional("_dd.base_service")
70-
// BUG: component tag is not set
71-
// .Matches("component", "aspnet")
69+
.Matches("component", "aspnet")
7270
.Matches("span.kind", "server"));
7371

7472
public static Result IsAspNetWebApi2V0(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)
@@ -95,8 +93,7 @@ public static Result IsAspNetWebApi2V0(this MockSpan span, ISet<string> excludeT
9593
.IsPresent("http.useragent")
9694
.IsPresent("http.url")
9795
.IsOptional("_dd.base_service")
98-
// BUG: component tag is not set
99-
// .Matches("component", "aspnet")
96+
.Matches("component", "aspnet")
10097
.Matches("span.kind", "server"));
10198

10299
public static Result IsAspNetCoreV0(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)

tracer/test/Datadog.Trace.TestHelpers/SpanMetadataV1Rules.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public static Result IsAspNetV1(this MockSpan span, ISet<string> excludeTags = n
5353
.IsPresent("http.useragent")
5454
.IsPresent("http.url")
5555
.IsOptional("_dd.base_service")
56-
// BUG: component tag is not set
57-
// .Matches("component", "aspnet")
56+
.Matches("component", "aspnet")
5857
.Matches("span.kind", "server"));
5958

6059
public static Result IsAspNetMvcV1(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)
@@ -72,8 +71,7 @@ public static Result IsAspNetMvcV1(this MockSpan span, ISet<string> excludeTags
7271
.IsPresent("http.useragent")
7372
.IsPresent("http.url")
7473
.IsOptional("_dd.base_service")
75-
// BUG: component tag is not set
76-
// .Matches("component", "aspnet")
74+
.Matches("component", "aspnet")
7775
.Matches("span.kind", "server"));
7876

7977
public static Result IsAspNetWebApi2V1(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)
@@ -100,8 +98,7 @@ public static Result IsAspNetWebApi2V1(this MockSpan span, ISet<string> excludeT
10098
.IsPresent("http.useragent")
10199
.IsPresent("http.url")
102100
.IsOptional("_dd.base_service")
103-
// BUG: component tag is not set
104-
// .Matches("component", "aspnet")
101+
.Matches("component", "aspnet")
105102
.Matches("span.kind", "server"));
106103

107104
public static Result IsAspNetCoreV1(this MockSpan span, ISet<string> excludeTags = null) => Result.FromSpan(span, excludeTags)

tracer/test/snapshots/AspNetMvc4Tests.Classic.NoFF.__path=_Admin_Home_Index_statusCode=200.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
aspnet.action: hellofromchild,
1212
aspnet.controller: home,
1313
aspnet.route: Admin/{controller}/{action}/{id},
14+
component: aspnet,
1415
env: integration_tests,
1516
http.method: GET,
1617
http.request.headers.host: localhost:00000,
@@ -35,6 +36,7 @@
3536
aspnet.area: admin,
3637
aspnet.controller: home,
3738
aspnet.route: Admin/{controller}/{action}/{id},
39+
component: aspnet,
3840
env: integration_tests,
3941
http.method: GET,
4042
http.request.headers.host: localhost:00000,
@@ -54,6 +56,7 @@
5456
Service: sample,
5557
Type: web,
5658
Tags: {
59+
component: aspnet,
5760
env: integration_tests,
5861
http.method: GET,
5962
http.request.headers.host: localhost:00000,

tracer/test/snapshots/AspNetMvc4Tests.Classic.NoFF.__path=_Admin_Home_statusCode=200.verified.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
aspnet.action: hellofromchild,
1212
aspnet.controller: home,
1313
aspnet.route: Admin/{controller}/{action}/{id},
14+
component: aspnet,
1415
env: integration_tests,
1516
http.method: GET,
1617
http.request.headers.host: localhost:00000,
@@ -35,6 +36,7 @@
3536
aspnet.area: admin,
3637
aspnet.controller: home,
3738
aspnet.route: Admin/{controller}/{action}/{id},
39+
component: aspnet,
3840
env: integration_tests,
3941
http.method: GET,
4042
http.request.headers.host: localhost:00000,
@@ -54,6 +56,7 @@
5456
Service: sample,
5557
Type: web,
5658
Tags: {
59+
component: aspnet,
5760
env: integration_tests,
5861
http.method: GET,
5962
http.request.headers.host: localhost:00000,

0 commit comments

Comments
 (0)