| | | 1 | | using Elsa.Diagnostics.OpenTelemetry.Contracts; |
| | | 2 | | using Elsa.Diagnostics.OpenTelemetry.Models; |
| | | 3 | | using Elsa.Diagnostics.OpenTelemetry.Options; |
| | | 4 | | using Microsoft.Extensions.Options; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Diagnostics.OpenTelemetry.Services; |
| | | 7 | | |
| | 4 | 8 | | public class CollectorConfigurationProvider(IOptions<OpenTelemetryDiagnosticsOptions> options) : ICollectorConfiguration |
| | | 9 | | { |
| | 4 | 10 | | private readonly OpenTelemetryDiagnosticsOptions _options = options.Value; |
| | | 11 | | |
| | | 12 | | public ValueTask<CollectorConfiguration> GetAsync(CancellationToken cancellationToken = default) |
| | | 13 | | { |
| | 3 | 14 | | var headers = string.IsNullOrWhiteSpace(_options.ApiKey) |
| | 3 | 15 | | ? new Dictionary<string, string>() |
| | 3 | 16 | | : new Dictionary<string, string> { [_options.ApiKeyHeaderName] = "<configured>" }; |
| | 3 | 17 | | var grpcEnabled = _options.EnableGrpc && !string.IsNullOrWhiteSpace(_options.GrpcEndpointPath); |
| | 3 | 18 | | var grpcDisabledReason = grpcEnabled |
| | 3 | 19 | | ? null |
| | 3 | 20 | | : _options.EnableGrpc |
| | 3 | 21 | | ? "gRPC endpoint path is not configured." |
| | 3 | 22 | | : _options.GrpcDisabledReason; |
| | | 23 | | |
| | 3 | 24 | | var configuration = new CollectorConfiguration( |
| | 3 | 25 | | new CollectorEndpointInfo("http/protobuf", _options.HttpEndpointPath, true, null), |
| | 3 | 26 | | new CollectorEndpointInfo("grpc", grpcEnabled ? _options.GrpcEndpointPath : null, grpcEnabled, grpcDisabledR |
| | 3 | 27 | | "OTEL_SERVICE_NAME", |
| | 3 | 28 | | "OTEL_EXPORTER_OTLP_ENDPOINT", |
| | 3 | 29 | | "OTEL_EXPORTER_OTLP_PROTOCOL", |
| | 3 | 30 | | headers); |
| | | 31 | | |
| | 3 | 32 | | return ValueTask.FromResult(configuration); |
| | | 33 | | } |
| | | 34 | | } |