Skip to content

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

Merged
thaJeztah merged 1 commit into
docker:masterfrom
jsternberg:trace-and-metrics-shutdown
Nov 5, 2026
Merged

thaJeztah merged 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 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli-plugins/plugin/plugin.go 0.00% 28 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 Resolved
Comment thread cli-plugins/plugin/plugin.go Resolved
Comment thread cli-plugins/plugin/plugin.go Resolved
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 Resolved
@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 Resolved
@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)

vvoland
vvoland previously approved these changes Nov 4, 2026

@vvoland vvoland left a comment

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.

LGTM with one nit:

Comment thread cli-plugins/plugin/plugin.go Resolved
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 <jonathan.sternberg@docker.com>

@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

@vvoland vvoland left a comment

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.

LGTM

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
thaJeztah merged commit dd422f4 into docker:master Nov 5, 2026
108 checks passed
@jsternberg
jsternberg deleted the trace-and-metrics-shutdown branch November 5, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants