Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (50 loc) · 1.77 KB
/
Copy pathProgram.cs
File metadata and controls
59 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Asp.Versioning;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using Scalar.AspNetCore;
using Trellis.ServiceLevelIndicators;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddApiVersioning(options => options.ApiVersionReader = new QueryStringApiVersionReader())
.AddMvc()
.AddApiExplorer(options => options.GroupNameFormat = "'v'VVV")
.AddOpenApi(options => options.Document.AddScalarTransformers());
builder.Services.AddProblemDetails();
builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService("SampleVersionedWebApplicationSLI"))
.WithMetrics(metrics =>
{
metrics.AddServiceLevelIndicatorInstrumentation();
metrics.AddOtlpExporter();
});
builder.Services.AddServiceLevelIndicator(options =>
{
options.LocationId = ServiceLevelIndicator.CreateLocationId("public", "westus3");
options.AutomaticallyEmitted = false;
options.LatencyThresholds.Add(TimeSpan.FromMilliseconds(250));
})
.AddMvc()
.AddApiVersion();
var app = builder.Build();
app.UseServiceLevelIndicator();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi().WithDocumentPerVersion();
app.MapScalarApiReference(options =>
{
var descriptions = app.DescribeApiVersions();
for (var i = 0; i < descriptions.Count; i++)
{
var description = descriptions[i];
var isDefault = i == descriptions.Count - 1;
options.AddDocument(description.GroupName, description.GroupName, isDefault: isDefault);
}
});
}
app.MapControllers();
app.MapGet("/health", () => Results.Ok());
app.Run();
/// <summary>
/// Application entry point for integration tests.
/// </summary>
public partial class Program;