Skip to content

feat: Add new Emitter API to start and stop metrics #18

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

felixge
Copy link
Member

@felixge felixge commented Jun 25, 2025

No description provided.

felixge added 2 commits June 25, 2025 17:01
IDK where it was there to begin with. The [go module spec][1] says:

> The toolchain directive only has an effect when the module is the main
> module and the default toolchain’s version is less than the suggested
> toolchain’s version.

So removing this should not have any impact.

[1]: https://go.dev/ref/mod#go-mod-file-toolchain
This brings us inline with the minimal go version required by
dd-trace-go and also allows using `cmp.Or` which is introduced by a
later commit in this PR.
@felixge felixge marked this pull request as ready for review June 25, 2025 16:01
@felixge felixge requested a review from a team as a code owner June 25, 2025 16:01
logger *slog.Logger
baseTags []string
unknownMetricLogOnce *sync.Once
unsupportedKindLogOnce *sync.Once
}
Copy link
Member Author

Choose a reason for hiding this comment

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

todo: follow-up PR - refactor this into the Emitter type

@felixge felixge marked this pull request as draft June 25, 2025 16:07
@felixge felixge force-pushed the push-ltsptlnlnkpt branch from 1e843fb to 7914529 Compare June 28, 2025 09:51
@felixge felixge marked this pull request as ready for review June 28, 2025 09:51
@felixge felixge requested a review from Copilot June 28, 2025 15:33
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new Emitter API to start and stop the reporting of runtime metrics to a statsd client. Key changes include:

  • Refactoring runtime metrics reporting by replacing the global Start function with an Emitter type that provides explicit start/stop semantics.
  • Updating tests to exercise the new Emitter API and its idempotent Stop behavior.
  • Simplifying base tags handling and updating go.mod for a newer Go version.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/runtimemetrics/tags_test.go Updated tests to directly call getBaseTags inline with tag assertions.
pkg/runtimemetrics/tags.go Simplified getBaseTags by removing unnecessary mutex locking and global state.
pkg/runtimetrics/runtime_metrics_test.go Revised unit tests to leverage the new Emitter API and check for idempotence.
pkg/runtimemetrics/runtime_metrics.go Introduced Options and Emitter, refactored runtime metric store usage, and improved logging.
go.mod Updated the Go version and removed the explicit toolchain specification.
Comments suppressed due to low confidence (1)

pkg/runtimemetrics/runtime_metrics.go:44

  • [nitpick] Consider adding a comment to clarify the behavior and intent of using cmp.Or for selecting default values, to improve code clarity for future maintainers.
		logger: cmp.Or(opts.Logger, slog.Default()),

Comment on lines +81 to +86
tick := time.Tick(e.period)
for {
select {
case <-e.stop:
return
case <-tick:
Copy link
Preview

Copilot AI Jun 28, 2025

Choose a reason for hiding this comment

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

Consider replacing time.Tick with time.NewTicker to allow proper cleanup of the ticker when the emitter is stopped, thereby avoiding potential resource leaks.

Suggested change
tick := time.Tick(e.period)
for {
select {
case <-e.stop:
return
case <-tick:
ticker := time.NewTicker(e.period)
defer ticker.Stop()
for {
select {
case <-e.stop:
return
case <-ticker.C:

Copilot uses AI. Check for mistakes.

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.

1 participant