Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.6.5" />
<PackageVersion Include="Aspire.Hosting.MongoDB" Version="13.6.5" />
<PackageVersion Include="Aspire.Hosting.Redis" Version="13.6.5" />
<PackageVersion Include="CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector" Version="13.6.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="10.10.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="10.10.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.19.1" />
Expand Down
22 changes: 22 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,25 @@ writes the connection string to `src/Web/Grand.Web/App_Data/Settings.cfg`, which
is not tracked by git - delete that file to run the installer again against a
fresh database.

## Telemetry in Grafana

`src/Aspire/Aspire.AppHost` sends the traces, metrics and logs of the
applications it starts to the Aspire dashboard. To see them in Grafana as well,
set `Observability:Grafana` to `true` in its `appsettings.json`, or start it with
the environment variable set:

```bash
Observability__Grafana=true dotnet run --project src/Aspire/Aspire.AppHost
```

The AppHost then starts two more containers: an OpenTelemetry Collector, which
receives what the applications export and sends it on to both the dashboard and
Grafana, and `grafana/otel-lgtm` - Grafana with Tempo (traces), Prometheus
(metrics) and Loki (logs). The `grafana` resource in the dashboard links to the
Grafana UI. Its data survives a restart in the `grandnode-grafana` volume.

The collector's pipeline is `src/Aspire/Aspire.AppHost/otel-collector.yaml`.
Outside Aspire, point an installation at your own collector with the `Telemetry`
section of `App_Data/appsettings.json` or the standard `OTEL_EXPORTER_OTLP_*`
environment variables.

1 change: 1 addition & 0 deletions src/Aspire/Aspire.AppHost/Aspire.AppHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageReference Include="Aspire.Hosting.AppHost" />
<PackageReference Include="Aspire.Hosting.MongoDB" />
<PackageReference Include="Aspire.Hosting.Redis" />
<PackageReference Include="CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Aspire.Dashboard.Sdk.$(NETCoreSdkRuntimeIdentifier)" />
Expand Down
28 changes: 28 additions & 0 deletions src/Aspire/Aspire.AppHost/ObservabilityConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.Extensions.Configuration;

namespace Aspire.AppHost;

public static class ObservabilityConfiguration
{
public static void AddGrafanaObservability(this IDistributedApplicationBuilder builder)
{
//opt-in: two more containers to pull and run, which a plain run of the store does not need
if (!builder.Configuration.GetValue<bool>("Observability:Grafana"))
return;

//Tempo, Loki, Prometheus and Grafana in one container, receiving OTLP itself
var grafana = builder.AddContainer("grafana", "grafana/otel-lgtm", "0.40.0")
.WithLifetime(ContainerLifetime.Persistent)
.WithVolume("grandnode-grafana", "/data")
.WithHttpEndpoint(targetPort: 3000)
.WithEndpoint(targetPort: 4317, name: "otlp", scheme: "http");

//an app exports to one OTLP endpoint only, which Aspire points at its dashboard - the collector takes
//that place and sends everything on to both the dashboard and Grafana
builder.AddOpenTelemetryCollector("otel-collector", settings => settings.CollectorTag = "0.165.0")
.WithConfig(Path.Combine(builder.AppHostDirectory, "otel-collector.yaml"))
.WithEnvironment("GRAFANA_OTLP_ENDPOINT", grafana.GetEndpoint("otlp"))
.WaitFor(grafana)
.WithAppForwarding();
}
}
1 change: 1 addition & 0 deletions src/Aspire/Aspire.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var redis = builder.AddRedis("redis").WithLifetime(ContainerLifetime.Persistent);

builder.AddGrafanaObservability();
builder.ConfigureGrandWebProject(mongodb, redis);

await builder.Build().RunAsync();
5 changes: 5 additions & 0 deletions src/Aspire/Aspire.AppHost/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
},
"Observability": {
//true starts an OpenTelemetry Collector and Grafana (grafana/otel-lgtm) next to the apps; their traces,
//metrics and logs then reach Grafana as well as the Aspire dashboard
"Grafana": false
}
}
38 changes: 38 additions & 0 deletions src/Aspire/Aspire.AppHost/otel-collector.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#OpenTelemetry Collector started by the AppHost when Observability:Grafana is true. It sends everything the apps
#export to both the Aspire dashboard and Grafana. ASPIRE_ENDPOINT, ASPIRE_API_KEY and the receivers' TLS come from
#the Aspire integration, GRAFANA_OTLP_ENDPOINT from ObservabilityConfiguration.
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318

processors:
batch:

exporters:
otlp_grpc/aspire:
endpoint: ${env:ASPIRE_ENDPOINT}
headers:
x-otlp-api-key: ${env:ASPIRE_API_KEY}
otlp_grpc/grafana:
endpoint: ${env:GRAFANA_OTLP_ENDPOINT}
tls:
insecure: true

service:
pipelines:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp_grpc/aspire, otlp_grpc/grafana]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [otlp_grpc/aspire, otlp_grpc/grafana]
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp_grpc/aspire, otlp_grpc/grafana]
Loading