Skip to content

Commit 283cd97

Browse files
authoredNov 29, 2023
Obtain distro version from the informational assembly version (#66)
1 parent a06081a commit 283cd97

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed
 

‎.markdownlint.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ default: true
55
MD013:
66
code_blocks: false
77
tables: false
8+
9+
# Allow same headers for non-siblings, e. g. in the CHANGELOG
10+
MD024:
11+
siblings_only: true

‎CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## Unreleased
44

5+
### Bug fixes
6+
7+
* [#65](https://github.com/grafana/grafana-opentelemetry-dotnet/issues/65):
8+
Using the distribution broke self-contained applications. This has been fixed
9+
by using a different way to determine the distribution version.
10+
* [#64](https://github.com/grafana/grafana-opentelemetry-dotnet/issues/64): The
11+
version in `telemetry.distro.version` contained a trailing commit hash. This
12+
commit hash is removed now before populating the attribute.
13+
514
## 0.6.0-beta.2
615

716
### New features

‎src/Grafana.OpenTelemetry.Base/GrafanaOpenTelemetryResourceDetector.cs

+18-3
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,33 @@ public GrafanaOpenTelemetryResourceDetector(GrafanaOpenTelemetrySettings setting
2727

2828
public Resource Detect()
2929
{
30-
var assembly = typeof(GrafanaOpenTelemetryResourceDetector).Assembly;
31-
3230
var attributes = new List<KeyValuePair<string, object>>(new KeyValuePair<string, object>[]
3331
{
3432
new KeyValuePair<string, object>(ResourceKey_DistroName, ResourceValue_DistroName),
35-
new KeyValuePair<string, object>(ResourceKey_DistroVersion, FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion),
33+
new KeyValuePair<string, object>(ResourceKey_DistroVersion, GetDistroVersion()),
3634
new KeyValuePair<string, object>(ResourceKey_DeploymentEnvironment, _settings.DeploymentEnvironment)
3735
});
3836

3937
attributes.AddRange(_settings.ResourceAttributes);
4038

4139
return new Resource(attributes);
4240
}
41+
42+
static internal string GetDistroVersion()
43+
{
44+
var informationalVersion = typeof(GrafanaOpenTelemetryResourceDetector)
45+
.Assembly
46+
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
47+
.InformationalVersion;
48+
49+
if (string.IsNullOrWhiteSpace(informationalVersion))
50+
{
51+
informationalVersion = "0.0.0";
52+
}
53+
54+
// A Git hash is appended to the informational version after a "+" character. That's of limited use and
55+
// therefore removed here.
56+
return informationalVersion.Split('+')[0];
57+
}
4358
}
4459
}

0 commit comments

Comments
 (0)
Please sign in to comment.