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] Include instrumentation version in debug log #6074

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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.

…ests.cs

Co-authored-by: Piotr Kiełkowicz <pkiekowicz@splunk.com>
@CodeBlanch CodeBlanch changed the title include instrumentation.Version in log [sdk-logs] Include instrumentation version in debug log Jan 22, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants