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

[otlp] Use LogRecord.Logger.Name for instrumentation scope if LogRecord.CategoryName is null #5300

Merged
merged 4 commits into from
Feb 5, 2024

Conversation

AB027PS
Copy link
Contributor

@AB027PS AB027PS commented Feb 1, 2024

Fixes #5274

Changes

I made a change to OtlpLogRecordTransformer to address a situation where LogRecord.CategoryName is null
according to a suggestion in #5274

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)

@AB027PS AB027PS requested a review from a team February 1, 2024 08:13
@CodeBlanch CodeBlanch added pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package logs Logging signal related labels Feb 1, 2024
@CodeBlanch CodeBlanch changed the title fixing a bug where LogRecord.CategoryName is null [otlp] Use LogRecord.Logger.Name for instrumentation scope if LogRecord.CategoryName is null Feb 1, 2024
@CodeBlanch
Copy link
Member

@AB027PS This is good thanks! There are a few things we need to do before we can merge:

  • Resolve warnings. Looks like some style issues. If you are using VS switch to Release config and rebuild that should surface everything for you locally.

  • Update CHANGELOG. Add a note at the bottom of the unreleased section here:

    Something like this...

    * Updated `OtlpLogExporter` to set instrumentation scope name on the data model
      from `LogRecord.Logger.Name` if `LogRecord.CategoryName` is `null`. This is
      typically the case when using the experimental Logs Bridge API.
      ([#5300](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5300))
    
  • We need a unit test. In here:

    Drop a test like...

     [Fact]
     public void LogRecordLoggerNameIsExportedWhenUsingBridgeApi()
     {
         LogRecordAttributeList attributes = default;
         attributes.Add("name", "tomato");
         attributes.Add("price", 2.99);
         attributes.Add("{OriginalFormat}", "Hello from {name} {price}.");
    
         var logRecords = new List<LogRecord>();
    
         using (var loggerProvider = Sdk.CreateLoggerProviderBuilder()
             .AddInMemoryExporter(logRecords)
             .Build())
         {
             var logger = loggerProvider.GetLogger("my_instrumentation_scope_name");
    
             logger.EmitLog(new LogRecordData(), attributes);
         }
    
         Assert.Single(logRecords);
    
         var otlpLogRecordTransformer = new OtlpLogRecordTransformer(DefaultSdkLimitOptions, new());
    
         var batch = new Batch<LogRecord>(new[] { logRecords[0] }, 1);
    
         var request = otlpLogRecordTransformer.BuildExportRequest(
             new Proto.Resource.V1.Resource(),
             batch);
    
         Assert.NotNull(request);
         Assert.Single(request.ResourceLogs);
         Assert.Single(request.ResourceLogs[0].ScopeLogs);
    
         Assert.Equal("my_instrumentation_scope_name", request.ResourceLogs[0].ScopeLogs[0].Scope?.Name);
     }

If you need help with anything let me know, happy to assist.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@CodeBlanch CodeBlanch merged commit ef977c1 into open-telemetry:main Feb 5, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logs Logging signal related pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow us to set CategoryName when using the logging bridge API
4 participants