Skip to content

.Net: [.NET] Process Framework with Aspire demo - Update dependencies #11539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
14 changes: 9 additions & 5 deletions dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageVersion Include="AWSSDK.BedrockRuntime" Version="4.0.0-preview.13" />
<PackageVersion Include="AWSSDK.Core" Version="4.0.0-preview.13" />
<PackageVersion Include="Aspire.Azure.AI.OpenAI" Version="9.1.0-preview.1.25121.10" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.1.0" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.2.0" />
<PackageVersion Include="Aspire.Hosting.Azure.CognitiveServices" Version="9.1.0" />
<PackageVersion Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0-preview.10" />
<PackageVersion Include="Azure.AI.ContentSafety" Version="1.0.0" />
Expand Down Expand Up @@ -49,8 +49,10 @@
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.3.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.5.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore"
Version="2.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues"
Version="5.5.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.SDK" Version="2.0.0" />
<PackageVersion Include="Microsoft.Azure.Kusto.Data" Version="12.2.8" />
<PackageVersion Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.1" />
Expand Down Expand Up @@ -94,12 +96,14 @@
<!-- Microsoft.Extensions.* -->
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.4.0-preview.1.25207.5" />
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="9.4.0-preview.1.25207.5" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference" Version="9.4.0-preview.1.25207.5" />
<PackageVersion Include="Microsoft.Extensions.AI.AzureAIInference"
Version="9.4.0-preview.1.25207.5" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.0-preview.1.25207.5" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables"
Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
<Sdk Name="Aspire.AppHost.Sdk" Version="9.2.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
<Sdk Name="Aspire.AppHost.Sdk" Version="9.2.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

var processOrchestrator = builder.AddProject<Projects.ProcessFramework_Aspire_ProcessOrchestrator>("processorchestrator")
.WithReference(translateAgent)
.WithReference(summaryAgent);
.WithReference(summaryAgent)
.WithHttpCommand("/api/processdoc", "Trigger Process",
commandOptions: new()
{
Method = HttpMethod.Get
}
);

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -1,46 +1,14 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using ProcessFramework.Aspire.ProcessOrchestrator;
using ProcessFramework.Aspire.ProcessOrchestrator.Models;
using ProcessFramework.Aspire.ProcessOrchestrator.Steps;

var builder = WebApplication.CreateBuilder(args);

string otelExporterEndpoint = builder.GetConfiguration("OTEL_EXPORTER_OTLP_ENDPOINT");
string otelExporterHeaders = builder.GetConfiguration("OTEL_EXPORTER_OTLP_HEADERS");

AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnosticsSensitive", true);

var loggerFactory = LoggerFactory.Create(builder =>
{
// Add OpenTelemetry as a logging provider
builder.AddOpenTelemetry(options =>
{
options.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; });
// Format log messages. This defaults to false.
options.IncludeFormattedMessage = true;
});

builder.AddTraceSource("Microsoft.SemanticKernel");
builder.SetMinimumLevel(LogLevel.Information);
});

using var traceProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

builder.AddServiceDefaults();
builder.Services.AddHttpClient<TranslatorAgentHttpClient>(client => { client.BaseAddress = new("https+http://translatoragent"); });
builder.Services.AddHttpClient<SummaryAgentHttpClient>(client => { client.BaseAddress = new("https+http://summaryagent"); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,21 @@
namespace Microsoft.Extensions.Hosting;

/// <summary>
/// Adds common .NET Aspire services: service discovery, resilience, health checks, and OpenTelemetry.
/// This project should be referenced by each service project in your solution.
/// To learn more about using this project, see https://aka.ms/dotnet/aspire/service-defaults
/// Provides extension methods for adding common .NET Aspire services, including service discovery,
/// resilience, health checks, and OpenTelemetry.
/// </summary>
public static class ServiceExtensions
public static class CommonExtensions
{
/// <summary>
/// Gets a configuration setting from the WebApplicationBuilder.
/// </summary>
/// <param name="builder">The WebApplicationBuilder instance.</param>
/// <param name="settingName">The name of the configuration setting.</param>
/// <returns>The value of the configuration setting.</returns>
/// <exception cref="InvalidOperationException">Thrown when the configuration setting is missing.</exception>
public static string GetConfiguration(this WebApplicationBuilder builder, string settingName)
{
return builder.Configuration[settingName] ?? throw new InvalidOperationException($"Missing configuration setting: {settingName}");
}
private const string HealthEndpointPath = "/health";
private const string AlivenessEndpointPath = "/alive";

/// <summary>
/// Adds default services to the application builder.
/// Adds default services to the application, including OpenTelemetry, health checks,
/// service discovery, and HTTP client defaults with resilience and service discovery enabled.
/// </summary>
/// <typeparam name="TBuilder">The type of the application builder.</typeparam>
/// <param name="builder">The application builder instance.</param>
/// <returns>The application builder instance with default services added.</returns>
/// <typeparam name="TBuilder">The type of the host application builder.</typeparam>
/// <param name="builder">The host application builder instance.</param>
/// <returns>The updated host application builder.</returns>
public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.ConfigureOpenTelemetry();
Expand Down Expand Up @@ -63,13 +54,14 @@ public static TBuilder AddServiceDefaults<TBuilder>(this TBuilder builder) where
}

/// <summary>
/// Configures OpenTelemetry for the application builder.
/// Configures OpenTelemetry for the application, including logging, metrics, and tracing.
/// </summary>
/// <typeparam name="TBuilder">The type of the application builder.</typeparam>
/// <param name="builder">The application builder instance.</param>
/// <returns>The application builder instance with OpenTelemetry configured.</returns>
/// <typeparam name="TBuilder">The type of the host application builder.</typeparam>
/// <param name="builder">The host application builder instance.</param>
/// <returns>The updated host application builder.</returns>
public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Logging.AddTraceSource("Microsoft.SemanticKernel");
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
Expand All @@ -81,28 +73,29 @@ public static TBuilder ConfigureOpenTelemetry<TBuilder>(this TBuilder builder) w
{
metrics.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddRuntimeInstrumentation();
.AddRuntimeInstrumentation()
.AddMeter("Microsoft.SemanticKernel*");
})
.WithTracing(tracing =>
{
tracing.AddSource(builder.Environment.ApplicationName)
.AddAspNetCoreInstrumentation()
.AddAspNetCoreInstrumentation(tracing =>
// Exclude health check requests from tracing
tracing.Filter = context =>
!context.Request.Path.StartsWithSegments(HealthEndpointPath)
&& !context.Request.Path.StartsWithSegments(AlivenessEndpointPath)
)
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
.AddHttpClientInstrumentation()
.AddSource("Microsoft.SemanticKernel*");
});

builder.AddOpenTelemetryExporters();

return builder;
}

/// <summary>
/// Adds OpenTelemetry exporters to the application builder.
/// </summary>
/// <typeparam name="TBuilder">The type of the application builder.</typeparam>
/// <param name="builder">The application builder instance.</param>
/// <returns>The application builder instance with OpenTelemetry exporters added.</returns>
private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
Expand All @@ -123,11 +116,11 @@ private static TBuilder AddOpenTelemetryExporters<TBuilder>(this TBuilder builde
}

/// <summary>
/// Adds default health checks to the application builder.
/// Adds default health checks to the application, including a liveness check to ensure the app is responsive.
/// </summary>
/// <typeparam name="TBuilder">The type of the application builder.</typeparam>
/// <param name="builder">The application builder instance.</param>
/// <returns>The application builder instance with default health checks added.</returns>
/// <typeparam name="TBuilder">The type of the host application builder.</typeparam>
/// <param name="builder">The host application builder instance.</param>
/// <returns>The updated host application builder.</returns>
public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) where TBuilder : IHostApplicationBuilder
{
builder.Services.AddHealthChecks()
Expand All @@ -138,21 +131,22 @@ public static TBuilder AddDefaultHealthChecks<TBuilder>(this TBuilder builder) w
}

