Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 8 Upgrade #104

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ build_script:
- ps: .\dotnet-install.ps1 -Runtime dotnet -Version 3.1.10
- ps: .\dotnet-install.ps1 -Version 6.0.100
- ps: .\dotnet-install.ps1 -Version 7.0.100
- ps: .\dotnet-install.ps1 -Version 8.0.100
- ps: .\build.ps1

test: off
Expand Down
38 changes: 38 additions & 0 deletions OpenTracing.Contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "samples\net7.0\Sh
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrafficGenerator", "samples\net7.0\TrafficGenerator\TrafficGenerator.csproj", "{69E6E77E-646D-475A-9B6B-C5511C21B11C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net8.0", "net8.0", "{71609BAA-55BF-4A0A-AE05-83D87644E44C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CustomersApi", "samples\net8.0\CustomersApi\CustomersApi.csproj", "{0DF66128-3C35-4301-98E2-8822FB56B146}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontendWeb", "samples\net8.0\FrontendWeb\FrontendWeb.csproj", "{744E71C6-79A5-4566-BCBA-221AF084A7EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrdersApi", "samples\net8.0\OrdersApi\OrdersApi.csproj", "{63E80769-4B3E-4897-ABD1-237226ED0629}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "samples\net8.0\Shared\Shared.csproj", "{05A112D5-65C4-4F7C-A974-94E5EFBE32DC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrafficGenerator", "samples\net8.0\TrafficGenerator\TrafficGenerator.csproj", "{67A203A9-9EAC-4375-9A32-E42E91C8AA22}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -145,6 +157,26 @@ Global
{69E6E77E-646D-475A-9B6B-C5511C21B11C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69E6E77E-646D-475A-9B6B-C5511C21B11C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69E6E77E-646D-475A-9B6B-C5511C21B11C}.Release|Any CPU.Build.0 = Release|Any CPU
{0DF66128-3C35-4301-98E2-8822FB56B146}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DF66128-3C35-4301-98E2-8822FB56B146}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DF66128-3C35-4301-98E2-8822FB56B146}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DF66128-3C35-4301-98E2-8822FB56B146}.Release|Any CPU.Build.0 = Release|Any CPU
{744E71C6-79A5-4566-BCBA-221AF084A7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{744E71C6-79A5-4566-BCBA-221AF084A7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{744E71C6-79A5-4566-BCBA-221AF084A7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{744E71C6-79A5-4566-BCBA-221AF084A7EF}.Release|Any CPU.Build.0 = Release|Any CPU
{63E80769-4B3E-4897-ABD1-237226ED0629}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63E80769-4B3E-4897-ABD1-237226ED0629}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63E80769-4B3E-4897-ABD1-237226ED0629}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63E80769-4B3E-4897-ABD1-237226ED0629}.Release|Any CPU.Build.0 = Release|Any CPU
{05A112D5-65C4-4F7C-A974-94E5EFBE32DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{05A112D5-65C4-4F7C-A974-94E5EFBE32DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{05A112D5-65C4-4F7C-A974-94E5EFBE32DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{05A112D5-65C4-4F7C-A974-94E5EFBE32DC}.Release|Any CPU.Build.0 = Release|Any CPU
{67A203A9-9EAC-4375-9A32-E42E91C8AA22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67A203A9-9EAC-4375-9A32-E42E91C8AA22}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67A203A9-9EAC-4375-9A32-E42E91C8AA22}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67A203A9-9EAC-4375-9A32-E42E91C8AA22}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -171,6 +203,12 @@ Global
{48CD3687-6EB7-47CD-A611-8D579FBCBB3B} = {E46F4333-859A-4CC5-BD2A-7FE8892861BE}
{B4A8B209-AA79-4C34-9A12-F03E3423B330} = {E46F4333-859A-4CC5-BD2A-7FE8892861BE}
{69E6E77E-646D-475A-9B6B-C5511C21B11C} = {E46F4333-859A-4CC5-BD2A-7FE8892861BE}
{71609BAA-55BF-4A0A-AE05-83D87644E44C} = {36333C22-54F7-403C-ABC4-BECE4EE3F52D}
{0DF66128-3C35-4301-98E2-8822FB56B146} = {71609BAA-55BF-4A0A-AE05-83D87644E44C}
{744E71C6-79A5-4566-BCBA-221AF084A7EF} = {71609BAA-55BF-4A0A-AE05-83D87644E44C}
{63E80769-4B3E-4897-ABD1-237226ED0629} = {71609BAA-55BF-4A0A-AE05-83D87644E44C}
{05A112D5-65C4-4F7C-A974-94E5EFBE32DC} = {71609BAA-55BF-4A0A-AE05-83D87644E44C}
{67A203A9-9EAC-4375-9A32-E42E91C8AA22} = {71609BAA-55BF-4A0A-AE05-83D87644E44C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {832F86C2-4B74-4259-8073-04EE0C37FBCD}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _**IMPORTANT:** OpenTracing and OpenCensus have merget to form **[OpenTelemetry]

## Supported .NET versions

This project currently only supports apps targeting .NET Core 3.1, .NET 6.0, or .NET 7.0!
This project currently only supports apps targeting .NET Core 3.1, .NET 6.0, .NET 7.0, or .NET 8.0!

This project DOES NOT support the full .NET framework as that uses different instrumentation code.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,6 +22,10 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[7.0.0,8)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework)=='net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="[8.0.0,9)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenTracing.Contrib.NetCore\OpenTracing.Contrib.NetCore.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.100",
"rollForward": "feature"
}
}
2 changes: 1 addition & 1 deletion launch-sample.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[CmdletBinding(PositionalBinding = $false)]
param(
[ValidateSet("net7.0", "net6.0", "netcoreapp3.1")]
[ValidateSet("net8.0", "net7.0", "net6.0", "netcoreapp3.1")]
[string] $Framework = "net6.0"
)

Expand Down
19 changes: 19 additions & 0 deletions samples/net8.0/CustomersApi/CustomersApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\..\..\src\OpenTracing.Contrib.NetCore\OpenTracing.Contrib.NetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="[8.0.0,9)" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="[8.0.0,9)" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions samples/net8.0/CustomersApi/DataStore/CustomerDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.EntityFrameworkCore;
using Shared;

namespace CustomersApi.DataStore;

public class CustomerDbContext : DbContext
{
public CustomerDbContext(DbContextOptions<CustomerDbContext> options)
: base(options)
{
}

public DbSet<Customer> Customers => Set<Customer>();

public void Seed()
{
if (Database.EnsureCreated())
{
Database.Migrate();

Customers.Add(new Customer(1, "Marcel Belding"));
Customers.Add(new Customer(2, "Phyllis Schriver"));
Customers.Add(new Customer(3, "Estefana Balderrama"));
Customers.Add(new Customer(4, "Kenyetta Lone"));
Customers.Add(new Customer(5, "Vernita Fernald"));
Customers.Add(new Customer(6, "Tessie Storrs"));

SaveChanges();
}
}
}
74 changes: 74 additions & 0 deletions samples/net8.0/CustomersApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CustomersApi.DataStore;
using Microsoft.EntityFrameworkCore;
using Shared;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.WebHost.UseUrls(Constants.CustomersUrl);

// Registers and starts Jaeger (see Shared.JaegerServiceCollectionExtensions)
builder.Services.AddJaeger();

// Enables OpenTracing instrumentation for ASP.NET Core, CoreFx, EF Core
builder.Services.AddOpenTracing(ot =>
{
ot.ConfigureAspNetCore(options =>
{
// We don't need any tracing data for our health endpoint.
options.Hosting.IgnorePatterns.Add(ctx => ctx.Request.Path == "/health");
});

ot.ConfigureEntityFrameworkCore(options =>
{
// This is an example for how certain EF Core commands can be ignored.
// As en example, we're ignoring the "PRAGMA foreign_keys=ON;" commands that are executed by Sqlite.
// Remove this code to see those statements.
options.IgnorePatterns.Add(cmd => cmd.Command.CommandText.StartsWith("PRAGMA"));
});
});

// Adds a Sqlite DB to show EFCore traces.
builder.Services.AddDbContext<CustomerDbContext>(options =>
{
options.UseSqlite("Data Source=DataStore/customers.db");
});

builder.Services.AddHealthChecks()
.AddDbContextCheck<CustomerDbContext>();


var app = builder.Build();


// Load some dummy data into the db.
using (var scope = app.Services.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<CustomerDbContext>();
dbContext.Seed();
}


// Configure the HTTP request pipeline.

app.MapGet("/", () => "Customers API");

app.MapHealthChecks("/health");

app.MapGet("/customers", async (CustomerDbContext dbContext) => await dbContext.Customers.ToListAsync());

app.MapGet("/customers/{id}", async (int id, CustomerDbContext dbContext, ILogger<Program> logger) =>
{
var customer = await dbContext.Customers.FirstOrDefaultAsync(x => x.CustomerId == id);

if (customer == null)
return Results.NotFound();

// ILogger events are sent to OpenTracing as well!
logger.LogInformation("Returning data for customer {CustomerId}", id);

return Results.Ok(customer);
});

app.Run();
12 changes: 12 additions & 0 deletions samples/net8.0/CustomersApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"CustomersApi": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
10 changes: 10 additions & 0 deletions samples/net8.0/CustomersApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
71 changes: 71 additions & 0 deletions samples/net8.0/FrontendWeb/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json;
using Shared;

namespace FrontendWeb.Controllers;

public class HomeController : Controller
{
private readonly HttpClient _httpClient;

public HomeController(HttpClient httpClient)
{
_httpClient = httpClient;
}

[HttpGet]
public IActionResult Index()
{
return View();
}

[HttpGet]
public async Task<IActionResult> PlaceOrder()
{
ViewBag.Customers = await GetCustomers();
return View(new PlaceOrderCommand { ItemNumber = "ABC11", Quantity = 1 });
}

[HttpPost, ValidateAntiForgeryToken]
public async Task<IActionResult> PlaceOrder(PlaceOrderCommand cmd)
{
if (!ModelState.IsValid)
{
ViewBag.Customers = await GetCustomers();
return View(cmd);
}

string body = JsonConvert.SerializeObject(cmd);

var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri(Constants.OrdersUrl + "orders"),
Content = new StringContent(body, Encoding.UTF8, "application/json")
};

await _httpClient.SendAsync(request);

return RedirectToAction("Index");
}

private async Task<IEnumerable<SelectListItem>> GetCustomers()
{
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri(Constants.CustomersUrl + "customers")
};

var response = await _httpClient.SendAsync(request);

response.EnsureSuccessStatusCode();

var body = await response.Content.ReadAsStringAsync();

return JsonConvert.DeserializeObject<List<Customer>>(body)
.Select(x => new SelectListItem { Value = x.CustomerId.ToString(), Text = x.Name });
}
}
14 changes: 14 additions & 0 deletions samples/net8.0/FrontendWeb/FrontendWeb.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\..\..\src\OpenTracing.Contrib.NetCore\OpenTracing.Contrib.NetCore.csproj" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions samples/net8.0/FrontendWeb/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Shared;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.WebHost.UseUrls(Constants.FrontendUrl);

// Registers and starts Jaeger (see Shared.JaegerServiceCollectionExtensions)
builder.Services.AddJaeger();

// Enables OpenTracing instrumentation for ASP.NET Core, CoreFx, EF Core
builder.Services.AddOpenTracing();

builder.Services.AddSingleton<HttpClient>();

builder.Services.AddMvc();


var app = builder.Build();


// Configure the HTTP request pipeline.

app.MapDefaultControllerRoute();

app.Run();
12 changes: 12 additions & 0 deletions samples/net8.0/FrontendWeb/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"FrontendWeb": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading