Skip to content
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

Enable instrumentation via IHostApplicationBuilder #58

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
35 changes: 17 additions & 18 deletions samples/DurableTask.Extensions.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
// Can register DataConvert in service container, or in options below.
// services.AddSingleton<DataConverter>(new StjDataConverter());
services.AddSingleton<IConsole, ConsoleWrapper>();
services.AddHostedService<TaskEnqueuer>();
})
.ConfigureTaskHubWorker((context, builder) =>
{
builder.WithOrchestrationService(new LocalOrchestrationService());
builder.AddDurableExtensions(opt => opt.DataConverter = new StjDataConverter());
builder.AddClient();
builder.AddOrchestrationsFromAssembly<GreetingsOrchestration>(includePrivate: true);
builder.AddActivitiesFromAssembly<GreetingsOrchestration>(includePrivate: true);
})
.UseConsoleLifetime()
.Build();
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

// Can register DataConvert in service container, or in options below.
// builder.Services.AddSingleton<DataConverter>(new StjDataConverter());
builder.Services.AddSingleton<IConsole, ConsoleWrapper>();
builder.Services.AddHostedService<TaskEnqueuer>();

builder.ConfigureTaskHubWorker((context, builder) =>
{
builder.WithOrchestrationService(new LocalOrchestrationService());
builder.AddDurableExtensions(opt => opt.DataConverter = new StjDataConverter());
builder.AddClient();
builder.AddOrchestrationsFromAssembly<GreetingsOrchestration>(includePrivate: true);
builder.AddActivitiesFromAssembly<GreetingsOrchestration>(includePrivate: true);
});

IHost host = builder.Build();

await host.RunAsync();

Expand Down
33 changes: 16 additions & 17 deletions samples/DurableTask.Instrumentation.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
.AddZipkinExporter()
.Build();

IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddSingleton<IConsole, ConsoleWrapper>();
services.AddHostedService<TaskEnqueuer>();
})
.ConfigureTaskHubWorker((context, builder) =>
{
builder.WithOrchestrationService(GetOrchestrationService());
builder.AddDurableExtensions();
builder.AddDurableInstrumentation();
builder.AddClient();
builder.AddOrchestrationsFromAssembly<TopOrchestration>(includePrivate: true);
builder.AddActivitiesFromAssembly<TopOrchestration>(includePrivate: true);
})
.UseConsoleLifetime()
.Build();
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Services.AddSingleton<IConsole, ConsoleWrapper>();
builder.Services.AddHostedService<TaskEnqueuer>();

builder.ConfigureTaskHubWorker((context, builder) =>
{
builder.WithOrchestrationService(GetOrchestrationService());
builder.AddDurableExtensions();
builder.AddDurableInstrumentation();
builder.AddClient();
builder.AddOrchestrationsFromAssembly<TopOrchestration>(includePrivate: true);
builder.AddActivitiesFromAssembly<TopOrchestration>(includePrivate: true);
});

IHost host = builder.Build();

await host.RunAsync();

Expand Down
52 changes: 26 additions & 26 deletions samples/DurableTask.Samples/Program.cs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, this file could be updated to use the minimal API approach of leaving out the Main method.

Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ public class Program
/// <returns>A task that completes when this program is finished running.</returns>
public static Task Main(string[] args)
{
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder => builder.AddUserSecrets<Program>())
.ConfigureServices(services =>
{
services.Configure<TaskHubOptions>(opt =>
{
opt.CreateIfNotExists = true;
});
services.AddSingleton<IConsole, ConsoleWrapper>();
services.AddHostedService<TaskEnqueuer>();
services.AddSingleton(UseLocalEmulator());
})
.ConfigureTaskHubWorker((context, builder) =>
{
builder.AddClient();
builder.UseOrchestrationMiddleware<SampleMiddleware>();
builder.UseActivityMiddleware<SampleMiddleware>();

builder
.AddOrchestration<GreetingsOrchestration>()
.AddOrchestration<GenericOrchestrationRunner>();

builder.AddActivitiesFromAssembly<Program>();
})
.UseConsoleLifetime()
.Build();
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

builder.Configuration.AddUserSecrets<Program>();

builder.Services.Configure<TaskHubOptions>(opt =>
{
opt.CreateIfNotExists = true;
});
builder.Services.AddSingleton<IConsole, ConsoleWrapper>();
builder.Services.AddHostedService<TaskEnqueuer>();
builder.Services.AddSingleton(UseLocalEmulator());

builder.ConfigureTaskHubWorker((context, builder) =>
{
builder.AddClient();
builder.UseOrchestrationMiddleware<SampleMiddleware>();
builder.UseActivityMiddleware<SampleMiddleware>();

builder
.AddOrchestration<GreetingsOrchestration>()
.AddOrchestration<GenericOrchestrationRunner>();

builder.AddActivitiesFromAssembly<Program>();
});

IHost host = builder.Build();

return host.RunAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace DurableTask.Hosting;

/// <summary>
/// Extensions for configuring a task hub worker service on <see cref="IHostBuilder"/>.
/// Extensions for configuring a task hub worker service on <see cref="IHostBuilder"/> or <see cref="IHostApplicationBuilder"/>.
/// </summary>
public static class TaskHubHostBuilderExtensions
{
Expand All @@ -28,6 +28,21 @@
return builder.ConfigureTaskHubWorker(configure, _ => { });
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
/// <param name="builder">The host builder, not null.</param>
/// <param name="configure">The action to configure the worker, not null.</param>
/// <returns>The original host builder with task hub worker configured.</returns>
public static IHostApplicationBuilder ConfigureTaskHubWorker(

Check failure on line 37 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
this IHostApplicationBuilder builder, Action<ITaskHubWorkerBuilder> configure)

Check failure on line 38 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
{
Check.NotNull(builder);
Check.NotNull(configure);

return builder.ConfigureTaskHubWorker(configure, _ => { });
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
Expand All @@ -47,6 +62,25 @@
return builder.ConfigureTaskHubWorker((_, b) => configure(b), configureOptions);
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
/// <param name="builder">The host builder, not null.</param>
/// <param name="configure">The action to configure the worker, not null.</param>
/// <param name="configureOptions">The action to configure the task hub host options.</param>
/// <returns>The original host builder with task hub worker configured.</returns>
public static IHostApplicationBuilder ConfigureTaskHubWorker(

Check failure on line 72 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
this IHostApplicationBuilder builder,

Check failure on line 73 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
Action<ITaskHubWorkerBuilder> configure,
Action<TaskHubOptions> configureOptions)
{
Check.NotNull(builder);
Check.NotNull(configure);
Check.NotNull(configureOptions);

return builder.ConfigureTaskHubWorker((_, b) => configure(b), configureOptions);
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
Expand All @@ -61,6 +95,20 @@
return builder.ConfigureTaskHubWorker(configure, _ => { });
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
/// <param name="builder">The host builder, not null.</param>
/// <param name="configure">The action to configure the worker, not null.</param>
/// <returns>The original host builder with task hub worker configured.</returns>
public static IHostApplicationBuilder ConfigureTaskHubWorker(

Check failure on line 104 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
this IHostApplicationBuilder builder, Action<IHostApplicationBuilder, ITaskHubWorkerBuilder> configure)

Check failure on line 105 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 105 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
{
Check.NotNull(builder);
Check.NotNull(configure);
return builder.ConfigureTaskHubWorker(configure, _ => { });
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
Expand Down Expand Up @@ -93,4 +141,34 @@

return builder;
}

/// <summary>
/// Configures the task hub worker background service.
/// </summary>
/// <param name="builder">The host builder, not null.</param>
/// <param name="configure">The action to configure the worker, not null.</param>
/// <param name="configureOptions">The action to configure the task hub host options.</param>
/// <returns>The original host builder with task hub worker configured.</returns>
public static IHostApplicationBuilder ConfigureTaskHubWorker(

Check failure on line 152 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
this IHostApplicationBuilder builder,

Check failure on line 153 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
Action<IHostApplicationBuilder, ITaskHubWorkerBuilder> configure,

Check failure on line 154 in src/DurableTask.Hosting/src/Extensions/TaskHubHostBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'IHostApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
Action<TaskHubOptions> configureOptions)
{
Check.NotNull(builder);
Check.NotNull(configure);
Check.NotNull(configureOptions);

builder.Services.AddOptions();
builder.Services.AddLogging();

builder.Services
.AddOptions<TaskHubOptions>()
.Bind(builder.Configuration.GetSection("TaskHub"))
.Configure(configureOptions);

builder.Services.AddTaskHubWorker(taskHubBuilder => configure(builder, taskHubBuilder));
builder.Services.AddHostedService<TaskHubBackgroundService>();

return builder;
}
}
Loading
Loading