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 enable ParseStateValues by default #3186

Merged

Conversation

cijothomas
Copy link
Member

@cijothomas cijothomas requested a review from a team April 15, 2022 03:05
@codecov
Copy link

codecov bot commented Apr 15, 2022

Codecov Report

Merging #3186 (14e7fe0) into main (50baa25) will increase coverage by 0.57%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3186      +/-   ##
==========================================
+ Coverage   85.17%   85.75%   +0.57%     
==========================================
  Files         259      260       +1     
  Lines        9345     9358      +13     
==========================================
+ Hits         7960     8025      +65     
+ Misses       1385     1333      -52     
Impacted Files Coverage Δ
...ryProtocol.Logs/OtlpLogExporterHelperExtensions.cs 92.30% <100.00%> (ø)
.../OpenTelemetry/Logs/OpenTelemetryLoggerProvider.cs 94.11% <0.00%> (+11.76%) ⬆️
...etryProtocol/Implementation/LogRecordExtensions.cs 94.52% <0.00%> (+16.43%) ⬆️
....Exporter.OpenTelemetryProtocol/OtlpLogExporter.cs 70.00% <0.00%> (+70.00%) ⬆️
...ementation/ExportClient/OtlpGrpcLogExportClient.cs 78.57% <0.00%> (+78.57%) ⬆️
...penTelemetry/Logs/BatchLogRecordExportProcessor.cs 100.00% <0.00%> (+100.00%) ⬆️

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.

@cijothomas
Copy link
Member Author

@alanwest @CodeBlanch Please share your thoughts/comments. I think this is a reasonable way to proceed. (will do similar change for ConsoleExporter as well), by letting individual Exporters to make it easy for their users to configure ParseStateValues. If an Exporter wants to still do its own parsing of "State", its totally legal, as State was part of LogRecord, before StateValues.

@@ -42,7 +42,7 @@ private static OpenTelemetryLoggerOptions AddOtlpExporter(OpenTelemetryLoggerOpt
{
configure?.Invoke(exporterOptions);
var otlpExporter = new OtlpLogExporter(exporterOptions);

loggerOptions.ParseStateValues = true;
Copy link
Member

Choose a reason for hiding this comment

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

Might be useful to have a comment here explaining why it is being done?

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.

Feels a bit clunky but I don't have a better solution 😄

Should we add more to the comments here calling out that exporters may automatically enable ParseStateValues if they support the feature?

/// <summary>
/// Gets or sets a value indicating whether or not log state should be
/// parsed into <see cref="LogRecord.StateValues"/> on generated <see
/// cref="LogRecord"/>s. Default value: False.
/// </summary>
/// <remarks>
/// Note: When <see cref="ParseStateValues"/> is set to <see
/// langword="true"/> <see cref="LogRecord.State"/> will always be <see
/// langword="null"/>.
/// </remarks>

@alanwest
Copy link
Member

alanwest commented Apr 20, 2022

I agree feels a bit clunky for AddOltpExporter to have the side effect of changing an option - though I also agree that ParseStateValues=true seems like the most reasonable default.

Why not the proposal from this comment? Are we considering it inefficient because prevents state from being garbage collected? Or some other reason? #3183 (comment).

If we consider the default (ParseStateValues = false) as a bad default, we could change the default to make it true. To avoid breaking existing users, the SDK can continue to populate State as well. That way, exporters need to only deal with the parse state values, and if any exporters were previously relying on the State, they will be unaffected as well...


Another alternative may be to make the setting bool? ParseStateValues. Default is null - i.e., unspecified. Makes it clear that the actual default depends on the exporter you've configured. This is similar to what I did with PeriodicExportingMetricReaderOptions.

public class PeriodicExportingMetricReaderOptions
{
/// <summary>
/// Gets or sets the metric export interval in milliseconds.
/// If not set, the default value depends on the type of metric exporter
/// associated with the metric reader.
/// </summary>
public int? ExportIntervalMilliseconds { get; set; }

I guess this would be a breaking change for anyone who's written an extension that uses the LoggingOptions class... maybe ok?

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.

Approving, but curious of folks thoughts on questions I posed.

@CodeBlanch
Copy link
Member

@alanwest

If we consider the default (ParseStateValues = false) as a bad default, we could change the default to make it true. To avoid breaking existing users, the SDK can continue to populate State as well. That way, exporters need to only deal with the parse state values, and if any exporters were previously relying on the State, they will be unaffected as well...

I liked this too initially. But then looking at some code, for example:

https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/1fffa1e265019bf03a7d1361fe46c8c2fb88dbba/src/OpenTelemetry.Exporter.Geneva/GenevaLogExporter.cs#L201

If we switched the behavior so we always set state, anyone who has their ordering as "check state, then check StateValues" we might be breaking those exporters if we do that.

Another alternative may be to make the setting bool? ParseStateValues. Default is null - i.e., unspecified. Makes it clear that the actual default depends on the exporter you've configured.

I like that. Might still be breaking. We could [Obsolete] ParseStateValues and add bool DisableState { get; set; } maybe? If user sets DisableState = true we know they truly don't want anything. If DisableState = false we treat that as ParseStateValues = true today?

@alanwest
Copy link
Member

I like that. Might still be breaking. We could [Obsolete] ParseStateValues and add bool DisableState { get; set; } maybe? If user sets DisableState = true we know they truly don't want anything. If DisableState = false we treat that as ParseStateValues = true today?

Yea, you're right it would definitely be a breaking change. It kinda seems like someone would need to be doing something kinda funky to be affected by the change, but obviously that's not a good enough reason for a breaking change 😄.

I'm not opposed to this idea of adding Obsolete. Feels a little dirty, but it's certainly something we've considered in other contexts - like the OTLP batch activity processor options. I think it might be a bit cleaner than an unexpected side affect of calling AddOtlpExporter.

@cijothomas
Copy link
Member Author

Merging to continue fixing the rest of OTLP LogExporter issues.
The question of how to deal with state definitely is worth coming back to, once we have a fully working solution for end users.

@cijothomas cijothomas merged commit b4267c7 into open-telemetry:main Apr 21, 2022
@cijothomas cijothomas deleted the cijothomas/otlp_log_enableparsestate branch April 21, 2022 02:40
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.

4 participants