-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c45cdd
commit d471839
Showing
62 changed files
with
588 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
builder.AddProject<Projects.SampleApp_Host>("sampleapp-host"); | ||
|
||
builder.Build().Run(); |
16 changes: 16 additions & 0 deletions
16
samples/SampleApp/SampleApp.AppHost/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"applicationUrl": "http://localhost:15289", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"DOTNET_ENVIRONMENT": "Development", | ||
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16263" | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
samples/SampleApp/SampleApp.AppHost/SampleApp.AppHost.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsAspireHost>true</IsAspireHost> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting" Version="8.0.0-preview.4.24156.9" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SampleApp.Host\SampleApp.Host.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
samples/SampleApp/SampleApp.AppHost/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning", | ||
"Aspire.Hosting.Dcp": "Warning" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
samples/SampleApp/SampleApp.Host/Controllers/WeatherForecastController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using SampleApp.Host.Interfaces.Services; | ||
|
||
namespace SampleApp.Host.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class WeatherForecastController(IWeatherService service) : ControllerBase | ||
{ | ||
[HttpGet(Name = "GetWeatherForecast")] | ||
public IEnumerable<WeatherForecast> Get() | ||
=> service.GetWeatherForecastsAsync(5); | ||
|
||
[HttpGet("{requestCount}", Name = "GetWeatherForecastWithRequest")] | ||
public IEnumerable<WeatherForecast> Get(int requestCount) | ||
=> service.GetWeatherForecastsAsync(requestCount); | ||
} |
5 changes: 5 additions & 0 deletions
5
samples/SampleApp/SampleApp.Host/Interfaces/Services/IWeatherService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace SampleApp.Host.Interfaces.Services; | ||
|
||
public interface IWeatherService { | ||
IEnumerable<WeatherForecast> GetWeatherForecastsAsync(int requestCount, CancellationToken cancellationToken = default); | ||
} |
30 changes: 30 additions & 0 deletions
30
samples/SampleApp/SampleApp.Host/Interfaces/Services/IWeatherServiceTelemetry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Diagnostics; | ||
using Purview.Telemetry; | ||
using Purview.Telemetry.Activities; | ||
using Purview.Telemetry.Logging; | ||
using Purview.Telemetry.Metrics; | ||
|
||
namespace SampleApp.Host.Interfaces.Services; | ||
|
||
[ActivitySource] | ||
[Logger] | ||
[Meter] | ||
public interface IWeatherServiceTelemetry { | ||
[Activity(ActivityKind.Client)] | ||
Activity? GettingWeatherForecastFromUpstreamService(string someRandomInfo, int requestedCount, [Baggage]int validatedRequestedCount); | ||
|
||
[Event] | ||
void MinAndMaxReceived(Activity? activity, int minTempInC, int maxTempInC); | ||
|
||
[Log(LogLevel.Warning)] | ||
void ThatsTooCold(int minTempInC); | ||
|
||
[Log] | ||
void RequestedCountIsTooSmall(int requestCount, int validatedRequestedCount); | ||
|
||
[Counter(AutoIncrement = true)] | ||
void WeatherForecastRequested(); | ||
|
||
[Counter(AutoIncrement = true)] | ||
void ItsTooCold([Tag]int tooColdCount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using SampleApp.Host.Interfaces.Services; | ||
using SampleApp.Host.Services; | ||
|
||
namespace SampleApp.Host; | ||
|
||
public class Program { | ||
public static void Main(string[] args) { | ||
var builder = WebApplication.CreateBuilder(args); | ||
builder.AddServiceDefaults(); | ||
builder.Services.AddMetrics(); | ||
|
||
// Add services to the container. | ||
builder.Services.AddIWeatherServiceTelemetry(); | ||
builder.Services.AddTransient<IWeatherService, WeatherService>(); | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) { | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using Purview.Telemetry.Activities; | ||
|
||
[assembly: ActivitySourceGeneration("sample-weather-app")] |
41 changes: 41 additions & 0 deletions
41
samples/SampleApp/SampleApp.Host/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:58142", | ||
"sslPort": 44302 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5275", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7015;http://localhost:5275", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Purview.Telemetry.SourceGenerator" Version="0.0.12-prerelease" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\SampleApp.ServiceDefaults\SampleApp.ServiceDefaults.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@SampleApp.Host_HostAddress = http://localhost:5275 | ||
|
||
GET {{SampleApp.Host_HostAddress}}/weatherforecast/ | ||
Accept: application/json | ||
|
||
### |
47 changes: 47 additions & 0 deletions
47
samples/SampleApp/SampleApp.Host/Services/WeatherService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using SampleApp.Host.Interfaces.Services; | ||
|
||
namespace SampleApp.Host.Services; | ||
|
||
sealed class WeatherService(IWeatherServiceTelemetry telemetry) : IWeatherService { | ||
const int _tooColdTempInC = -10; | ||
|
||
static readonly string[] _summaries = | ||
[ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
]; | ||
|
||
public IEnumerable<WeatherForecast> GetWeatherForecastsAsync(int requestCount, CancellationToken cancellationToken = default) { | ||
var validatedRequestedCount = requestCount; | ||
if (validatedRequestedCount < 5) { | ||
validatedRequestedCount = 5; | ||
|
||
telemetry.RequestedCountIsTooSmall(requestCount, validatedRequestedCount); | ||
} | ||
|
||
using var activity = telemetry.GettingWeatherForecastFromUpstreamService($"{Guid.NewGuid()}", requestCount, validatedRequestedCount); | ||
|
||
telemetry.WeatherForecastRequested(); | ||
|
||
// This would usually be async of course... | ||
cancellationToken.ThrowIfCancellationRequested(); | ||
|
||
var results = Enumerable.Range(1, validatedRequestedCount).Select(index => new WeatherForecast { | ||
Date = DateOnly.FromDateTime(DateTime.UtcNow.AddDays(index)), | ||
TemperatureC = Random.Shared.Next(-20, 55), | ||
Summary = _summaries[Random.Shared.Next(_summaries.Length)] | ||
}).ToArray(); | ||
|
||
var minTempInC = results.Min(m => m.TemperatureC); | ||
telemetry.MinAndMaxReceived(activity, | ||
minTempInC, | ||
results.Max(wf => wf.TemperatureC) | ||
); | ||
|
||
if (minTempInC < _tooColdTempInC) { | ||
telemetry.ThatsTooCold(minTempInC); | ||
telemetry.ItsTooCold(results.Count(wf => wf.TemperatureC < _tooColdTempInC)); | ||
} | ||
|
||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SampleApp.Host; | ||
|
||
readonly public record struct WeatherForecast( | ||
DateOnly Date, | ||
int TemperatureC, | ||
string? Summary) { | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} |
8 changes: 8 additions & 0 deletions
8
samples/SampleApp/SampleApp.Host/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
Oops, something went wrong.