Skip to content

Commit

Permalink
PR feedback - change fetching version contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Apr 8, 2024
1 parent 0d8add2 commit 9f5f5bf
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{A49299
ProjectSection(SolutionItems) = preProject
src\Shared\ActivityHelperExtensions.cs = src\Shared\ActivityHelperExtensions.cs
src\Shared\ActivityInstrumentationHelper.cs = src\Shared\ActivityInstrumentationHelper.cs
src\Shared\AssemblyVersionExtensions.cs = src\Shared\AssemblyVersionExtensions.cs
src\Shared\DiagnosticDefinitions.cs = src\Shared\DiagnosticDefinitions.cs
src\Shared\ExceptionExtensions.cs = src\Shared\ExceptionExtensions.cs
src\Shared\Guard.cs = src\Shared\Guard.cs
src\Shared\InstrumentationScopeHelper.cs = src\Shared\InstrumentationScopeHelper.cs
src\Shared\MathHelper.cs = src\Shared\MathHelper.cs
src\Shared\PeerServiceResolver.cs = src\Shared\PeerServiceResolver.cs
src\Shared\PeriodicExportingMetricReaderHelper.cs = src\Shared\PeriodicExportingMetricReaderHelper.cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ namespace OpenTelemetry.Instrumentation.GrpcNetClient.Implementation;

internal sealed class GrpcClientDiagnosticListener : ListenerHandler
{
internal static readonly AssemblyName AssemblyName = typeof(GrpcClientDiagnosticListener).Assembly.GetName();
internal static readonly Assembly Assembly = typeof(GrpcClientDiagnosticListener).Assembly;
internal static readonly AssemblyName AssemblyName = Assembly.GetName();
internal static readonly string ActivitySourceName = AssemblyName.Name;
internal static readonly string Version = InstrumentationScopeHelper.GetPackageVersion<GrpcClientDiagnosticListener>();
internal static readonly string Version = Assembly.GetPackageVersion();
internal static readonly ActivitySource ActivitySource = new(ActivitySourceName, Version);

private const string OnStartEvent = "Grpc.Net.Client.GrpcOut.Start";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Instrumentation.Http\HttpRequestMessageContextPropagation.cs" Link="Includes\HttpRequestMessageContextPropagation.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\InstrumentationScopeHelper.cs" Link="Includes\InstrumentationScopeHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\AssemblyVersionExtensions.cs" Link="Includes\AssemblyVersionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Options\*.cs" Link="Includes\Options\%(Filename).cs" />
<Compile Include="$(RepoRoot)\src\Shared\Shims\NullableAttributes.cs" Link="Includes\Shims\NullableAttributes.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ internal sealed class SqlActivitySourceHelper
{
public const string MicrosoftSqlServerDatabaseSystemName = "mssql";

public static readonly AssemblyName AssemblyName = typeof(SqlActivitySourceHelper).Assembly.GetName();
public static readonly Assembly Assembly = typeof(SqlActivitySourceHelper).Assembly;
public static readonly AssemblyName AssemblyName = Assembly.GetName();
public static readonly string ActivitySourceName = AssemblyName.Name;
public static readonly ActivitySource ActivitySource = new(ActivitySourceName, InstrumentationScopeHelper.GetPackageVersion<SqlActivitySourceHelper>());
public static readonly ActivitySource ActivitySource = new(ActivitySourceName, Assembly.GetPackageVersion());
public static readonly string ActivityName = ActivitySourceName + ".Execute";

public static readonly IEnumerable<KeyValuePair<string, object>> CreationTags = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\InstrumentationScopeHelper.cs" Link="Includes\InstrumentationScopeHelper.cs" />
<Compile Include="$(RepoRoot)\src\Shared\AssemblyVersionExtensions.cs" Link="Includes\AssemblyVersionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Shims\NullableAttributes.cs" Link="Includes\Shims\NullableAttributes.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

namespace OpenTelemetry.Instrumentation;

internal static class InstrumentationScopeHelper
internal static class AssemblyVersionExtensions
{
public static string GetPackageVersion<T>()
public static string GetPackageVersion(this Assembly assembly)
{
// MinVer https://github.com/adamralph/minver?tab=readme-ov-file#version-numbers
// together with Microsoft.SourceLink.GitHub https://github.com/dotnet/sourcelink
// fills AssemblyInformationalVersionAttribute by
// `{NuGetPackageVersion}+{CommitHash}`, e.g. `1.7.0-beta.1.86+33d5521a73e881ac59d4bf1213765270ec2422ff`.
// For Scope version, value of AssemblyInformationalVersionAttribute without commit hash is returned.
return typeof(T).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split(new[] { '+' }, 2)[0];
// For package version, value of AssemblyInformationalVersionAttribute without commit hash is returned.
return assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split(new[] { '+' }, 2)[0];
}
}

0 comments on commit 9f5f5bf

Please sign in to comment.