Skip to content

Commit 9c0cc8d

Browse files
committed
implement comments
1 parent 6998638 commit 9c0cc8d

25 files changed

Lines changed: 40 additions & 46 deletions

File tree

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77

88
using System.Collections.Generic;
99
using System.Web;
10-
using Datadog.Trace.Logging;
1110

1211
namespace Datadog.Trace.AspNet
1312
{
1413
internal static class SharedItems
1514
{
1615
public const string HttpContextPropagatedResourceNameKey = "__Datadog.Trace.ClrProfiler.Managed.AspNetMvcIntegration-aspnet.resourcename";
17-
private static readonly IDatadogLogger Log = DatadogLogging.GetLoggerFor(typeof(SharedItems));
1816

19-
internal static void PushItem<T>(HttpContext context, string key, T item)
17+
internal static void PushScope(HttpContext context, string key, Scope item)
2018
{
2119
if (context == null)
2220
{
@@ -29,36 +27,32 @@ internal static void PushItem<T>(HttpContext context, string key, T item)
2927
{
3028
context.Items[key] = item;
3129
}
32-
else if (existingItem is Stack<T> stack)
30+
else if (existingItem is Stack<Scope> stack)
3331
{
3432
stack.Push(item);
3533
}
36-
else if (existingItem is T previousScope)
34+
else if (existingItem is Scope previousScope)
3735
{
38-
var newStack = new Stack<T>();
36+
var newStack = new Stack<Scope>();
3937
newStack.Push(previousScope);
4038
newStack.Push(item);
4139
context.Items[key] = newStack;
4240
}
43-
else
44-
{
45-
Log.Warning("Trying to push an item in HttpContext.Items but a previous object of unhandled type is already stored there");
46-
}
4741
}
4842

49-
internal static T TryPopItem<T>(HttpContext context, string key)
43+
internal static Scope TryPopScope(HttpContext context, string key)
5044
{
5145
var item = context?.Items[key];
52-
if (item is T storedScope)
46+
if (item is Scope storedScope)
5347
{
5448
return storedScope;
5549
}
56-
else if (item is Stack<T> stack && stack.Count > 0)
50+
else if (item is Stack<Scope> stack && stack.Count > 0)
5751
{
5852
return stack.Pop();
5953
}
6054

61-
return default(T);
55+
return default(Scope);
6256
}
6357
}
6458
}

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AspNetMvcIntegration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ internal static Scope CreateScope(ControllerContextStruct controllerContext)
166166
}
167167

168168
var tags = new AspNetTags();
169-
scope = Tracer.Instance.StartActiveInternal(OperationName, propagatedContext, tags: tags);
169+
scope = Tracer.Instance.StartActiveInternal(isChildAction ? ChildActionOperationName : OperationName, propagatedContext, tags: tags);
170170
span = scope.Span;
171171

172172
span.DecorateWebServerSpan(

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AsyncControllerActionInvoker_BeginInvokeAction_Integration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static CallTargetState OnMethodBegin<TTarget, TContext>(TTarget instance,
6161
{
6262
var duckedControllerContext = controllerContext.DuckCast<ControllerContextStruct>();
6363
scope = AspNetMvcIntegration.CreateScope(duckedControllerContext);
64-
SharedItems.PushItem(HttpContext.Current, AspNetMvcIntegration.HttpContextKey, scope);
64+
SharedItems.PushScope(HttpContext.Current, AspNetMvcIntegration.HttpContextKey, scope);
6565

6666
var security = Security.Instance;
6767
if (security.Settings.Enabled)

tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AspNet/AsyncControllerActionInvoker_EndInvokeAction_Integration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static CallTargetReturn<TResult> OnMethodEnd<TTarget, TResult>(TTarget in
5555

5656
try
5757
{
58-
scope = SharedItems.TryPopItem<Scope>(httpContext, AspNetMvcIntegration.HttpContextKey);
58+
scope = SharedItems.TryPopScope(httpContext, AspNetMvcIntegration.HttpContextKey);
5959
}
6060
catch (Exception ex)
6161
{

tracer/test/Datadog.Trace.Tests/AspNet/SharedItemsTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void TestEmpty()
2121
var context = CreateContext();
2222

2323
// Assert
24-
Assert.Null(SharedItems.TryPopItem<Scope>(context, key));
24+
Assert.Null(SharedItems.TryPopScope(context, key));
2525
}
2626

2727
[Fact]
@@ -33,10 +33,10 @@ public void TestOneItem()
3333
var context = CreateContext();
3434

3535
// Act
36-
SharedItems.PushItem(context, key, scope);
36+
SharedItems.PushScope(context, key, scope);
3737

3838
// Assert
39-
Assert.Equal(scope, SharedItems.TryPopItem<Scope>(context, key));
39+
Assert.Equal(scope, SharedItems.TryPopScope(context, key));
4040
}
4141

4242
[Fact]
@@ -49,14 +49,14 @@ public void TestStackingItems()
4949
var scope3 = new Scope(scope2, null, null, false);
5050
var context = CreateContext();
5151
// Act
52-
SharedItems.PushItem(context, key, scope1);
53-
SharedItems.PushItem(context, key, scope2);
54-
SharedItems.PushItem(context, key, scope3);
52+
SharedItems.PushScope(context, key, scope1);
53+
SharedItems.PushScope(context, key, scope2);
54+
SharedItems.PushScope(context, key, scope3);
5555

5656
// Assert
57-
Assert.Equal(scope3, SharedItems.TryPopItem<Scope>(context, key));
58-
Assert.Equal(scope2, SharedItems.TryPopItem<Scope>(context, key));
59-
Assert.Equal(scope1, SharedItems.TryPopItem<Scope>(context, key));
57+
Assert.Equal(scope3, SharedItems.TryPopScope(context, key));
58+
Assert.Equal(scope2, SharedItems.TryPopScope(context, key));
59+
Assert.Equal(scope1, SharedItems.TryPopScope(context, key));
6060
}
6161

6262
private HttpContext CreateContext()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
TraceId: Id_1,
44
SpanId: Id_2,
5-
Name: aspnet-mvc.request,
5+
Name: aspnet-mvc.request.child-action,
66
Resource: GET /admin/home/index,
77
Service: sample,
88
Type: web,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
TraceId: Id_1,
44
SpanId: Id_2,
5-
Name: aspnet-mvc.request,
5+
Name: aspnet-mvc.request.child-action,
66
Resource: GET /admin/home,
77
Service: sample,
88
Type: web,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
TraceId: Id_1,
44
SpanId: Id_2,
5-
Name: aspnet-mvc.request,
5+
Name: aspnet-mvc.request.child-action,
66
Resource: GET /admin,
77
Service: sample,
88
Type: web,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
TraceId: Id_1,
44
SpanId: Id_2,
5-
Name: aspnet-mvc.request,
5+
Name: aspnet-mvc.request.child-action,
66
Resource: GET /admin/home/index,
77
Service: sample,
88
Type: web,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
TraceId: Id_1,
44
SpanId: Id_2,
5-
Name: aspnet-mvc.request,
5+
Name: aspnet-mvc.request.child-action,
66
Resource: GET /admin/home/index,
77
Service: sample,
88
Type: web,

0 commit comments

Comments
 (0)