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

Add toString to SdkMeter, SdkObservableInstrument, AbstractInstrumentBuilder #5072

Merged
merged 1 commit into from
Jan 1, 2023

Conversation

jack-berg
Copy link
Member

Resolves #5013.

The sample code I posted here now prints:

io.opentelemetry.sdk.metrics.SdkMeterProvider: SdkMeterProvider{clock=SystemClock{}, resource=Resource{schemaUrl=null, attributes={service.name="unknown_service:java", telemetry.sdk.language="java", telemetry.sdk.name="opentelemetry", telemetry.sdk.version="1.22.0-SNAPSHOT"}}, metricReaders=[InMemoryMetricReader{aggregationTemporality=CUMULATIVE}], views=[]}
io.opentelemetry.sdk.metrics.SdkMeter: SdkMeter{instrumentationScopeInfo=InstrumentationScopeInfo{name=meter, version=null, schemaUrl=null, attributes={}}}
io.opentelemetry.sdk.metrics.SdkLongCounter$SdkLongCounterBuilder: SdkLongCounterBuilder{instrumentDescriptor=InstrumentDescriptor{name=counter, description=, unit=, type=COUNTER, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkLongCounter: SdkLongCounter{descriptor=InstrumentDescriptor{name=counter, description=, unit=, type=COUNTER, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=counter, description=, unit=, type=OBSERVABLE_COUNTER, valueType=LONG}]}}
io.opentelemetry.sdk.metrics.SdkDoubleCounter$SdkDoubleCounterBuilder: SdkDoubleCounterBuilder{instrumentDescriptor=InstrumentDescriptor{name=counter, description=, unit=, type=COUNTER, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkDoubleCounter: SdkDoubleCounter{descriptor=InstrumentDescriptor{name=counter, description=, unit=, type=COUNTER, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=counter, description=, unit=, type=OBSERVABLE_COUNTER, valueType=DOUBLE}]}}
io.opentelemetry.sdk.metrics.SdkLongUpDownCounter$SdkLongUpDownCounterBuilder: SdkLongUpDownCounterBuilder{instrumentDescriptor=InstrumentDescriptor{name=updowncounter, description=, unit=, type=UP_DOWN_COUNTER, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkLongUpDownCounter: SdkLongUpDownCounter{descriptor=InstrumentDescriptor{name=updowncounter, description=, unit=, type=UP_DOWN_COUNTER, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=updowncounter, description=, unit=, type=OBSERVABLE_UP_DOWN_COUNTER, valueType=LONG}]}}
io.opentelemetry.sdk.metrics.SdkDoubleUpDownCounter$SdkDoubleUpDownCounterBuilder: SdkDoubleUpDownCounterBuilder{instrumentDescriptor=InstrumentDescriptor{name=updowncounter, description=, unit=, type=UP_DOWN_COUNTER, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkDoubleUpDownCounter: SdkDoubleUpDownCounter{descriptor=InstrumentDescriptor{name=updowncounter, description=, unit=, type=UP_DOWN_COUNTER, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=updowncounter, description=, unit=, type=OBSERVABLE_UP_DOWN_COUNTER, valueType=LONG}]}}
io.opentelemetry.sdk.metrics.SdkDoubleHistogram$SdkDoubleHistogramBuilder: SdkDoubleHistogramBuilder{instrumentDescriptor=InstrumentDescriptor{name=histogram, description=, unit=, type=HISTOGRAM, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkDoubleHistogram: SdkDoubleHistogram{descriptor=InstrumentDescriptor{name=histogram, description=, unit=, type=HISTOGRAM, valueType=DOUBLE}}
io.opentelemetry.sdk.metrics.SdkLongHistogram$SdkLongHistogramBuilder: SdkLongHistogramBuilder{instrumentDescriptor=InstrumentDescriptor{name=histogram, description=, unit=, type=HISTOGRAM, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkLongHistogram: SdkLongHistogram{descriptor=InstrumentDescriptor{name=histogram, description=, unit=, type=HISTOGRAM, valueType=LONG}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=gauge, description=, unit=, type=OBSERVABLE_GAUGE, valueType=DOUBLE}]}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=gauge, description=, unit=, type=OBSERVABLE_GAUGE, valueType=LONG}]}}
io.opentelemetry.sdk.metrics.SdkObservableInstrument: SdkObservableInstrument{callback=CallbackRegistration{instrumentDescriptors=[InstrumentDescriptor{name=gauge, description=, unit=, type=OBSERVABLE_GAUGE, valueType=LONG}]}}

