Skip to content

cli-plugins/plugin: add OnFinalize hook 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

@jsternberg jsternberg commented Oct 23, 2026 •

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 using OnFinalize. 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 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli-plugins/plugin/plugin.go 0.00% 29 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 Outdated
Comment thread cli-plugins/plugin/plugin.go Outdated
Comment thread cli-plugins/plugin/plugin.go Outdated
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
@jsternberg
jsternberg force-pushed the trace-and-metrics-shutdown branch 2 times, most recently from 7f0dd35 to 81d4db6 Compare October 27, 2026 15:03
@jsternberg jsternberg changed the title cli-plugins/plugin: add PersistentPostRunE for shutting down otel providers cli-plugins/plugin: add OnFinalize hook for shutting down otel providers Oct 27, 2026
@jsternberg
jsternberg force-pushed the trace-and-metrics-shutdown branch from 81d4db6 to abdbe37 Compare October 27, 2026 15:25

@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
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 using `OnFinalize`. 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 abdbe37 to 29eb393 Compare October 27, 2026 17:36

@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: 🟢 APPROVE

Lower-confidence findings (not posted inline)

  • [low] cli-plugins/plugin/plugin.go:78 — cobra.OnFinalize registered unconditionally even when tcmd.Initialize fails (unverified; type assertions in the hook guard against uninitialized providers, so no crash occurs)

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