Skip to content

Commit 2dea270

Browse files
update SdkVersion to include pre-release part (Azure#24290)
* update SdkVersion to include pre-release part * remove try catch as it is there in GetSdkVersion() * remove default version as null/empty should be ok. * adding back try catch * remove default new Version()
1 parent 65d942d commit 2dea270

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/src/SdkVersionUtils.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ private static string GetSdkVersion()
1717
{
1818
try
1919
{
20-
Version dotnetSdkVersion = GetVersion(typeof(object));
21-
Version otelSdkVersion = GetVersion(typeof(Sdk));
22-
Version extensionVersion = GetVersion(typeof(AzureMonitorTraceExporter));
20+
string dotnetSdkVersion = GetVersion(typeof(object));
21+
string otelSdkVersion = GetVersion(typeof(Sdk));
22+
string extensionVersion = GetVersion(typeof(AzureMonitorTraceExporter));
2323

24-
return string.Format(CultureInfo.InvariantCulture, $"dotnet{dotnetSdkVersion.ToString(2)}:otel{otelSdkVersion.ToString(3)}:ext{extensionVersion.ToString(3)}");
24+
return string.Format(CultureInfo.InvariantCulture, $"dotnet{dotnetSdkVersion}:otel{otelSdkVersion}:ext{extensionVersion}");
2525
}
2626
catch (Exception ex)
2727
{
@@ -30,18 +30,27 @@ private static string GetSdkVersion()
3030
}
3131
}
3232

33-
private static Version GetVersion(Type type)
33+
private static string GetVersion(Type type)
3434
{
35-
// TODO: Distinguish preview/stable release and minor versions. e.g: 5.0.0-preview.8.20365.13
36-
string versionString = type
35+
try
36+
{
37+
string versionString = type
3738
.Assembly
38-
.GetCustomAttributes(false)
39-
.OfType<AssemblyFileVersionAttribute>()
39+
.GetCustomAttributes<AssemblyInformationalVersionAttribute>()
4040
.First()
41-
.Version;
41+
.InformationalVersion;
4242

43-
// Return zeros rather then failing if the version string fails to parse
44-
return Version.TryParse(versionString, out var version) ? version : new Version();
43+
// Informational version will be something like 1.1.0-beta2+a25741030f05c60c85be102ce7c33f3899290d49.
44+
// Ignoring part after '+' if it is present.
45+
string shortVersion = versionString?.Split('+')[0];
46+
47+
return shortVersion;
48+
}
49+
catch (Exception ex)
50+
{
51+
AzureMonitorExporterEventSource.Log.Write($"ErrorInitializingPartOfSdkVersion{EventLevelSuffix.Error}", $"{ex.ToInvariantString()}");
52+
return null;
53+
}
4554
}
4655
}
4756
}

0 commit comments

Comments
 (0)