-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathAutoInstrumentationVersion.cs
37 lines (30 loc) · 1.37 KB
/
AutoInstrumentationVersion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
using System.Reflection;
using OpenTelemetry.AutoInstrumentation.Configurations;
namespace OpenTelemetry.AutoInstrumentation;
internal class AutoInstrumentationVersion
{
public static readonly string Version = GetAssemblyInformationalVersion();
private static string GetAssemblyInformationalVersion()
{
try
{
var informationalVersion = typeof(ResourceConfigurator).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
if (informationalVersion == null)
{
return string.Empty;
}
// informationalVersion could be in the following format:
// {majorVersion}.{minorVersion}.{patchVersion}.{pre-release label}.{pre-release version}.{gitHeight}.{Git SHA of current commit}
// The following parts are optional: pre-release label, pre-release version, git height, Git SHA of current commit
// for example: 1.5.0-alpha.1.40+807f703e1b4d9874a92bd86d9f2d4ebe5b5d52e4
var indexOfPlusSign = informationalVersion.IndexOf('+');
return indexOfPlusSign > 0 ? informationalVersion.Substring(0, indexOfPlusSign) : informationalVersion;
}
catch (Exception)
{
return string.Empty;
}
}
}