Skip to content

cli-plugins/plugin: add PersistentPostRunE for shutting down otel providers - #7433

Open
jsternberg wants to merge 1 commit into
docker:masterfrom
jsternberg:trace-and-metrics-shutdown
Open

jsternberg wants to merge 1 commit into
docker:masterfrom
jsternberg:trace-and-metrics-shutdown

Conversation

@jsternberg

Copy link
Copy Markdown
Contributor

OTEL providers provided by this library to plugins were not properly
shut down. Metrics from the CLI were forcibly flushed in a separate area
and the buildx command does its own flushing, but this didn't apply to
traces.

Add shutdown on post run for plugins. This will allow compose to use the
tracer provider from this library rather than roll its own custom one.

@codecov-commenter

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli-plugins/plugin/plugin.go 0.00% 25 Missing ⚠️
cli/command/telemetry.go 0.00% 1 Missing ⚠️
cli/command/telemetry_docker.go 0.00% 1 Missing ⚠️
cli/command/telemetry_utils.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟡 NEEDS ATTENTION

Comment thread cli-plugins/plugin/plugin.go
Comment thread cli-plugins/plugin/plugin.go
Comment on lines +83 to +84
PersistentPostRunE = func(cmd *cobra.Command, _ []string) error {
persistentPostRunOnce.Do(func() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will only run for commands that succeed - is this what we want here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it's not. Why would this not run if the command fails? Do we call os.Exit? I don't see anything in the documentation that mentions the post run doesn't when the command fails.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks they really should fix the documentation on that to point this out. I guess PersistentPostRunE is just wrong then for this. I'll try to see where else it can go.

Comment thread cli-plugins/plugin/plugin.go Outdated
}
})
}
wg.Wait()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do these Shutdown methods have a guarantee to finish in the given timeout?

If not, perhaps we should run this in a goroutine which we would only wait for the ExportTimeout and if they dont manage to return in that time, just continue with shutdown

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think so but I'll just add an additional bit of time and do this just in case the Shutdown methods aren't cooperating for some reason.

@thaJeztah thaJeztah added this to the 29.10.0 milestone Oct 26, 2026
@jsternberg
jsternberg force-pushed the trace-and-metrics-shutdown branch 2 times, most recently from af5268d to 2927abc Compare October 26, 2026 19:37
Comment thread cli-plugins/plugin/plugin.go Outdated
…viders

OTEL providers provided by this library to plugins were not properly
shut down. Metrics from the CLI were forcibly flushed in a separate area
and the `buildx` command does its own flushing, but this didn't apply to
traces.

Add shutdown on post run for plugins. This will allow compose to use the
tracer provider from this library rather than roll its own custom one.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
@jsternberg
jsternberg force-pushed the trace-and-metrics-shutdown branch from 2927abc to 7f0dd35 Compare October 26, 2026 20:23
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.

5 participants