Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use HostUrl to contextually resolve the aspire dashboard url within…
… a container.
  • Loading branch information
afscrome committed Sep 14, 2025
commit 925e24f8980ff9d742e741135d0a6cc0e944cb9f
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> AddOpenTelemetryC

var isHttpsEnabled = !settings.ForceNonSecureReceiver && url.StartsWith("https", StringComparison.OrdinalIgnoreCase);

var dashboardOtlpEndpoint = ReplaceLocalhostWithContainerHost(url, builder.Configuration);

var resource = new OpenTelemetryCollectorResource(name);
var resourceBuilder = builder.AddResource(resource)
.WithImage(settings.CollectorImage, settings.CollectorTag)
.WithEnvironment("ASPIRE_ENDPOINT", dashboardOtlpEndpoint)
.WithEnvironment("ASPIRE_ENDPOINT", new HostUrl(url))
.WithEnvironment("ASPIRE_API_KEY", builder.Configuration[DashboardOtlpApiKeyVariableName]);

if (settings.EnableGrpcEndpoint)
Expand Down Expand Up @@ -87,15 +85,6 @@ public static IResourceBuilder<OpenTelemetryCollectorResource> WithAppForwarding
return builder;
}

private static string ReplaceLocalhostWithContainerHost(string value, IConfiguration configuration)
{
var hostName = configuration["AppHost:ContainerHostname"] ?? "host.docker.internal";

return value.Replace("localhost", hostName, StringComparison.OrdinalIgnoreCase)
.Replace("127.0.0.1", hostName)
.Replace("[::1]", hostName);
}

/// <summary>
/// Adds a config file to the collector
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ public void ContainerHasAspireEnvironmentVariables()

Assert.Contains("ASPIRE_ENDPOINT", context.EnvironmentVariables.Keys);
Assert.Contains("ASPIRE_API_KEY", context.EnvironmentVariables.Keys);
Assert.Equal("http://host.docker.internal:18889", context.EnvironmentVariables["ASPIRE_ENDPOINT"]);

var url = Assert.IsType<HostUrl>(context.EnvironmentVariables["ASPIRE_ENDPOINT"]);
Assert.Equal("http://localhost:18889", url.Url);
Assert.NotNull(context.EnvironmentVariables["ASPIRE_API_KEY"]);
}

Expand Down