Skip to content

Commit

Permalink
Updated the telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk committed Jul 11, 2024
1 parent 5e15400 commit 87d0ab9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/Inshapardaz.Api/Inshapardaz.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageReference Include="Paramore.Brighter.Extensions.DependencyInjection" Version="9.7.8" />
<PackageReference Include="Paramore.Darker.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
Expand Down
44 changes: 28 additions & 16 deletions src/Inshapardaz.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,39 @@
builder.WebHost.UseKestrel(o => o.Limits.MaxRequestBodySize = null);

//=====================================================================
// Configura open telemetry
// Configure open telemetry

const string serviceName = "Inshapardaz";

builder.Logging.AddOpenTelemetry(options =>
{
options
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName))
.AddConsoleExporter();
});
string tracingOtlpEndpoint = builder.Configuration["OLTP_ENDPOINT_URL"];

builder.Logging.AddOpenTelemetry(options => options
.SetResourceBuilder(ResourceBuilder.CreateDefault()
.AddService(serviceName))
.AddConsoleExporter());

builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddConsoleExporter())
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddConsoleExporter());
.AddMeter("Microsoft.AspnetCore.Hosting")
.AddMeter("Microsoft.AspnetCore.Server.Kestrel")
.AddPrometheusExporter()
.AddConsoleExporter())
.WithTracing(tracing =>
{
tracing
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation();
if (tracingOtlpEndpoint != null)
{
tracing.AddOtlpExporter(opt => opt.Endpoint = new Uri(tracingOtlpEndpoint));
}
else
{
tracing.AddConsoleExporter();
}
});

//=====================================================================
// Add services to the container.
Expand All @@ -63,9 +75,9 @@
//--------------------------------------------------------------------
builder.Services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
options.AddDefaultPolicy(policyBuilder =>
{
builder.WithOrigins("*")
policyBuilder.WithOrigins("*")
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders(HeaderNames.Location, HeaderNames.ContentDisposition, HeaderNames.ContentType);
Expand Down Expand Up @@ -180,13 +192,13 @@
.WithExposedHeaders(HeaderNames.Location, HeaderNames.ContentDisposition, HeaderNames.ContentType));

app.UseHttpsRedirection();
app.MapPrometheusScrapingEndpoint();

app.UseAuthorization();
app.UseRequestLogging();
app.UseMiddleware<ErrorHandlerMiddleware>();
app.UseMiddleware<LibraryConfigurationMiddleware>();
app.UseStatusCodeMiddleWare();

app.UseMiddleware<JwtMiddleware>();

app.MapControllers();
Expand Down

0 comments on commit 87d0ab9

Please sign in to comment.