@jack-berg jack-berg requested a review from a team December 29, 2022 22:38
@@ -33,9 +35,13 @@
AbstractInstrumentBuilder(
Copy link
Member Author

Choose a reason for hiding this comment

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

The refactoring in this class ensures all descriptive fields required for a toString() implementation are available when constructed.

@@ -28,18 +27,20 @@ public final class CallbackRegistration {
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger);
private final List<SdkObservableMeasurement> observableMeasurements;
private final Runnable callback;
private final String callbackDescription;
Copy link
Member Author

Choose a reason for hiding this comment

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

This callbackDescription field was really a toString() implementation in disguise.


Builder(
SdkDoubleCounterBuilder(
Copy link
Member Author

Choose a reason for hiding this comment

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

Giving these builders more descriptive names gives AbstractInstrumentBuilder#toString() a useful classname to include.

@codecov
Copy link

codecov bot commented Dec 29, 2022

Codecov Report

Base: 91.07% // Head: 91.09% // Increases project coverage by +0.02% 🎉

Coverage data is based on head (e73c5b7) compared to base (19e2ce0).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5072      +/-   ##
============================================
+ Coverage     91.07%   91.09%   +0.02%     
- Complexity     4889     4891       +2     
============================================
  Files           553      553              
  Lines         14469    14453      -16     
  Branches       1381     1381              
============================================
- Hits          13177    13166      -11     
+ Misses          898      894       -4     
+ Partials        394      393       -1     
Impacted Files Coverage Δ
...lemetry/sdk/metrics/AbstractInstrumentBuilder.java 100.00% <100.00%> (ø)
...io/opentelemetry/sdk/metrics/SdkDoubleCounter.java 100.00% <100.00%> (ø)
...entelemetry/sdk/metrics/SdkDoubleGaugeBuilder.java 100.00% <100.00%> (ø)
.../opentelemetry/sdk/metrics/SdkDoubleHistogram.java 100.00% <100.00%> (ø)
...ntelemetry/sdk/metrics/SdkDoubleUpDownCounter.java 100.00% <100.00%> (ø)
...a/io/opentelemetry/sdk/metrics/SdkLongCounter.java 100.00% <100.00%> (ø)
...opentelemetry/sdk/metrics/SdkLongGaugeBuilder.java 100.00% <100.00%> (ø)
...io/opentelemetry/sdk/metrics/SdkLongHistogram.java 100.00% <100.00%> (ø)
...pentelemetry/sdk/metrics/SdkLongUpDownCounter.java 100.00% <100.00%> (ø)
...in/java/io/opentelemetry/sdk/metrics/SdkMeter.java 100.00% <100.00%> (ø)
... and 6 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

WriteableMetricStorage storage =
meterSharedState.registerSynchronousMetricStorage(descriptor, meterProviderSharedState);
return instrumentFactory.apply(descriptor, storage);
}

final CallbackRegistration registerDoubleAsynchronousInstrument(
final SdkObservableInstrument registerDoubleAsynchronousInstrument(
InstrumentType type, Consumer<ObservableDoubleMeasurement> updater) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't the type available now at the class level, and hence not needed to be passed in?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I think I see... for types that can be both observable and not, we need to be able to pass this in, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly. The type is assumed to be the synchronous version (i.e. COUNTER, UP_DOWN_COUNTER, etc) until a callback is regsitered.

@jack-berg jack-berg merged commit ad2013f into open-telemetry:main Jan 1, 2023
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.

api metrics missing toString implementation
2 participants