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

GenevaExporter - LogSerialization Fixes #295

Merged
merged 5 commits into from
Apr 14, 2022

Conversation

cijothomas
Copy link
Member

  1. Fixes an issue which dropped the LogRecord.State, when it is a KVP of size1

  2. Refactored LogExporter code a bit:
    LogExporter obtains the IReadOnlyList<KeyValuePair<string, object>> by either casting the State, or from the StateValues.
    Serializes each KVP to form Part C fields.
    Body is only populated if IncludeFormatMessage is true OR special casing {OriginalFormat} from Log extension methods.

As a result:
The below log statement, will result in empty body, as there is no formatter provided by the user, and Exporter will not attempt "ToString() on the state" to populate body.
logger.Log(LogLevel.Information, default, state: "somestringasdata", exception: null, formatter: null);

The below log statement will also result in empty body, if IncludeFormattedMessage = false, else uses the formatted message from user. Again, Exporter does not attempt any "ToString()" of the state.

logger.Log(LogLevel.Information, default, state: "somestringasdata", exception: null, formatter: (state, ex) => "Example formatted message.");

In short, Exporter no longer attempts to do "ToString() on state to populate body.".

  1. Tests are refactored. (could be further improved, coming in next PR), categorized into "Raw Log method", vs "using extension methods on Log (with message templating)."

4. Expecting slight perf boost (less if...else ladder), will run benchmarks and update numbers, before merging.
// * Summary *

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1586 (21H2)
Intel Core i7-4790 CPU 3.60GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.201
[Host] : .NET 6.0.3 (6.0.322.12309), X64 RyuJIT
DefaultJob : .NET 6.0.3 (6.0.322.12309), X64 RyuJIT

Main branch

Method Mean Error StdDev Gen 0 Allocated
LoggerWithGenevaExporter 1,100.1 ns 14.49 ns 12.85 ns 0.0610 256 B
SerializeLogRecord 797.9 ns 7.26 ns 6.43 ns 0.0057 24 B

with this PR

Method Mean Error StdDev Gen 0 Allocated
LoggerWithGenevaExporter 1,085.7 ns 14.71 ns 13.04 ns 0.0610 256 B
SerializeLogRecord 794.0 ns 7.82 ns 6.93 ns 0.0057 24 B

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.

@codecov
Copy link

codecov bot commented Apr 14, 2022

Codecov Report

Merging #295 (30d97bb) into main (3f965ae) will decrease coverage by 0.14%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #295      +/-   ##
==========================================
- Coverage   24.46%   24.32%   -0.15%     
==========================================
  Files         120      120              
  Lines        3687     3680       -7     
==========================================
- Hits          902      895       -7     
  Misses       2785     2785              
Impacted Files Coverage Δ
...OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs 90.00% <100.00%> (-0.38%) ⬇️

@utpilla
Copy link
Contributor

utpilla commented Apr 14, 2022

I think the CHANGELOG needs to be updated.

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

6 participants