fix(otel): ensure OTEL sends final span when -o opt is used #6505
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this fix, when the -o/--output option was used the last OTEL span wouldn't be sent.
Fixing this surfaced some other issues and the code changes might look odd out of context so I'll try and explain the motivations below (also explained in the individual commit messages):
First commit
First off, the
Cli.run()
method would either return the results to the callee which would then do the clean up OR, if a certain combination of flags was passed, it would trigger a process exit itself (via theshutdown
function) and the cleanup logic in the callee would never run. This was one of the reasons for the OTEL bug.This meant that the behaviour of
Cli.run()
was pretty unpredictable and hard to track and the cleanup logic in the callee wasn't guaranteed to run. This was fixed in the first commit and now theCli.run()
method always returns the results in a consistent manner and cleanup is done by the callee.Second commit
After this change, it became obvious that the
exitOnAbort
flag didn't really do anything so it was removed in the second commit.Third commit
Finally, fixing the OTEL bug with the
Cli.run()
changes exposed another bug where callingotelSdk.shutdown()
would hang in those cases where an exporter hadn't been configured. This happens when the Garden class isn't initialised AND no OTEL exporter set via theOTEL_*
env var. For example when runninggarden help
. This was fixed by checking whether an exporter was set in the first place before callingotelSdk.shutdown()
. It's a little ugly but the other alternatives I explored didn't feel any better, it's kind of a function of how we use OTEL.What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #6482
Special notes for your reviewer: