| | | 1 | | using CShells.AspNetCore.Features; |
| | | 2 | | using CShells.FastEndpoints.Features; |
| | | 3 | | using CShells.Features; |
| | | 4 | | using Elsa.Diagnostics.OpenTelemetry.Extensions; |
| | | 5 | | using Elsa.Diagnostics.OpenTelemetry.Options; |
| | | 6 | | using Elsa.PackageManifest.Generator.Hints; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | using Microsoft.AspNetCore.Routing; |
| | | 9 | | using Microsoft.Extensions.DependencyInjection; |
| | | 10 | | using Microsoft.Extensions.Hosting; |
| | | 11 | | |
| | | 12 | | namespace Elsa.Diagnostics.OpenTelemetry.ShellFeatures; |
| | | 13 | | |
| | | 14 | | [ShellFeature( |
| | | 15 | | DisplayName = "OpenTelemetry Diagnostics", |
| | | 16 | | Description = "Provides OpenTelemetry diagnostics collection, query services, and live updates", |
| | | 17 | | DependsOn = ["ElsaFastEndpoints"])] |
| | | 18 | | [UsedImplicitly] |
| | | 19 | | public class OpenTelemetryFeature : IFastEndpointsShellFeature, IWebShellFeature |
| | | 20 | | { |
| | 0 | 21 | | private static readonly OpenTelemetryDiagnosticsOptions DefaultOptions = new(); |
| | | 22 | | |
| | | 23 | | [ManifestSetting( |
| | | 24 | | DisplayName = "Trace Capacity", |
| | | 25 | | Description = "Maximum number of recent traces retained in memory.", |
| | | 26 | | Category = "Diagnostics", |
| | | 27 | | DefaultValue = "5000", |
| | | 28 | | RestartRequired = true)] |
| | 0 | 29 | | public int TraceCapacity { get; set; } = DefaultOptions.TraceCapacity; |
| | | 30 | | |
| | | 31 | | [ManifestSetting( |
| | | 32 | | DisplayName = "Span Capacity", |
| | | 33 | | Description = "Maximum number of recent spans retained in memory.", |
| | | 34 | | Category = "Diagnostics", |
| | | 35 | | DefaultValue = "25000", |
| | | 36 | | RestartRequired = true)] |
| | 0 | 37 | | public int SpanCapacity { get; set; } = DefaultOptions.SpanCapacity; |
| | | 38 | | |
| | | 39 | | [ManifestSetting( |
| | | 40 | | DisplayName = "Metric Point Capacity", |
| | | 41 | | Description = "Maximum number of recent metric points retained in memory.", |
| | | 42 | | Category = "Diagnostics", |
| | | 43 | | DefaultValue = "25000", |
| | | 44 | | RestartRequired = true)] |
| | 0 | 45 | | public int MetricPointCapacity { get; set; } = DefaultOptions.MetricPointCapacity; |
| | | 46 | | |
| | | 47 | | [ManifestSetting( |
| | | 48 | | DisplayName = "Log Record Capacity", |
| | | 49 | | Description = "Maximum number of recent OTLP log records retained in memory.", |
| | | 50 | | Category = "Diagnostics", |
| | | 51 | | DefaultValue = "10000", |
| | | 52 | | RestartRequired = true)] |
| | 0 | 53 | | public int LogRecordCapacity { get; set; } = DefaultOptions.LogRecordCapacity; |
| | | 54 | | |
| | | 55 | | [ManifestSetting( |
| | | 56 | | DisplayName = "Resource Capacity", |
| | | 57 | | Description = "Maximum number of recent telemetry resources retained in memory.", |
| | | 58 | | Category = "Diagnostics", |
| | | 59 | | DefaultValue = "500", |
| | | 60 | | RestartRequired = true)] |
| | 0 | 61 | | public int ResourceCapacity { get; set; } = DefaultOptions.ResourceCapacity; |
| | | 62 | | |
| | | 63 | | [ManifestSetting( |
| | | 64 | | DisplayName = "Subscriber Channel Capacity", |
| | | 65 | | Description = "Maximum queued live updates per subscriber before updates are dropped.", |
| | | 66 | | Category = "Diagnostics", |
| | | 67 | | DefaultValue = "1000", |
| | | 68 | | RestartRequired = true)] |
| | 0 | 69 | | public int SubscriberChannelCapacity { get; set; } = DefaultOptions.SubscriberChannelCapacity; |
| | | 70 | | |
| | | 71 | | [ManifestSetting( |
| | | 72 | | DisplayName = "Max HTTP Request Body Size", |
| | | 73 | | Description = "Maximum OTLP HTTP/protobuf request body size in bytes.", |
| | | 74 | | Category = "Diagnostics", |
| | | 75 | | DefaultValue = "10485760", |
| | | 76 | | RestartRequired = true)] |
| | 0 | 77 | | public long MaxHttpRequestBodySize { get; set; } = DefaultOptions.MaxHttpRequestBodySize; |
| | | 78 | | |
| | | 79 | | public void ConfigureServices(IServiceCollection services) |
| | | 80 | | { |
| | 0 | 81 | | services.AddOpenTelemetryDiagnosticsServices(ConfigureOptions); |
| | 0 | 82 | | } |
| | | 83 | | |
| | | 84 | | public void MapEndpoints(IEndpointRouteBuilder endpoints, IHostEnvironment? environment) |
| | | 85 | | { |
| | 0 | 86 | | endpoints.MapOpenTelemetryHttpProtobufCollector(); |
| | 0 | 87 | | endpoints.MapOpenTelemetryGrpcCollector(); |
| | 0 | 88 | | endpoints.MapOpenTelemetryHub(); |
| | 0 | 89 | | } |
| | | 90 | | |
| | | 91 | | private void ConfigureOptions(OpenTelemetryDiagnosticsOptions options) |
| | | 92 | | { |
| | 0 | 93 | | options.TraceCapacity = TraceCapacity; |
| | 0 | 94 | | options.SpanCapacity = SpanCapacity; |
| | 0 | 95 | | options.MetricPointCapacity = MetricPointCapacity; |
| | 0 | 96 | | options.LogRecordCapacity = LogRecordCapacity; |
| | 0 | 97 | | options.ResourceCapacity = ResourceCapacity; |
| | 0 | 98 | | options.SubscriberChannelCapacity = SubscriberChannelCapacity; |
| | 0 | 99 | | options.MaxHttpRequestBodySize = MaxHttpRequestBodySize; |
| | 0 | 100 | | } |
| | | 101 | | } |