/// <summary>
/// Maps default endpoints for the application.
/// Maps default health check endpoints for the application.
/// Adds "/health" and "/alive" endpoints in development environments.
/// </summary>
/// <param name="app">The WebApplication instance.</param>
/// <returns>The WebApplication instance with default endpoints mapped.</returns>
/// <param name="app">The web application instance.</param>
/// <returns>The updated web application instance.</returns>
public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Adding health checks endpoints to applications in non-development environments has security implications.
// See https://aka.ms/dotnet/aspire/healthchecks for details before enabling these endpoints in non-development environments.
if (app.Environment.IsDevelopment())
{
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");
app.MapHealthChecks(HealthEndpointPath);

// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
app.MapHealthChecks(AlivenessEndpointPath, new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using ProcessFramework.Aspire.Shared;

var builder = WebApplication.CreateBuilder(args);

string otelExporterEndpoint = builder.GetConfiguration("OTEL_EXPORTER_OTLP_ENDPOINT");
string otelExporterHeaders = builder.GetConfiguration("OTEL_EXPORTER_OTLP_HEADERS");

AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnosticsSensitive", true);

var loggerFactory = LoggerFactory.Create(builder =>
{
// Add OpenTelemetry as a logging provider
builder.AddOpenTelemetry(options =>
{
options.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; });
// Format log messages. This defaults to false.
options.IncludeFormattedMessage = true;
});

builder.AddTraceSource("Microsoft.SemanticKernel");
builder.SetMinimumLevel(LogLevel.Information);
});

using var traceProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

builder.AddServiceDefaults();
builder.AddAzureOpenAIClient("openAiConnectionName");
builder.Services.AddSingleton(builder =>
{
var kernelBuilder = Kernel.CreateBuilder();

kernelBuilder.AddAzureOpenAIChatCompletion("gpt-4o", builder.GetService<AzureOpenAIClient>());

return kernelBuilder.Build();
});
builder.Services.AddKernel().AddAzureOpenAIChatCompletion("gpt-4o");

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,17 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
using OpenTelemetry;
using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using ProcessFramework.Aspire.Shared;

var builder = WebApplication.CreateBuilder(args);

string otelExporterEndpoint = builder.GetConfiguration("OTEL_EXPORTER_OTLP_ENDPOINT");
string otelExporterHeaders = builder.GetConfiguration("OTEL_EXPORTER_OTLP_HEADERS");

AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnosticsSensitive", true);

var loggerFactory = LoggerFactory.Create(builder =>
{
// Add OpenTelemetry as a logging provider
builder.AddOpenTelemetry(options =>
{
options.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; });
// Format log messages. This defaults to false.
options.IncludeFormattedMessage = true;
});

builder.AddTraceSource("Microsoft.SemanticKernel");
builder.SetMinimumLevel(LogLevel.Information);
});

using var traceProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

using var meterProvider = Sdk.CreateMeterProviderBuilder()
.AddMeter("Microsoft.SemanticKernel*")
.AddOtlpExporter(exporter => { exporter.Endpoint = new Uri(otelExporterEndpoint); exporter.Headers = otelExporterHeaders; exporter.Protocol = OtlpExportProtocol.Grpc; })
.Build();

builder.AddServiceDefaults();
builder.AddAzureOpenAIClient("openAiConnectionName");
builder.Services.AddSingleton(builder =>
{
var kernelBuilder = Kernel.CreateBuilder();

kernelBuilder.AddAzureOpenAIChatCompletion("gpt-4o", builder.GetService<AzureOpenAIClient>());

return kernelBuilder.Build();
});
builder.Services.AddKernel().AddAzureOpenAIChatCompletion("gpt-4o");

var app = builder.Build();

Expand Down
Loading