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

GovukAppConfig silences OpenTelemetry log output when running a rake task #311

Merged
merged 1 commit into from Aug 21, 2023

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Jul 31, 2023

#307 removes OpenTelemetry initialisation in the console to avoid flooding the console with OpenTelemetry startup messages.

This PR adds the additional behaviour that when OpenTelemetry is configured (ie we are not on a console), we do a second check to see whether we're in a rake task and silence OpenTelemetry log messages so that Rake tasks with simple text output are not swamped with OpenTelemetry startup messages.

Since we're already assuming Rails.const_defined? is available, we use it to check for Rake, then call Rake.application.top_level tasks, which returns an empty array if running in rails, but a list of tasks if running through rake.

@theseanything
Copy link
Contributor

@KludgeKML ah sorry this had been a problem. So the telemetry can actually be usefully for Rake tasks, we can follow the requests paths of a rake task etc...

Happy to switch it off for now - but wondering if there's a nicer way just to silence this output.

@KludgeKML
Copy link
Contributor Author

@theseanything I don't know much about how OpenTelemetry is configured, do you know if there is a way to silence the startup output?

@robinjam
Copy link
Contributor

robinjam commented Aug 1, 2023

It looks like we could configure it not to log anything (perhaps only when invoked via a Rake task?)

OpenTelemetry::SDK.configure do |c|
  c.logger = Logger.new(File::NULL)
end

https://www.rubydoc.info/gems/opentelemetry-sdk/OpenTelemetry/SDK#configure-instance_method

@KludgeKML KludgeKML changed the title GovukAppConfig no longer automatically initialises OpenTelemetry when running a rake task GovukAppConfig silences OpenTelemetry log output when running a rake task Aug 17, 2023
@KludgeKML
Copy link
Contributor Author

@robinjam / @theseanything I've updated this PR to try James's suggestion, will try it on a branch of email-alert-api to confirm it works as expected, then if that goes okay I'll tag you both in as reviewers.

@KludgeKML
Copy link
Contributor Author

@theseanything Since you approved I've moved the changed code into lib/govuk_app_config/govuk_open_telemetry.rb instead of it being in the railtie (so that the OpenTelemetry::SDK config code is all in one block). That still okay?

@KludgeKML KludgeKML merged commit 4703501 into main Aug 21, 2023
5 checks passed
@KludgeKML KludgeKML deleted the no-open-telemetry-in-rake branch August 21, 2023 08:48
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.

None yet

3 participants