Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk.logs] Fix the version reported by LogRecord.Logger when using ILogger integration #4635

Conversation

CodeBlanch
Copy link
Member

@CodeBlanch CodeBlanch commented Jul 5, 2023

Relates to #4433

Changes

  • Fixes the logger instrumentation scope when using ILogger to report the {majorVersion}.{minorVersion}.{patchVersion}.{pre-release label}.{pre-release version}.{gitHeight} from the SDK AssemblyInformationalVersionAttribute (eg 1.5.0-alpha.1) instead of AssemblyVersion (eg 1.0.0.0).

Merge requirement checklist

  • CONTRIBUTING guidelines followed (nullable enabled, static analysis, etc.)
  • Unit tests added/updated

@CodeBlanch CodeBlanch requested a review from a team July 5, 2023 17:20
@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #4635 (84b3f02) into main (ad08228) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 84b3f02 differs from pull request most recent head b806633. Consider uploading reports for the commit b806633 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #4635   +/-   ##
=======================================
  Coverage   84.94%   84.94%           
=======================================
  Files         314      313    -1     
  Lines       12681    12611   -70     
=======================================
- Hits        10772    10713   -59     
+ Misses       1909     1898   -11     
Impacted Files Coverage Δ
.../OpenTelemetry/Logs/ILogger/OpenTelemetryLogger.cs 86.79% <100.00%> (ø)
src/OpenTelemetry/Logs/LogRecord.cs 67.37% <100.00%> (+0.23%) ⬆️
...enTelemetry/Resources/ResourceBuilderExtensions.cs 100.00% <100.00%> (+9.37%) ⬆️
src/OpenTelemetry/Sdk.cs 100.00% <100.00%> (ø)

... and 26 files with indirect coverage changes

@@ -41,13 +42,20 @@ static Sdk()
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
Activity.ForceDefaultIdFormat = true;
SelfDiagnostics.EnsureInitialized();

var sdkVersion = typeof(Sdk).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored! Sorry about that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we test this? The current test seems to be insufficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fully robust probably needs an integration test that looks at the actual dll's AssemblyInformationalVersionAttribute spit out by the build system? Don't want to tackle that on this PR but I added a unit test that covers the parse logic.

}

/// <summary>
/// Gets a value indicating whether instrumentation is suppressed (disabled).
/// </summary>
public static bool SuppressInstrumentation => SuppressInstrumentationScope.IsSuppressed;

internal static string InformationalVersion { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal static string InformationalVersion { get; }
internal static readonly string InformationalVersion;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this, but why? 🤣 A property with just a getter ({ get; }) is readonly for the backing generated by the compiler IIRC.

Copy link
Contributor

@utpilla utpilla Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why?

Just because it's more obvious and intuitive when you use readonly field 😀

@CodeBlanch CodeBlanch merged commit 66a6062 into open-telemetry:main Jul 10, 2023
@CodeBlanch CodeBlanch deleted the sdk-logs-ilogger-instrumentationscope branch July 10, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants