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

Convert Seq component to use OTEL's AddProcessor instead of AddOtlpExporter #3697

Merged
merged 17 commits into from
Apr 16, 2024

Conversation

liammclennan
Copy link
Contributor

@liammclennan liammclennan commented Apr 15, 2024

OpenTelemetry's AddOtlpExporter now throws an exception, so the Seq component is not working.

This PR switches to AddProcessor and adds some configuration work to compensate for AddProcessor not picking up .NET's OTEL configuration (as described by @CodeBlanch here). Adding OtlpExporterOptions onto Seq's configuration makes it possible to set the most vital options.

Changes due to #3546

Thank you to @CodeBlanch for showing the way forward!

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Apr 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 15, 2024
Comment on lines 31 to 35
public OtlpExporterOptions Logs
{
get;
private set;
} = new ();
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
public OtlpExporterOptions Logs
{
get;
private set;
} = new ();
public OtlpExporterOptions Logs { get; } = new();

No need for a private setter, it is never used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 40 to 45
public OtlpExporterOptions Traces
{
get;
private set;
} = new ();

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
public OtlpExporterOptions Traces
{
get;
private set;
} = new ();
public OtlpExporterOptions Traces { get; } = new();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

));

if (settings.HealthChecks)
if (settings is { HealthChecks: true, ServerUrl: not null })
Copy link
Member

Choose a reason for hiding this comment

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

Should it be an error if you haven't set ServerUrl? Seems odd that setting HealthChecks = true, but not getting health checks would be silent.

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 don't think it should be an error because a user could set Logs.EndPoint or Traces.EndPoint directly.

The combination of no ServerUrl and HealthChecks == true is never valid, so I will make that an error.

Comment on lines 35 to 39
settings.ServerUrl = builder.Configuration.GetConnectionString(connectionName);
settings.Logs.Protocol = OtlpExportProtocol.HttpProtobuf;
settings.Traces.Protocol = OtlpExportProtocol.HttpProtobuf;

builder.Configuration.GetSection("Aspire:Seq").Bind(settings);
Copy link
Member

Choose a reason for hiding this comment

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

The settings should continue to be bound to the configuration section before getting the connection string from connectionName. That is consistent with every other component. The order of precedence goes (lower number wins):

  1. User code (configureSettings) always wins
  2. ConnectionStrings w/ connection name
  3. Configuration section

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Done.

}
}
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddProcessor(
sp => new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))

Choose a reason for hiding this comment

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

@liammclennan If you want to respect ExportProcessorType make this...

        builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddProcessor(
            sp => settings.Logs.ExportProcessorType == ExportProcessorType.Batch
                ? new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
                : new SimpleLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
            ));

Similar for below in tracing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. I've made this change.

@JamesNK
Copy link
Member

JamesNK commented Apr 16, 2024

@reyang @davidfowl UseOtlpExporter seems to be causing problems when integrating with other OTEL APIs. Is this intended? Won't this make it more likely that libraries with OTEL configuration will throw errors when used in an Aspire app?

Comment on lines 60 to 62
_ => settings.Logs.ExportProcessorType == ExportProcessorType.Batch
? new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
: new SimpleLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
Copy link
Member

Choose a reason for hiding this comment

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

switch expressions are much cleaner here:

Suggested change
_ => settings.Logs.ExportProcessorType == ExportProcessorType.Batch
? new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
: new SimpleLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))
_ => settings.Logs.ExportProcessorType switch
ExportProcessorType.Batch => new BatchLogRecordExportProcessor(new OtlpLogExporter(settings.Logs)),
_ => new SimpleLogRecordExportProcessor(new OtlpLogExporter(settings.Logs))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @davidfowl

This change is done.

Comment on lines 31 to 34
public OtlpExporterOptions Logs
{
get;
} = new ();
Copy link
Member

@davidfowl davidfowl Apr 16, 2024

Choose a reason for hiding this comment

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

This formatting is very weird:

Suggested change
public OtlpExporterOptions Logs
{
get;
} = new ();
public OtlpExporterOptions Logs { get; } = new();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 39 to 43
public OtlpExporterOptions Traces
{
get;
} = new ();

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
public OtlpExporterOptions Traces
{
get;
} = new ();
public OtlpExporterOptions Traces { get; } = new();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix!

@eerhardt eerhardt merged commit e58ae7d into dotnet:main Apr 16, 2024
8 checks passed
@eerhardt
Copy link
Member

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8709142034

Copy link
Contributor

@eerhardt backporting to release/8.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.
Using index info to reconstruct a base tree...
M	playground/seq/Seq.AppHost/aspire-manifest.json
A	src/Components/Aspire.Seq/PublicAPI.Unshipped.txt
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/Components/Aspire.Seq/PublicAPI.Unshipped.txt deleted in HEAD and modified in Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.. Version Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`. of src/Components/Aspire.Seq/PublicAPI.Unshipped.txt left in tree.
Auto-merging playground/seq/Seq.AppHost/aspire-manifest.json
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@eerhardt an error occurred while backporting to release/8.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

eerhardt pushed a commit to eerhardt/aspire that referenced this pull request Apr 16, 2024
…pExporter` (dotnet#3697)

* Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.

* Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.

* Move OTLP exporter options onto SeqSettings.cs

* Add test

* Update README

* Renamed Seq settings

* Change order of config

* Updated code doc

* ConfigurationSchema.json

* Throw an exception if ServerUrl is unspecified, but HealthChecks is enabled.

* Fix tests

* PR feedback

Fix dotnet#3546
danmoseley pushed a commit that referenced this pull request Apr 17, 2024
…pExporter` (#3697) (#3728)

* Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.

* Switch Seq OpenTelemetry configuration from `AddOtlpExporter` to `AddProcessor`.

* Move OTLP exporter options onto SeqSettings.cs

* Add test

* Update README

* Renamed Seq settings

* Change order of config

* Updated code doc

* ConfigurationSchema.json

* Throw an exception if ServerUrl is unspecified, but HealthChecks is enabled.

* Fix tests

* PR feedback

Fix #3546

Co-authored-by: Liam McLennan <lmclennan@datalust.co>
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants