Skip to content

[sdk-logs] Include instrumentation version in debug log #6074

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

Conversation

SimonCropp
Copy link
Contributor

Changes

Given Instrumentation version is being captured in AddInstrumentation

    public override LoggerProviderBuilder AddInstrumentation<TInstrumentation>(Func<TInstrumentation> instrumentationFactory)
    {
        Debug.Assert(instrumentationFactory != null, "instrumentationFactory was null");

        this.Instrumentation.Add(
            new InstrumentationRegistration(
                typeof(TInstrumentation).Name,
                typeof(TInstrumentation).Assembly.GetName().Version?.ToString() ?? DefaultInstrumentationVersion,
                instrumentationFactory!()));

        return this;
    }

I assume the intent is to use it in the logs? So i added it there and added a test to assert it.

If u think Instrumentation version has no value in the logs, do you want another PR that removes the redundant version detection?

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

@SimonCropp SimonCropp requested a review from a team as a code owner January 17, 2025 23:27
@github-actions github-actions bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Jan 17, 2025
@@ -69,7 +69,7 @@ public LoggerProviderSdk(
this.instrumentations.Add(instrumentation.Instance);
}

instrumentationFactoriesAdded.Append(instrumentation.Name);
instrumentationFactoriesAdded.Append($"{instrumentation.Name} {instrumentation.Version}");
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not against logging of the Version here. It is important to mention that it will be taking the version in this way typeof(TInstrumentation).Assembly.GetName().Version?.ToString() ?? "1.0.0.0". It means that it will be reporting only major version of the library in most cases (if the library follows this recomendation).

This version will be different than typical data reported by the contrib instrumentation packages https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/89f0af731441a364779693a1874c57f33b1e721c/src/Shared/AssemblyVersionExtensions.cs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

want me to change it to not record if no version is found?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am telling that it usually will record 1.0.0.0/2.0.0.0/3.0.0.0,etc. There will be no differences between e.g. 1.1.0 nuget package and 1.2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then shouldnt it default to use the AssemblyInformationalVersionAttribute it is exists?

Copy link
Contributor

@Kielek Kielek Jan 21, 2025

Choose a reason for hiding this comment

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

For sure, it is one of the options, you can consider, and it should working for all contrib packages.

@CodeBlanch CodeBlanch changed the title include instrumentation.Version in log [sdk-logs] Include instrumentation version in debug log Jan 22, 2025
Copy link
Contributor

This PR was marked stale due to lack of activity and will be closed in 7 days. Commenting or pushing will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Jan 29, 2025
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.40%. Comparing base (48e5a08) to head (038c90c).
Report is 20 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6074      +/-   ##
==========================================
- Coverage   86.40%   86.40%   -0.01%     
==========================================
  Files         257      257              
  Lines       11656    11655       -1     
==========================================
- Hits        10071    10070       -1     
  Misses       1585     1585              
Files with missing lines Coverage Δ
src/OpenTelemetry/Logs/LoggerProviderSdk.cs 92.78% <ø> (-0.08%) ⬇️

Copy link
Contributor

github-actions bot commented Feb 5, 2025

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants