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 LogExporter to special case {OriginalFormat} to populate body #3182

Conversation

cijothomas
Copy link
Member

This PR modifies OTLP LogExporter to:
"specially" treat {OriginalFormat} key from LogRecord.StateValues, and populate Body from its value, if LogRecord.FormattedMessage is not available.

Why:
Official docs on logging recommends (or rather only talks about), using the extensions methods to do logging, which would result in storing the "template" as {OriginalFormat}

Since this is the most common scenario, I am proposing to "special" case this, to populate body from. (If user opted-in for IncludeFormattedMessage=true, then this special casing is not applied, and {OriginalFormat} get stores as just any other attribute, and Body will be the LogRecord.FormattedMessage. Okay to change that behavior if there is agreement.)

@cijothomas cijothomas requested a review from a team April 14, 2022 18:01
}
else
{
Assert.Equal("OpenTelemetry {Greeting} {Subject}!", otlpLogRecord.Body.StringValue);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the "special" treatment of {OriginalFormat} key.

{
Assert.Null(otlpLogRecord.Body);
}
else
Copy link
Member Author

Choose a reason for hiding this comment

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

intentionally making the same Assert on If..Else, to make it easy for readers :)

@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #3182 (e9ec70c) into main (ed3945d) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3182      +/-   ##
==========================================
+ Coverage   84.85%   84.87%   +0.01%     
==========================================
  Files         259      259              
  Lines        9326     9330       +4     
==========================================
+ Hits         7914     7919       +5     
+ Misses       1412     1411       -1     
Impacted Files Coverage Δ
...etryProtocol/Implementation/LogRecordExtensions.cs 78.08% <100.00%> (+1.27%) ⬆️
...emetry.Api/Internal/OpenTelemetryApiEventSource.cs 82.35% <0.00%> (+2.94%) ⬆️

Copy link

@jviau jviau left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@alanwest alanwest left a comment

Choose a reason for hiding this comment

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

LGTM

([#3177](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3177))

* LogExporter to special case {OriginalFormat} to populate
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* LogExporter to special case {OriginalFormat} to populate
* LogExporter to special case '{OriginalFormat}' to populate

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

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

@cijothomas cijothomas merged commit c926c02 into open-telemetry:main Apr 14, 2022
@cijothomas cijothomas deleted the cijothomas/otlplog_specialcaseoriginalformat branch April 14, 2022 20:58
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.

5 participants