Skip to content

Commit 4a1c7f3

Browse files
authored
Remove build pre-release tags and build metadata from service.version (#2274)
1 parent f6b0237 commit 4a1c7f3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/api/Elastic.Documentation.Api.Infrastructure/OpenTelemetry/OpenTelemetryExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,18 @@ private static void ConfigureServiceVersionAttributes<TBuilder>(TBuilder builder
105105
where TBuilder : IHostApplicationBuilder
106106
{
107107

108-
var serviceVersion = Assembly.GetExecutingAssembly()
108+
var informationalVersion = Assembly.GetExecutingAssembly()
109109
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
110110

111-
if (serviceVersion is null)
111+
if (informationalVersion is null)
112112
{
113113
Console.WriteLine($"Unable to determine service.version from {nameof(AssemblyInformationalVersionAttribute)}. Skipping setting it.");
114114
return;
115115
}
116116

117+
// Extract just major.minor.patch by removing prerelease tags (-) and build metadata (+)
118+
var serviceVersion = informationalVersion.Split(['+', '-'])[0];
119+
117120
var versionAttribute = new KeyValuePair<string, object>("service.version", serviceVersion);
118121

119122
_ = builder.Services.ConfigureOpenTelemetryTracerProvider(tracerProviderBuilder =>

0 commit comments

Comments
 (0)