Skip to content

Commit

Permalink
Expose some APIs from the host (#7)
Browse files Browse the repository at this point in the history
- Make ExecutableComponent implement IDistributedApplicationComponentWithEnvironment
- Expose OtlpEndpoint API
  • Loading branch information
davidfowl authored Oct 1, 2023
1 parent 1fecfe7 commit a5eea2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Aspire.Hosting/ApplicationModel/ExecutableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Aspire.Hosting.ApplicationModel;

public class ExecutableComponent(string command, string workingDirectory, string[]? args) : IDistributedApplicationComponent
public class ExecutableComponent(string command, string workingDirectory, string[]? args) : IDistributedApplicationComponentWithEnvironment
{
public string Command { get; } = command;
public string WorkingDirectory { get; } = workingDirectory;
Expand Down
27 changes: 13 additions & 14 deletions src/Aspire.Hosting/Otlp/OtlpConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,27 @@

namespace Aspire.Hosting.Otlp;

internal static class OtlpConfigurationExtensions
public static class OtlpConfigurationExtensions
{
private const string DashboardOtlpUrlVariableName = "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL";
private const string DashboardOtlpUrlDefaultValue = "http://localhost:18889";

public static IDistributedApplicationComponentBuilder<T> ConfigureOtlpEnvironment<T>(this IDistributedApplicationComponentBuilder<T> builder) where T : IDistributedApplicationComponent
public static IDistributedApplicationComponentBuilder<T> ConfigureOtlpEnvironment<T>(this IDistributedApplicationComponentBuilder<T> builder) where T : IDistributedApplicationComponentWithEnvironment
{
// Configure OpenTelemetry in projects using environment variables.
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/configuration/sdk-environment-variables.md

return builder.WithAnnotation(
new EnvironmentCallbackAnnotation((config) =>
{
config["OTEL_EXPORTER_OTLP_ENDPOINT"] = builder.ApplicationBuilder.Configuration[DashboardOtlpUrlVariableName] ?? DashboardOtlpUrlDefaultValue;
return builder.WithEnvironment((config) =>
{
config["OTEL_EXPORTER_OTLP_ENDPOINT"] = builder.ApplicationBuilder.Configuration[DashboardOtlpUrlVariableName] ?? DashboardOtlpUrlDefaultValue;

// Set a small batch schedule delay in development.
// This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive.
if (builder.ApplicationBuilder.Environment.IsDevelopment())
{
config["OTEL_BLRP_SCHEDULE_DELAY"] = "1000"; // milliseconds
config["OTEL_BSP_SCHEDULE_DELAY"] = "1000"; // milliseconds
}
}));
// Set a small batch schedule delay in development.
// This reduces the delay that OTLP exporter waits to sends telemetry and makes the dashboard telemetry pages responsive.
if (builder.ApplicationBuilder.Environment.IsDevelopment())
{
config["OTEL_BLRP_SCHEDULE_DELAY"] = "1000"; // milliseconds
config["OTEL_BSP_SCHEDULE_DELAY"] = "1000"; // milliseconds
}
});
}
}

0 comments on commit a5eea2d

Please sign in to comment.