Skip to content
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

Global meter forwarding implementation #392

Merged
merged 15 commits into from
Dec 24, 2019

Conversation

jmacd
Copy link
Contributor

@jmacd jmacd commented Dec 19, 2019

Implements deferred initialization for metric instruments registered before the first Meter SDK is installed.

This implements the behavior specified in open-telemetry/oteps#45.
Resolves #388.

@jmacd jmacd added the area:metrics Part of OpenTelemetry Metrics label Dec 19, 2019
// If none is registered then an instance of metric.NoopProvider is returned.
// Use the trace provider to create a named meter. E.g.
// MeterProvider returns the registered global meter provider. If
// none is registered then a dewfault meter provider is returned that
Copy link
Contributor

Choose a reason for hiding this comment

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

typo:s/dewfault/default/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if current == mp {
// Setting the provider to the prior default
// is nonsense, set it to a noop.
mp = metric.NoopProvider{}
Copy link
Contributor

Choose a reason for hiding this comment

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

panic would be better than replacing it with NoopProvider{}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -71,13 +77,19 @@ const (
)

func (i *Instrument) AcquireHandle(labels apimetric.LabelSet) apimetric.HandleImpl {
if ld, ok := labels.(apimetric.LabelSetDelegate); ok {
labels = ld.Delegate()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This check should be done for sdk as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! This crossed my mind as I was walking out the office. Suggests more tests, too :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

mock.MeasurementBatches[2].Measurements[0].Number)
require.Equal(t, "test.measure",
mock.MeasurementBatches[2].Measurements[0].Instrument.Name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add test for multiple Meters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jmacd
Copy link
Contributor Author

jmacd commented Dec 23, 2019

FYI I discovered that named Tracers will need similar support as discussed in open-telemetry/oteps#74 but I will leave that out of this PR.

Copy link
Member

@paivagustavo paivagustavo left a comment

Choose a reason for hiding this comment

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

small grammars nits but LGTM

// provider. Mutexes in the Provider and Meters ensure that each
// instrument has a delegate before the global provider is set.
//
// LabelSets are implemented using the by delegating to the Meter
Copy link
Member

Choose a reason for hiding this comment

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

It seems that there is an extra using the here

LabelSets are implemented using the by delegating

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// LabelSets are implemented using the by delegating to the Meter
// instance using the metric.LabelSetDelegator interface.
//
// Bound instrument operations are implementing by delegating to the
Copy link
Member

Choose a reason for hiding this comment

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

Should be are implemented to be consistent with the LabelSets doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks!

@jmacd jmacd merged commit 1414d36 into open-telemetry:master Dec 24, 2019
@jmacd jmacd deleted the jmacd/global_meter branch December 24, 2019 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the global Meter useful for registering metric instruments before the SDK is initialized
3 participants