Added initial observability

This commit is contained in:
henrik
2024-11-13 21:26:14 +01:00
parent 9134cf9ec6
commit bea8ed917d
7 changed files with 64 additions and 5 deletions

View File

@@ -1,4 +1,9 @@
<!DOCTYPE html>
@using System.Text.Json
@using Elastic.Apm
@inject IApmAgent Agent
@inject IHostEnvironment Environment
<!DOCTYPE html>
<html lang="en">
<head>
@@ -13,6 +18,21 @@
<body>
<Routes/>
<script src="@Assets["_framework/blazor.web.js"]"></script>
@if (Agent.Configuration.Enabled)
{
<script src="@Assets["elastic-apm-rum.umd.min.js"]"></script>
<script permanent>
elasticApm.init({
serviceName: 'Pushy',
serverUrl: 'https://apm.henrikml.dk',
distributedTracingOrigins: ['https://pushy.henrikml.dk'],
pageLoadTraceId: '@Agent.Tracer.CurrentTransaction?.TraceId',
pageLoadSpanId: '@Agent.Tracer.CurrentTransaction?.EnsureParentId()',
pageLoadSampled: @JsonSerializer.Serialize(Agent.Tracer?.CurrentTransaction?.IsSampled),
environment: '@Environment.EnvironmentName'
})
</script>
}
</body>
</html>

View File

@@ -42,6 +42,7 @@
CreatedItems.Add(item);
Form = new UploadForm();
Logger.LogInformation("A new item was created!");
}
public sealed class UploadForm

View File

@@ -25,6 +25,7 @@ public interface ITextItem : IGrainWithStringKey
public sealed class TextItemGrain : Grain, ITextItem, IRemindable
{
private readonly IPersistentState<TextItem> _state;
private IGrainReminder? _reminder;
public TextItemGrain(

View File

@@ -1,3 +1,6 @@
using Elastic.Extensions.Logging;
using Elastic.Extensions.Logging.Options;
using Elastic.Transport;
using Pushy.Components;
using StackExchange.Redis;
using LinkGenerator = Pushy.LinkGenerator;
@@ -9,21 +12,43 @@ builder.UseOrleans(silo =>
silo.UseLocalhostClustering();
silo.UseRedisReminderService(conf =>
{
conf.ConfigurationOptions = ConfigurationOptions.Parse(builder.Configuration.GetConnectionString("Valkey"));
conf.ConfigurationOptions = ConfigurationOptions.Parse(builder.Configuration.GetConnectionString("Valkey")!);
});
silo.AddRedisGrainStorageAsDefault(options =>
{
options.ConfigurationOptions =
ConfigurationOptions.Parse(builder.Configuration.GetConnectionString("Valkey"));
ConfigurationOptions.Parse(builder.Configuration.GetConnectionString("Valkey")!);
});
silo.AddActivityPropagation();
});
var transport = new TransportConfiguration(new StaticNodePool([new Uri("https://elastic-node-1.home.local:9200")]))
.Authentication(new ApiKey(builder.Configuration["Elasticsearch:ApiKey"]!));
builder.Logging.AddElasticsearch(opt =>
{
opt.IsEnabled = true;
opt.DataStream = new DataStreamNameOptions()
{
Type = "logs", DataSet = "Pushy", Namespace = "pushy"
};
opt.Transport = new DistributedTransport(transport);
});
builder.Services.AddScoped<LinkGenerator>();
builder.Services.AddAllElasticApm();
builder.Services.AddHealthChecks();
builder.Services.AddCors(policy =>
{
policy.AddDefaultPolicy(builder =>
{
builder.WithOrigins("https://henrikml.dk")
.AllowAnyHeader();
});
});
// Add services to the container.
builder.Services.AddRazorComponents()
@@ -35,6 +60,7 @@ builder.Services.AddResponseCompression();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
@@ -51,6 +77,7 @@ else
app.UseHttpsRedirection();
app.UseResponseCompression();
app.UseCors();
app.MapStaticAssets();
app.UseAntiforgery();

View File

@@ -10,6 +10,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.30.0" />
<PackageReference Include="Elastic.Extensions.Logging" Version="8.12.2" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.0" />
<PackageReference Include="Microsoft.Orleans.Persistence.Redis" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Reminders.Redis" Version="8.2.0" />

View File

@@ -2,8 +2,14 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"Elastic.Apm": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ElasticApm":
{
"ServerUrl": "http://apm.home.local:8200",
"TransactionNameGroups": "GET /t/*"
}
}

File diff suppressed because one or more lines are too long