Fügen Sie den externen Service im Aspire hinzu

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Fügen Sie den externen Service im Aspire hinzu

by Anonymous » 23 Aug 2025, 23:08

Ich versuche, einem Aspire-Dashboard eine ASP.NET-Core-App hinzuzufügen.

Code: Select all

builder.AddExternalService("FirstApp", new Uri("http://localhost:5027"))
.WithHttpHealthCheck("/healthz")
.WithExplicitStart();
< /code>
Und es hat funktioniert. Ich kann sehen, dass die App ausgeführt wird, andere Daten, wie Metriken, Spuren und Protokolle, nicht an die Aspire-App gesendet werden.var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();

var oltpEndpoint = new Uri("http://localhost:19131");
var resourceBuilder = ResourceBuilder.CreateDefault()
.AddService("FirstApi", serviceVersion: "1.0.0");

// OpenTelemetry
builder.Logging.AddOpenTelemetry(options =>
{
options
.SetResourceBuilder(resourceBuilder)
.AddConsoleExporter()
.AddOtlpExporter(oltpOptions =>
{
oltpOptions.Endpoint = oltpEndpoint;
oltpOptions.Protocol = OtlpExportProtocol.Grpc;
});
});

builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics
.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation()
.AddConsoleExporter()
.AddOtlpExporter(options =>
{
options.Endpoint = oltpEndpoint;
options.Protocol = OtlpExportProtocol.Grpc;
});
})
.WithTracing(tracing =>
{
tracing
.SetResourceBuilder(resourceBuilder)
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddConsoleExporter()
.AddOtlpExporter(options =>
{
options.Endpoint = oltpEndpoint;
options.Protocol = OtlpExportProtocol.Grpc;
});
});

// Service Discovery
builder.Services.AddServiceDiscovery();

var app = builder.Build();

app.MapScalarApiReference();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
})
.WithName("GetWeatherForecast");

app.MapHealthChecks("/healthz");

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Hier ist mein Aspire LORTSSATTINGS.JSON Datei:

Code: Select all

{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15004",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19131",
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20150"
}
}
}
}
PS: Ich möchte Builder nicht verwenden.>

Top