Skip to content

Commit 2406193

Browse files
authored
big refactoring (#82)
1 parent 50a570c commit 2406193

35 files changed

+715
-602
lines changed

benchmarks/OpenTracing.Contrib.NetCore.Benchmarks/CoreFx/HttpHandlerDiagnosticsBenchmark.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void GlobalSetup()
2828
.AddOpenTracingCoreServices(builder =>
2929
{
3030
builder.AddBenchmarkTracer(Mode);
31-
builder.AddCoreFx();
31+
builder.AddHttpHandler();
3232
})
3333
.BuildServiceProvider();
3434

samples/net5.0/OrdersApi/Controllers/OrdersController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
5-
using Shared;
66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.EntityFrameworkCore;
78
using Newtonsoft.Json;
89
using OpenTracing;
910
using OrdersApi.DataStore;
11+
using Shared;
1012

1113
namespace Samples.OrdersApi.Controllers
1214
{
@@ -24,6 +26,14 @@ public OrdersController(OrdersDbContext dbContext, HttpClient httpClient, ITrace
2426
_tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
2527
}
2628

29+
[HttpGet]
30+
public async Task<IActionResult> Index()
31+
{
32+
var orders = await _dbContext.Orders.ToListAsync();
33+
34+
return Ok(orders.Select(x => new { x.OrderId }).ToList());
35+
}
36+
2737
[HttpPost]
2838
public async Task<IActionResult> Index([FromBody] PlaceOrderCommand cmd)
2939
{

samples/net5.0/OrdersApi/Program.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ public static IHostBuilder CreateHostBuilder(string[] args)
3434
// We don't need any tracing data for our health endpoint.
3535
options.Hosting.IgnorePatterns.Add(ctx => ctx.Request.Path == "/health");
3636
});
37-
38-
builder.ConfigureEntityFrameworkCore(options =>
39-
{
40-
options.IgnorePatterns.Add(cmd => cmd.Command.CommandText == "SELECT 1");
41-
});
42-
43-
builder.ConfigureMicrosoftSqlClient(options =>
44-
{
45-
options.IgnorePatterns.Add(cmd => cmd.CommandText == "SELECT 1");
46-
});
4737
});
4838
});
4939
}

samples/net5.0/Shared/JaegerServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Jaeger.Senders.Thrift;
77
using Microsoft.Extensions.Logging;
88
using OpenTracing;
9-
using OpenTracing.Contrib.NetCore.CoreFx;
9+
using OpenTracing.Contrib.NetCore.Configuration;
1010
using OpenTracing.Util;
1111

1212
namespace Microsoft.Extensions.DependencyInjection

samples/netcoreapp2.1/OrdersApi/Controllers/OrdersController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
5-
using Shared;
66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.EntityFrameworkCore;
78
using Newtonsoft.Json;
89
using OpenTracing;
910
using OrdersApi.DataStore;
11+
using Shared;
1012

1113
namespace Samples.OrdersApi.Controllers
1214
{
@@ -24,6 +26,14 @@ public OrdersController(OrdersDbContext dbContext, HttpClient httpClient, ITrace
2426
_tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
2527
}
2628

29+
[HttpGet]
30+
public async Task<IActionResult> Index()
31+
{
32+
var orders = await _dbContext.Orders.ToListAsync();
33+
34+
return Ok(orders.Select(x => new { x.OrderId }).ToList());
35+
}
36+
2737
[HttpPost]
2838
public async Task<IActionResult> Index([FromBody] PlaceOrderCommand cmd)
2939
{

samples/netcoreapp2.1/Shared/JaegerServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Jaeger.Samplers;
55
using Microsoft.Extensions.Logging;
66
using OpenTracing;
7-
using OpenTracing.Contrib.NetCore.CoreFx;
7+
using OpenTracing.Contrib.NetCore.Configuration;
88
using OpenTracing.Util;
99

1010
namespace Microsoft.Extensions.DependencyInjection

samples/netcoreapp3.1/OrdersApi/Controllers/OrdersController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Net.Http;
45
using System.Threading.Tasks;
5-
using Shared;
66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.EntityFrameworkCore;
78
using Newtonsoft.Json;
89
using OpenTracing;
910
using OrdersApi.DataStore;
11+
using Shared;
1012

1113
namespace Samples.OrdersApi.Controllers
1214
{
@@ -24,6 +26,14 @@ public OrdersController(OrdersDbContext dbContext, HttpClient httpClient, ITrace
2426
_tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
2527
}
2628

29+
[HttpGet]
30+
public async Task<IActionResult> Index()
31+
{
32+
var orders = await _dbContext.Orders.ToListAsync();
33+
34+
return Ok(orders.Select(x => new { x.OrderId }).ToList());
35+
}
36+
2737
[HttpPost]
2838
public async Task<IActionResult> Index([FromBody] PlaceOrderCommand cmd)
2939
{

samples/netcoreapp3.1/OrdersApi/Program.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ public static IHostBuilder CreateHostBuilder(string[] args)
3434
// We don't need any tracing data for our health endpoint.
3535
options.Hosting.IgnorePatterns.Add(ctx => ctx.Request.Path == "/health");
3636
});
37-
38-
builder.ConfigureEntityFrameworkCore(options =>
39-
{
40-
options.IgnorePatterns.Add(cmd => cmd.Command.CommandText == "SELECT 1");
41-
});
42-
43-
builder.ConfigureMicrosoftSqlClient(options =>
44-
{
45-
options.IgnorePatterns.Add(cmd => cmd.CommandText == "SELECT 1");
46-
});
4737
});
4838
});
4939
}

samples/netcoreapp3.1/Shared/JaegerServiceCollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Jaeger.Senders.Thrift;
77
using Microsoft.Extensions.Logging;
88
using OpenTracing;
9-
using OpenTracing.Contrib.NetCore.CoreFx;
9+
using OpenTracing.Contrib.NetCore.Configuration;
1010
using OpenTracing.Util;
1111

1212
namespace Microsoft.Extensions.DependencyInjection

src/OpenTracing.Contrib.NetCore/AspNetCore/AspNetCoreDiagnosticOptions.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,37 @@
22

33
namespace OpenTracing.Contrib.NetCore.Configuration
44
{
5-
public class AspNetCoreDiagnosticOptions
5+
public class AspNetCoreDiagnosticOptions : DiagnosticOptions
66
{
77
public HostingOptions Hosting { get; } = new HostingOptions();
8+
9+
public AspNetCoreDiagnosticOptions()
10+
{
11+
// We create separate spans for MVC actions & results so we don't need these additional events by default.
12+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuting");
13+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnActionExecution");
14+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuting");
15+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnActionExecuting");
16+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeActionMethod");
17+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeControllerActionMethod");
18+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterControllerActionMethod");
19+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterActionMethod");
20+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted");
21+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted");
22+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnActionExecution");
23+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnActionExecuted");
24+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnActionExecuted");
25+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnActionExecution");
26+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuting");
27+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnResultExecuting");
28+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnResultExecuted");
29+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnResultExecuted");
30+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.BeforeOnResourceExecuted");
31+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuted");
32+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.AfterOnResourceExecuting");
33+
34+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.Razor.BeginInstrumentationContext");
35+
IgnoredEvents.Add("Microsoft.AspNetCore.Mvc.Razor.EndInstrumentationContext");
36+
}
837
}
938
}

0 commit comments

Comments
 (0)