Skip to content

Commit

Permalink
Add configuration of OTLP export endpoint to standalone dashboard sam…
Browse files Browse the repository at this point in the history
…ple and improve readme (dotnet#136)
  • Loading branch information
JamesNK authored Mar 3, 2024
1 parent 23be73a commit ff1ff43
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
11 changes: 8 additions & 3 deletions samples/StandaloneDashboard/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ static IHostApplicationBuilder ConfigureOpenTelemetry(IHostApplicationBuilder bu
tracing.AddSource(PokemonDownloader.ActivitySourceName);
});

builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter());
// Use the OTLP exporter if the endpoint is configured.
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
if (useOtlpExporter)
{
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter());
}

return builder;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"ConsoleApp": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
}
}
8 changes: 8 additions & 0 deletions samples/StandaloneDashboard/ConsoleApp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317"
}
17 changes: 12 additions & 5 deletions samples/StandaloneDashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ description: "A sample of using the Aspire dashboard to view telemetry from non-

# Standalone Aspire dashboard sample app

The Aspire dashboard can be used to view OpenTelemetry data from any app. The dashboard supports running standalone, and any app can send it open telemetry.
View telemetry from any app in the Aspire dashboard. The dashboard supports running standalone, and apps configured with an [OpenTelemetry SDK](https://opentelemetry.io/docs/getting-started/dev/) can send it data.

This is a simple .NET app that downloads data from [PokeAPI](https://pokeapi.co/). The app sends telemetry to the Aspire dashboard which can be viewed in the dashboard telemetry UI.
This sample is a .NET console app that downloads data from [PokeAPI](https://pokeapi.co/). The app sends telemetry to the Aspire dashboard which is viewed in the dashboard telemetry UI.

![Screenshot of the standalone .NET Aspire dashboard](./images/aspire-dashboard-screenshot.png)

> [!NOTE]
> [PokeAPI](https://pokeapi.co/) is a free, open-source RESTful API that is not owned by Microsoft.
## Demonstrates

- How to run the Aspire dashboard from a Docker container
Expand Down Expand Up @@ -66,6 +69,10 @@ dotnet run --project ConsoleApp

1. The console app launches, downloads information about all Pokemon and then exits.
2. View the Aspire dashboard at http://localhost:18888 to see app telemetry.
1. View structured logs to see the list of downloaded Pokemon.
2. View traces to see HTTP requests made.
3. View metrics to see numeric data about the app such as average HTTP request duration.
1. View structured logs to see the list of downloaded Pokemon.
2. View traces to see HTTP requests made.
3. View metrics to see numeric data about the app such as average HTTP request duration.

## Configure OpenTelemetry

The telemetry export endpoint is configured with the `OTEL_EXPORTER_OTLP_ENDPOINT` setting. This value is set to `http://localhost:4317` in the sample's appsettings.json file. Removing the `OTEL_EXPORTER_OTLP_ENDPOINT` value disables exporting telemetry.

0 comments on commit ff1ff43

Please sign in to comment.