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

Allow us to set CategoryName when using the logging bridge API #5274

Closed
AB027PS opened this issue Jan 29, 2024 · 1 comment · Fixed by #5300
Closed

Allow us to set CategoryName when using the logging bridge API #5274

AB027PS opened this issue Jan 29, 2024 · 1 comment · Fixed by #5300
Labels
enhancement New feature or request

Comments

@AB027PS
Copy link
Contributor

AB027PS commented Jan 29, 2024

Feature Request

Is your feature request related to a problem?

If I create a logger with the OtlpExporter using the bridge API and then emit a log, an exception will be thrown at line 50 here

foreach (var logRecord in logRecordBatch)
{
var otlpLogRecord = this.ToOtlpLog(logRecord);
if (otlpLogRecord != null)
{
if (!logsByCategory.TryGetValue(logRecord.CategoryName, out var scopeLogs))
{
scopeLogs = this.GetLogListFromPool(logRecord.CategoryName);
logsByCategory.Add(logRecord.CategoryName, scopeLogs);
resourceLogs.ScopeLogs.Add(scopeLogs);
}
because logRecord.CategoryName will be null. A possible workaround is to create a processor which will set CategoryName to a non-null value on each LogRecord separately, but that only prevents the exceptions and doesn't address the feature request.

Describe the solution you'd like:

Add a CategoryName property to the LogRecordData struct.

@AB027PS AB027PS added the enhancement New feature or request label Jan 29, 2024
@CodeBlanch
Copy link
Member

@AB027PS Thanks for this bug report! I commented on the PR but I think a better change would be something like this inside OtlpExporter:

         var scopeName = logRecord.CategoryName ?? logRecord.Logger?.Name ?? DefaultScopeName;
         if (!logsByCategory.TryGetValue(scopeName, out var scopeLogs)) 
         { 
             scopeLogs = this.GetLogListFromPool(scopeName); 
             logsByCategory.Add(scopeName, scopeLogs); 
             resourceLogs.ScopeLogs.Add(scopeLogs); 
         } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants