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

Move aspnetcore samples to modern .NET 6-style apps #271

Merged
merged 1 commit into from
Sep 23, 2022
Merged
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
52 changes: 29 additions & 23 deletions examples/aspnetcore-redis/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Honeycomb.OpenTelemetry;
using OpenTelemetry.Trace;
using StackExchange.Redis;

namespace aspnetcoreredis
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
var redis = ConnectionMultiplexer.Connect(
new ConfigurationOptions
{
EndPoints = { "localhost:6379" },
AbortOnConnectFail = false, // allow for reconnects if redis is not available
}
}
);
builder.Services.AddSingleton<IConnectionMultiplexer>(redis);

var honeycombOptions =
builder.Configuration.GetSection(HoneycombOptions.ConfigSectionName)
.Get<HoneycombOptions>();

builder.Services.AddOpenTelemetryTracing(otelBuilder =>
otelBuilder
.AddHoneycomb(builder.Configuration)
.AddAspNetCoreInstrumentationWithBaggage()
.AddRedisInstrumentation(redis)
);

builder.Services.AddSingleton(TracerProvider.Default.GetTracer(honeycombOptions.ServiceName));

var app = builder.Build();
app.MapControllers();
await app.RunAsync();
73 changes: 0 additions & 73 deletions examples/aspnetcore-redis/Startup.cs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/aspnetcore-redis/aspnetcoreredis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,7 +13,6 @@

<ItemGroup>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.6" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.6" />
<PackageReference Include="OpenTelemetry.Instrumentation.StackExchangeRedis" Version="1.0.0-rc9.7" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Mvc;
using OpenTelemetry.Trace;
using System.Diagnostics.Metrics;

Expand All @@ -22,7 +17,6 @@ public class WeatherForecastController : ControllerBase
private readonly Tracer _tracer;
private readonly Counter<int> _counter;


public WeatherForecastController(ILogger<WeatherForecastController> logger, Tracer tracer, Meter meter)
{
_logger = logger;
Expand Down
52 changes: 28 additions & 24 deletions examples/aspnetcore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Honeycomb.OpenTelemetry;
using OpenTelemetry.Trace;
using System.Diagnostics.Metrics;

namespace aspnetcore
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
var honeycombOptions =
builder.Configuration.GetSection(HoneycombOptions.ConfigSectionName)
.Get<HoneycombOptions>();

builder.Services.AddOpenTelemetryTracing(otelBuilder =>
otelBuilder
.AddHoneycomb(builder.Configuration)
.AddAspNetCoreInstrumentationWithBaggage()
);

builder.Services.AddSingleton(TracerProvider.Default.GetTracer(honeycombOptions.ServiceName));

// (optional metrics setup)
// meter name used here must be configured in the OpenTelemetry SDK
// service name is configured by default
// you may configure additional meter names using the Honeycomb options
var meter = new Meter(honeycombOptions.MetricsDataset);
builder.Services.AddSingleton(meter);

var app = builder.Build();

app.MapControllers();
await app.RunAsync();
70 changes: 0 additions & 70 deletions examples/aspnetcore/Startup.cs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/aspnetcore/aspnetcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
Expand All @@ -12,7 +13,6 @@

<ItemGroup>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9.6" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9.6" />
</ItemGroup>

</Project>