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

Exposed public setters for LogRecord.State, LogRecord.StateValues, and LogRecord.FormattedMessage. #3217

Merged
merged 6 commits into from
Apr 22, 2022

Conversation

Yun-Ting
Copy link
Contributor

@Yun-Ting Yun-Ting commented Apr 21, 2022

Fixes #2877.

For significant contributions please make sure you have completed the following items:

  • Appropriate CHANGELOG.md updated for non-trivial changes
  • Design discussion issue #
  • Changes in public API reviewed

@Yun-Ting Yun-Ting requested a review from a team April 21, 2022 18:52
internal class MyClassWithRedactionEnumerator : IReadOnlyList<KeyValuePair<string, object>>
{
private static readonly Regex Rgx = new("\\(?\\d{3}[\\.|\\)]?\\d{3}[\\.|\\-]\\d{4}");
private readonly IReadOnlyList<KeyValuePair<string, object>> myList;
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
private readonly IReadOnlyList<KeyValuePair<string, object>> myList;
private readonly IReadOnlyList<KeyValuePair<string, object>> traits;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated name of the private field to be state.
Not sure which one is better, trait or state; but both of them definitely are better than myList 🤓.

return this.GetEnumerator();
}

public override string ToString()
Copy link
Member

Choose a reason for hiding this comment

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

do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll need this for the compiler:

IEnumerator IEnumerable.GetEnumerator()
{
    return this.GetEnumerator();
}

Screenshot (4)

Copy link
Member

Choose a reason for hiding this comment

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

The comment is about ToString() override. Enumeration is needed.

Copy link
Contributor Author

@Yun-Ting Yun-Ting Apr 21, 2022

Choose a reason for hiding this comment

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

Interesting - my browser is showing me code highlight as this:
image


internal class MyClassWithRedactionEnumerator : IReadOnlyList<KeyValuePair<string, object>>
{
private static readonly Regex Rgx = new("\\(?\\d{3}[\\.|\\)]?\\d{3}[\\.|\\-]\\d{4}");
Copy link
Member

Choose a reason for hiding this comment

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

for this tutorial, i dont think we need to show actual regex! its upto end user to make their own.. we can do simple match like value.Contains("secret"), as it is sufficient to demonstrate the approach.

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member

@reyang reyang Apr 21, 2022

Choose a reason for hiding this comment

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

Or if the class is renamed to "PhoneNumberRedactionSomething" it sounds reasonable.

@Yun-Ting Yun-Ting changed the title Add setters for State, StateValues, and FormattedMessage fields for LogRecord. Exposed public setters for LogRecord.State, LogRecord.StateValues, and LogRecord.FormattedMessage. Apr 22, 2022
@codecov
Copy link

codecov bot commented Apr 22, 2022

Codecov Report

Merging #3217 (ad09158) into main (ad2969d) will increase coverage by 0.22%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3217      +/-   ##
==========================================
+ Coverage   85.47%   85.70%   +0.22%     
==========================================
  Files         260      260              
  Lines        9366     9366              
==========================================
+ Hits         8006     8027      +21     
+ Misses       1360     1339      -21     
Impacted Files Coverage Δ
src/OpenTelemetry/Logs/LogRecord.cs 96.92% <100.00%> (ø)
...metryProtocol/Implementation/ActivityExtensions.cs 91.44% <0.00%> (+2.70%) ⬆️
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 77.27% <0.00%> (+40.90%) ⬆️
...entation/ExportClient/OtlpGrpcTraceExportClient.cs 78.57% <0.00%> (+42.85%) ⬆️

{
public override void OnEnd(LogRecord logRecord)
{
if (logRecord.State is IReadOnlyList<KeyValuePair<string, object>> listOfKvp)
Copy link
Member

Choose a reason for hiding this comment

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

just for completion, we could show how to use same approach for logRecord.StateValues as well. (not a blocker for this PR)

@@ -64,6 +65,9 @@ public static void Main()
{
logger.LogError("{name} is broken.", "refrigerator");
}

// message will be redacted by MyRedactionProcessor
logger.LogInformation("OpenTelemetry {sensitiveString}.", "<secret>");
Copy link
Member

Choose a reason for hiding this comment

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

also it'd be good to modify the readme.md for the extending-the-sdk to include the redaction part. Similar to this https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/docs/trace/extending-the-sdk#filtering-processor

@cijothomas
Copy link
Member

Merging. Couple of non-blocking doc improvements suggested.

@cijothomas cijothomas merged commit 11699a3 into open-telemetry:main Apr 22, 2022
@Yun-Ting Yun-Ting deleted the yunl/logRecordSetter2 branch June 2, 2022 17:42
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.

Make some fields in LogRecord mutable for consistency with Activity.
3 participants