< Summary

Information
Class: Elsa.Diagnostics.OpenTelemetry.Services.CollectorConfigurationProvider
Assembly: Elsa.Diagnostics.OpenTelemetry
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.OpenTelemetry/Services/CollectorConfigurationProvider.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 34
Line coverage: 100%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAsync(...)90%1010100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.OpenTelemetry/Services/CollectorConfigurationProvider.cs

#LineLine coverage
 1using Elsa.Diagnostics.OpenTelemetry.Contracts;
 2using Elsa.Diagnostics.OpenTelemetry.Models;
 3using Elsa.Diagnostics.OpenTelemetry.Options;
 4using Microsoft.Extensions.Options;
 5
 6namespace Elsa.Diagnostics.OpenTelemetry.Services;
 7
 48public class CollectorConfigurationProvider(IOptions<OpenTelemetryDiagnosticsOptions> options) : ICollectorConfiguration
 9{
 410    private readonly OpenTelemetryDiagnosticsOptions _options = options.Value;
 11
 12    public ValueTask<CollectorConfiguration> GetAsync(CancellationToken cancellationToken = default)
 13    {
 314        var headers = string.IsNullOrWhiteSpace(_options.ApiKey)
 315            ? new Dictionary<string, string>()
 316            : new Dictionary<string, string> { [_options.ApiKeyHeaderName] = "<configured>" };
 317        var grpcEnabled = _options.EnableGrpc && !string.IsNullOrWhiteSpace(_options.GrpcEndpointPath);
 318        var grpcDisabledReason = grpcEnabled
 319            ? null
 320            : _options.EnableGrpc
 321                ? "gRPC endpoint path is not configured."
 322                : _options.GrpcDisabledReason;
 23
 324        var configuration = new CollectorConfiguration(
 325            new CollectorEndpointInfo("http/protobuf", _options.HttpEndpointPath, true, null),
 326            new CollectorEndpointInfo("grpc", grpcEnabled ? _options.GrpcEndpointPath : null, grpcEnabled, grpcDisabledR
 327            "OTEL_SERVICE_NAME",
 328            "OTEL_EXPORTER_OTLP_ENDPOINT",
 329            "OTEL_EXPORTER_OTLP_PROTOCOL",
 330            headers);
 31
 332        return ValueTask.FromResult(configuration);
 33    }
 34}