Skip to content

OTLP LogExporter to special case {OriginalFormat} to populate body#3182

Merged
cijothomas merged 5 commits into
open-telemetry:mainfrom
cijothomas:cijothomas/otlplog_specialcaseoriginalformat
Apr 14, 2022
Merged

OTLP LogExporter to special case {OriginalFormat} to populate body#3182
cijothomas merged 5 commits into
open-telemetry:mainfrom
cijothomas:cijothomas/otlplog_specialcaseoriginalformat

Conversation

@cijothomas

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

codecov Bot commented Apr 14, 2022

Copy link
Copy Markdown

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%) ⬆️

@jviau jviau left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Comment thread src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md Outdated
Co-authored-by: Alan West <3676547+alanwest@users.noreply.github.com>

@alanwest alanwest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

* LogExporter to correctly map Severity to OTLP.
([#3177](https://github.com/open-telemetry/opentelemetry-dotnet/pull/3177))

* LogExporter to special case {OriginalFormat} to populate

Copy link
Copy Markdown
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

@reyang reyang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@CodeBlanch CodeBlanch left a comment

Copy link
Copy Markdown
Member

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