diff --git a/src/api/Elastic.Documentation.Api.Infrastructure/OpenTelemetry/OpenTelemetryExtensions.cs b/src/api/Elastic.Documentation.Api.Infrastructure/OpenTelemetry/OpenTelemetryExtensions.cs index fc33e4675..d6572a751 100644 --- a/src/api/Elastic.Documentation.Api.Infrastructure/OpenTelemetry/OpenTelemetryExtensions.cs +++ b/src/api/Elastic.Documentation.Api.Infrastructure/OpenTelemetry/OpenTelemetryExtensions.cs @@ -105,15 +105,18 @@ private static void ConfigureServiceVersionAttributes(TBuilder builder where TBuilder : IHostApplicationBuilder { - var serviceVersion = Assembly.GetExecutingAssembly() + var informationalVersion = Assembly.GetExecutingAssembly() .GetCustomAttribute()?.InformationalVersion; - if (serviceVersion is null) + if (informationalVersion is null) { Console.WriteLine($"Unable to determine service.version from {nameof(AssemblyInformationalVersionAttribute)}. Skipping setting it."); return; } + // Extract just major.minor.patch by removing prerelease tags (-) and build metadata (+) + var serviceVersion = informationalVersion.Split(['+', '-'])[0]; + var versionAttribute = new KeyValuePair("service.version", serviceVersion); _ = builder.Services.ConfigureOpenTelemetryTracerProvider(tracerProviderBuilder =>