Skip to content

Commit

Permalink
Made telemetry optional for local development
Browse files Browse the repository at this point in the history
  • Loading branch information
umerfaruk committed Jul 14, 2024
1 parent 87d0ab9 commit 12f409b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 55 deletions.
25 changes: 0 additions & 25 deletions src/Inshapardaz.Api/Inshapardaz.Api.sln

This file was deleted.

62 changes: 34 additions & 28 deletions src/Inshapardaz.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,37 @@

string tracingOtlpEndpoint = builder.Configuration["OLTP_ENDPOINT_URL"];

builder.Logging.AddOpenTelemetry(options => options
.SetResourceBuilder(ResourceBuilder.CreateDefault()
if (!builder.Environment.IsDevelopment())
{
builder.Logging.AddOpenTelemetry(options => options
.SetResourceBuilder(ResourceBuilder.CreateDefault()
.AddService(serviceName))
.AddConsoleExporter());

builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.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();
}
});

.AddConsoleExporter());

builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName))
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.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 Down Expand Up @@ -183,6 +186,10 @@
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
app.MapPrometheusScrapingEndpoint();
}

app.UseCors(x => x
.SetIsOriginAllowed(origin => true)
Expand All @@ -192,7 +199,6 @@
.WithExposedHeaders(HeaderNames.Location, HeaderNames.ContentDisposition, HeaderNames.ContentType));

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

app.UseAuthorization();
app.UseRequestLogging();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void ShouldHavePreviousLink()
}

[Test]
public void ShouldReturExpectedBookPages()
public void ShouldReturnExpectedBookPages()
{
var expectedItems = BookBuilder.GetPages(_book.Id).OrderBy(p => p.SequenceNumber).Skip(10).Take(10);
foreach (var item in expectedItems)
Expand Down
2 changes: 1 addition & 1 deletion tests/Inshapardaz.Api.Tests/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"Database": {
"DatabaseConnectionType": "MySql",
"ConnectionString": "Server=127.0.0.1;Database=nawishta_test;Uid=root;Pwd=Passw0rd;SslMode=none;"
"ConnectionString": "Server=127.0.0.1;Database=nawishta_test;Uid=root;Pwd=Passw0rd;"
},
"Storage": {
"FileStoreType": "Database"
Expand Down

0 comments on commit 12f409b

Please sign in to comment.