Enable optional OpenTelemetry tracing configuration.

Added a feature flag (`useOtel`) to conditionally enable OpenTelemetry tracing. This allows developers to toggle tracing for debugging or testing without affecting the default behavior.
This commit is contained in:
Sipke Schoorstra 2025-03-08 22:03:13 +01:00
parent 1d7fd81b3e
commit d19fc6e976
No known key found for this signature in database
GPG key ID: 5C10502B28A4268F

View file

@ -96,6 +96,7 @@ const bool useTenantsFromConfiguration = true;
const bool useSecrets = false;
const bool disableVariableWrappers = false;
const bool disableVariableCopying = false;
const bool useOtel = false;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
@ -120,13 +121,15 @@ var sqlDatabaseProvider = Enum.Parse<SqlDatabaseProvider>(configuration["Databas
TypeAliasRegistry.RegisterAlias("OrderReceivedProducerFactory", typeof(GenericProducerFactory<string, OrderReceived>));
TypeAliasRegistry.RegisterAlias("OrderReceivedConsumerFactory", typeof(GenericConsumerFactory<string, OrderReceived>));
if (useOtel)
{
// Configure OpenTelemetry Tracing
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("Elsa.Workflows") // Match your ActivitySource name here
.SetSampler(new AlwaysOnSampler()) // Always record traces for testing
.AddConsoleExporter() // Export spans to the console (optional)
.Build();
}
// Add Elsa services.
services