From 0d8c83e15df769e1f4e135ea830315c6a86a4808 Mon Sep 17 00:00:00 2001 From: Bogdan Cristian Drutu Date: Thu, 20 Feb 2020 12:51:56 -0800 Subject: [PATCH] Add a MeterSharedState class that includes the InstrumentationLibraryInfo Signed-off-by: Bogdan Cristian Drutu --- .../sdk/internal/ComponentRegistry.java | 2 +- .../sdk/metrics/AbstractCounter.java | 15 +++-- .../sdk/metrics/AbstractInstrument.java | 21 ++++--- .../AbstractInstrumentWithBinding.java | 5 +- .../sdk/metrics/AbstractMeasure.java | 14 ++--- .../sdk/metrics/AbstractObserver.java | 15 ++--- .../sdk/metrics/DoubleCounterSdk.java | 15 +++-- .../sdk/metrics/DoubleMeasureSdk.java | 15 +++-- .../sdk/metrics/DoubleObserverSdk.java | 15 +++-- .../sdk/metrics/LongCounterSdk.java | 15 +++-- .../sdk/metrics/LongMeasureSdk.java | 19 +++--- .../sdk/metrics/LongObserverSdk.java | 15 +++-- .../opentelemetry/sdk/metrics/MeterSdk.java | 18 +++--- .../sdk/metrics/MeterSharedState.java | 31 ++++++++++ .../metrics/AbstractCounterBuilderTest.java | 28 ++++----- .../sdk/metrics/AbstractCounterTest.java | 8 +-- .../AbstractInstrumentBuilderTest.java | 59 +++++++++---------- .../sdk/metrics/AbstractInstrumentTest.java | 21 ++++--- .../metrics/AbstractMeasureBuilderTest.java | 30 +++++----- .../sdk/metrics/AbstractMeasureTest.java | 8 +-- .../metrics/AbstractObserverBuilderTest.java | 30 +++++----- .../sdk/metrics/AbstractObserverTest.java | 8 +-- .../sdk/metrics/MeterSdkRegistryTest.java | 2 +- 23 files changed, 204 insertions(+), 205 deletions(-) create mode 100644 sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSharedState.java diff --git a/sdk/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java b/sdk/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java index e87f6d60c55..9096d149567 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/internal/ComponentRegistry.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; /** - * Base class for all the registry classes (Tracer, Meter, etc.). + * Base class for all the provider classes (TracerProvider, MeterProvider, etc.). * * @param the type of the registered value. */ diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractCounter.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractCounter.java index bab24e5b426..e3dad5c556a 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractCounter.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractCounter.java @@ -17,7 +17,6 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.Counter; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.common.InstrumentType; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor; @@ -33,19 +32,19 @@ abstract class AbstractCounter InstrumentDescriptor descriptor, InstrumentValueType instrumentValueType, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, new ActiveBatcher( getDefaultBatcher( descriptor, getCounterInstrumentType(monotonic), instrumentValueType, meterProviderSharedState, - instrumentationLibraryInfo))); + meterSharedState))); this.monotonic = monotonic; this.instrumentValueType = instrumentValueType; } @@ -86,8 +85,8 @@ abstract static class Builder, V> Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -110,13 +109,13 @@ private static Batcher getDefaultBatcher( InstrumentType instrumentType, InstrumentValueType instrumentValueType, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { + MeterSharedState meterSharedState) { Aggregation defaultAggregation = Aggregations.sum(); return Batchers.getCumulativeAllLabels( getDefaultMetricDescriptor( descriptor, instrumentType, instrumentValueType, defaultAggregation), meterProviderSharedState.getResource(), - instrumentationLibraryInfo, + meterSharedState.getInstrumentationLibraryInfo(), defaultAggregation.getAggregatorFactory(instrumentValueType), meterProviderSharedState.getClock()); } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrument.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrument.java index 5f43b20a9bd..97f1d3ad6c0 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrument.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrument.java @@ -19,7 +19,6 @@ import io.opentelemetry.internal.StringUtils; import io.opentelemetry.internal.Utils; import io.opentelemetry.metrics.Instrument; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.data.MetricData; import java.util.ArrayList; import java.util.Collections; @@ -31,18 +30,18 @@ abstract class AbstractInstrument implements Instrument { private final InstrumentDescriptor descriptor; private final MeterProviderSharedState meterProviderSharedState; - private final InstrumentationLibraryInfo instrumentationLibraryInfo; + private final MeterSharedState meterSharedState; private final ActiveBatcher activeBatcher; // All arguments cannot be null because they are checked in the abstract builder classes. AbstractInstrument( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, ActiveBatcher activeBatcher) { this.descriptor = descriptor; this.meterProviderSharedState = meterProviderSharedState; - this.instrumentationLibraryInfo = instrumentationLibraryInfo; + this.meterSharedState = meterSharedState; this.activeBatcher = activeBatcher; } @@ -54,8 +53,8 @@ final MeterProviderSharedState getMeterProviderSharedState() { return meterProviderSharedState; } - final InstrumentationLibraryInfo getInstrumentationLibraryInfo() { - return instrumentationLibraryInfo; + final MeterSharedState getMeterSharedState() { + return meterSharedState; } final ActiveBatcher getActiveBatcher() { @@ -93,7 +92,7 @@ abstract static class Builder, V> private final String name; private final MeterProviderSharedState meterProviderSharedState; - private final InstrumentationLibraryInfo instrumentationLibraryInfo; + private final MeterSharedState meterSharedState; private String description = ""; private String unit = "1"; private List labelKeys = Collections.emptyList(); @@ -102,14 +101,14 @@ abstract static class Builder, V> Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { + MeterSharedState meterSharedState) { Utils.checkNotNull(name, "name"); Utils.checkArgument( StringUtils.isValidMetricName(name) && name.length() <= NAME_MAX_LENGTH, ERROR_MESSAGE_INVALID_NAME); this.name = name; this.meterProviderSharedState = meterProviderSharedState; - this.instrumentationLibraryInfo = instrumentationLibraryInfo; + this.meterSharedState = meterSharedState; } @Override @@ -143,8 +142,8 @@ final MeterProviderSharedState getMeterProviderSharedState() { return meterProviderSharedState; } - final InstrumentationLibraryInfo getInstrumentationLibraryInfo() { - return instrumentationLibraryInfo; + final MeterSharedState getMeterSharedState() { + return meterSharedState; } final InstrumentDescriptor getInstrumentDescriptor() { diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrumentWithBinding.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrumentWithBinding.java index b1dce983df7..8051b0a28b6 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrumentWithBinding.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractInstrumentWithBinding.java @@ -17,7 +17,6 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.LabelSet; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.data.MetricData; import java.util.List; import java.util.Map; @@ -32,9 +31,9 @@ abstract class AbstractInstrumentWithBinding AbstractInstrumentWithBinding( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, ActiveBatcher activeBatcher) { - super(descriptor, meterProviderSharedState, instrumentationLibraryInfo, activeBatcher); + super(descriptor, meterProviderSharedState, meterSharedState, activeBatcher); boundLabels = new ConcurrentHashMap<>(); collectLock = new ReentrantLock(); } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractMeasure.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractMeasure.java index 138b01c0308..b6db051ff89 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractMeasure.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractMeasure.java @@ -17,8 +17,6 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.Measure; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; -import io.opentelemetry.sdk.metrics.common.InstrumentType; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; abstract class AbstractMeasure @@ -30,12 +28,12 @@ abstract class AbstractMeasure InstrumentDescriptor descriptor, InstrumentValueType instrumentValueType, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean absolute) { super( descriptor, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, new ActiveBatcher(Batchers.getNoop())); this.absolute = absolute; this.instrumentValueType = instrumentValueType; @@ -77,8 +75,8 @@ abstract static class Builder, V> Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -91,8 +89,4 @@ final boolean isAbsolute() { return this.absolute; } } - - static InstrumentType getInstrumentType(boolean absolute) { - return absolute ? InstrumentType.MEASURE_ABSOLUTE : InstrumentType.MEASURE_NON_ABSOLUTE; - } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractObserver.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractObserver.java index 0c0dcaf25a4..df660fa99cb 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractObserver.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/AbstractObserver.java @@ -17,8 +17,6 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.Observer; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; -import io.opentelemetry.sdk.metrics.common.InstrumentType; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; import io.opentelemetry.sdk.metrics.data.MetricData; import java.util.Collections; @@ -32,12 +30,12 @@ class AbstractObserver extends AbstractInstrument { InstrumentDescriptor descriptor, InstrumentValueType instrumentValueType, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, new ActiveBatcher(Batchers.getNoop())); this.monotonic = monotonic; this.instrumentValueType = instrumentValueType; @@ -85,8 +83,8 @@ abstract static class Builder, V> Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -99,9 +97,4 @@ final boolean isMonotonic() { return this.monotonic; } } - - // TODO: make this private - static InstrumentType getInstrumentType(boolean monotonic) { - return monotonic ? InstrumentType.OBSERVER_MONOTONIC : InstrumentType.OBSERVER_NON_MONOTONIC; - } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java index 1148de2e401..c18194da59f 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java @@ -18,7 +18,6 @@ import io.opentelemetry.metrics.DoubleCounter; import io.opentelemetry.metrics.LabelSet; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.DoubleCounterSdk.BoundInstrument; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; @@ -28,12 +27,12 @@ private DoubleCounterSdk( InstrumentDescriptor descriptor, boolean monotonic, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { + MeterSharedState meterSharedState) { super( descriptor, InstrumentValueType.DOUBLE, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, monotonic); } @@ -75,8 +74,8 @@ public void add(double delta) { static DoubleCounter.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -86,8 +85,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -101,7 +100,7 @@ public DoubleCounter build() { getInstrumentDescriptor(), isMonotonic(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo()); + getMeterSharedState()); } } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java index 7cdb7493938..7268a360e54 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java @@ -18,7 +18,6 @@ import io.opentelemetry.metrics.DoubleMeasure; import io.opentelemetry.metrics.LabelSet; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.DoubleMeasureSdk.BoundInstrument; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; @@ -27,13 +26,13 @@ final class DoubleMeasureSdk extends AbstractMeasure implements private DoubleMeasureSdk( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean absolute) { super( descriptor, InstrumentValueType.DOUBLE, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, absolute); } @@ -75,8 +74,8 @@ public void record(double value) { static DoubleMeasure.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -86,8 +85,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -100,7 +99,7 @@ public DoubleMeasure build() { return new DoubleMeasureSdk( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isAbsolute()); } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java index aac9b63cc27..6630cb3f30a 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java @@ -17,20 +17,19 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.DoubleObserver; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; final class DoubleObserverSdk extends AbstractObserver implements DoubleObserver { DoubleObserverSdk( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, InstrumentValueType.LONG, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, monotonic); } @@ -42,8 +41,8 @@ public void setCallback(Callback metricUpda static DoubleObserver.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -53,8 +52,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -67,7 +66,7 @@ public DoubleObserver build() { return new DoubleObserverSdk( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isMonotonic()); } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java index 52d5edd5fc4..bbbdc1fab43 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java @@ -18,7 +18,6 @@ import io.opentelemetry.metrics.LabelSet; import io.opentelemetry.metrics.LongCounter; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.LongCounterSdk.BoundInstrument; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; @@ -27,13 +26,13 @@ final class LongCounterSdk extends AbstractCounter implements L private LongCounterSdk( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, InstrumentValueType.LONG, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, monotonic); } @@ -75,8 +74,8 @@ public void add(long delta) { static LongCounter.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -86,8 +85,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -100,7 +99,7 @@ public LongCounter build() { return new LongCounterSdk( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isMonotonic()); } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java index 36fbfa55a02..720beb624ce 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java @@ -18,7 +18,6 @@ import io.opentelemetry.metrics.LabelSet; import io.opentelemetry.metrics.LongMeasure; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.LongMeasureSdk.BoundInstrument; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; @@ -27,14 +26,10 @@ final class LongMeasureSdk extends AbstractMeasure implements L private LongMeasureSdk( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean absolute) { super( - descriptor, - InstrumentValueType.LONG, - meterProviderSharedState, - instrumentationLibraryInfo, - absolute); + descriptor, InstrumentValueType.LONG, meterProviderSharedState, meterSharedState, absolute); } @Override @@ -76,8 +71,8 @@ public void record(long value) { static LongMeasure.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -87,8 +82,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -101,7 +96,7 @@ public LongMeasure build() { return new LongMeasureSdk( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isAbsolute()); } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java index 671433f1a9c..731a3e53807 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java @@ -17,20 +17,19 @@ package io.opentelemetry.sdk.metrics; import io.opentelemetry.metrics.LongObserver; -import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; import io.opentelemetry.sdk.metrics.common.InstrumentValueType; final class LongObserverSdk extends AbstractObserver implements LongObserver { LongObserverSdk( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, InstrumentValueType.LONG, meterProviderSharedState, - instrumentationLibraryInfo, + meterSharedState, monotonic); } @@ -42,8 +41,8 @@ public void setCallback(Callback metricUpdater) static LongObserver.Builder builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - return new Builder(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + return new Builder(name, meterProviderSharedState, meterSharedState); } private static final class Builder @@ -53,8 +52,8 @@ private static final class Builder private Builder( String name, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, meterProviderSharedState, instrumentationLibraryInfo); + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -67,7 +66,7 @@ public LongObserver build() { return new LongObserverSdk( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isMonotonic()); } } diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java index 34ef5de088c..c53ad9e5a6f 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSdk.java @@ -31,47 +31,47 @@ /** {@link MeterSdk} is SDK implementation of {@link Meter}. */ final class MeterSdk implements Meter { private final MeterProviderSharedState meterProviderSharedState; - private final InstrumentationLibraryInfo instrumentationLibraryInfo; + private final MeterSharedState meterSharedState; MeterSdk( MeterProviderSharedState meterProviderSharedState, InstrumentationLibraryInfo instrumentationLibraryInfo) { this.meterProviderSharedState = meterProviderSharedState; - this.instrumentationLibraryInfo = instrumentationLibraryInfo; + this.meterSharedState = MeterSharedState.create(instrumentationLibraryInfo); } InstrumentationLibraryInfo getInstrumentationLibraryInfo() { - return instrumentationLibraryInfo; + return meterSharedState.getInstrumentationLibraryInfo(); } @Override public DoubleCounter.Builder doubleCounterBuilder(String name) { - return DoubleCounterSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return DoubleCounterSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override public LongCounter.Builder longCounterBuilder(String name) { - return LongCounterSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return LongCounterSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override public DoubleMeasure.Builder doubleMeasureBuilder(String name) { - return DoubleMeasureSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return DoubleMeasureSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override public LongMeasure.Builder longMeasureBuilder(String name) { - return LongMeasureSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return LongMeasureSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override public DoubleObserver.Builder doubleObserverBuilder(String name) { - return DoubleObserverSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return DoubleObserverSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override public LongObserver.Builder longObserverBuilder(String name) { - return LongObserverSdk.builder(name, meterProviderSharedState, instrumentationLibraryInfo); + return LongObserverSdk.builder(name, meterProviderSharedState, meterSharedState); } @Override diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSharedState.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSharedState.java new file mode 100644 index 00000000000..c4b55b9c052 --- /dev/null +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/MeterSharedState.java @@ -0,0 +1,31 @@ +/* + * Copyright 2020, OpenTelemetry Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.opentelemetry.sdk.metrics; + +import com.google.auto.value.AutoValue; +import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; +import javax.annotation.concurrent.Immutable; + +@AutoValue +@Immutable +abstract class MeterSharedState { + static MeterSharedState create(InstrumentationLibraryInfo instrumentationLibraryInfo) { + return new AutoValue_MeterSharedState(instrumentationLibraryInfo); + } + + abstract InstrumentationLibraryInfo getInstrumentationLibraryInfo(); +} diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractCounterBuilderTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractCounterBuilderTest.java index 41268071369..4d27a4cf845 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractCounterBuilderTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractCounterBuilderTest.java @@ -38,19 +38,19 @@ public class AbstractCounterBuilderTest { @Rule public ExpectedException thrown = ExpectedException.none(); private static final String NAME = "name"; - private static final MeterProviderSharedState METER_SHARED_STATE = + private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE = MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty()); - private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO = - InstrumentationLibraryInfo.getEmpty(); + private static final MeterSharedState METER_SHARED_STATE = + MeterSharedState.create(InstrumentationLibraryInfo.getEmpty()); @Test public void defaultValue() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); assertThat(testInstrumentBuilder.isMonotonic()).isTrue(); - assertThat(testInstrumentBuilder.getMeterProviderSharedState()).isEqualTo(METER_SHARED_STATE); - assertThat(testInstrumentBuilder.getInstrumentationLibraryInfo()) - .isEqualTo(INSTRUMENTATION_LIBRARY_INFO); + assertThat(testInstrumentBuilder.getMeterProviderSharedState()) + .isSameInstanceAs(METER_PROVIDER_SHARED_STATE); + assertThat(testInstrumentBuilder.getMeterSharedState()).isSameInstanceAs(METER_SHARED_STATE); TestInstrument testInstrument = testInstrumentBuilder.build(); assertThat(testInstrument).isInstanceOf(TestInstrument.class); @@ -64,7 +64,7 @@ public void defaultValue() { @Test public void setAndGetValues() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setMonotonic(false); assertThat(testInstrumentBuilder.isMonotonic()).isFalse(); assertThat(testInstrumentBuilder.build()).isInstanceOf(TestInstrument.class); @@ -74,9 +74,9 @@ private static final class TestInstrumentBuilder extends AbstractCounter.Builder { TestInstrumentBuilder( String name, - MeterProviderSharedState sharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, sharedState, instrumentationLibraryInfo); + MeterProviderSharedState meterProviderSharedState, + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -89,7 +89,7 @@ public TestInstrument build() { return new TestInstrument( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isMonotonic()); } } @@ -99,13 +99,13 @@ private static final class TestInstrument extends AbstractCounter LABEL_KEY = Collections.singletonList("key"); private static final Map CONSTANT_LABELS = Collections.singletonMap("key_2", "value_2"); - private static final MeterProviderSharedState METER_SHARED_STATE = + private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE = MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty()); - private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO = - InstrumentationLibraryInfo.getEmpty(); + private static final MeterSharedState METER_SHARED_STATE = + MeterSharedState.create(InstrumentationLibraryInfo.getEmpty()); @Test public void preventNull_Name() { thrown.expect(NullPointerException.class); thrown.expectMessage("name"); - new TestInstrumentBuilder(null, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO).build(); + new TestInstrumentBuilder(null, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE).build(); } @Test public void preventEmpty_Name() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Name"); - new TestInstrumentBuilder("", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder("", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); } @Test public void checkCorrect_Name() { - new TestInstrumentBuilder("a", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); - new TestInstrumentBuilder("METRIC_name", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); - new TestInstrumentBuilder("metric.name_01", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); - new TestInstrumentBuilder("metric_name.01", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder("a", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); + new TestInstrumentBuilder("METRIC_name", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); + new TestInstrumentBuilder("metric.name_01", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); + new TestInstrumentBuilder("metric_name.01", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Name"); - new TestInstrumentBuilder( - "01.metric_name_01", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder("01.metric_name_01", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); } @Test public void preventNonPrintableName() { thrown.expect(IllegalArgumentException.class); - new TestInstrumentBuilder("\2", METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO).build(); + new TestInstrumentBuilder("\2", METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE).build(); } @Test @@ -87,14 +86,14 @@ public void preventTooLongName() { String longName = String.valueOf(chars); thrown.expect(IllegalArgumentException.class); thrown.expectMessage(AbstractInstrument.Builder.ERROR_MESSAGE_INVALID_NAME); - new TestInstrumentBuilder(longName, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO).build(); + new TestInstrumentBuilder(longName, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE).build(); } @Test public void preventNull_Description() { thrown.expect(NullPointerException.class); thrown.expectMessage("description"); - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setDescription(null) .build(); } @@ -103,7 +102,7 @@ public void preventNull_Description() { public void preventNull_Unit() { thrown.expect(NullPointerException.class); thrown.expectMessage("unit"); - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setUnit(null) .build(); } @@ -112,7 +111,7 @@ public void preventNull_Unit() { public void preventNull_LabelKeys() { thrown.expect(NullPointerException.class); thrown.expectMessage("labelKeys"); - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setLabelKeys(null) .build(); } @@ -121,7 +120,7 @@ public void preventNull_LabelKeys() { public void preventNull_LabelKey() { thrown.expect(NullPointerException.class); thrown.expectMessage("labelKey"); - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setLabelKeys(Collections.singletonList(null)) .build(); } @@ -130,7 +129,7 @@ public void preventNull_LabelKey() { public void preventNull_ConstantLabels() { thrown.expect(NullPointerException.class); thrown.expectMessage("constantLabels"); - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setConstantLabels(null) .build(); } @@ -138,7 +137,7 @@ public void preventNull_ConstantLabels() { @Test public void defaultValue() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); TestInstrument testInstrument = testInstrumentBuilder.build(); assertThat(testInstrument).isInstanceOf(TestInstrument.class); assertThat(testInstrument.getDescriptor().getName()).isEqualTo(NAME); @@ -151,14 +150,14 @@ public void defaultValue() { @Test public void setAndGetValues() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setDescription(DESCRIPTION) .setUnit(UNIT) .setLabelKeys(LABEL_KEY) .setConstantLabels(CONSTANT_LABELS); - assertThat(testInstrumentBuilder.getMeterProviderSharedState()).isEqualTo(METER_SHARED_STATE); - assertThat(testInstrumentBuilder.getInstrumentationLibraryInfo()) - .isEqualTo(INSTRUMENTATION_LIBRARY_INFO); + assertThat(testInstrumentBuilder.getMeterProviderSharedState()) + .isSameInstanceAs(METER_PROVIDER_SHARED_STATE); + assertThat(testInstrumentBuilder.getMeterSharedState()).isSameInstanceAs(METER_SHARED_STATE); TestInstrument testInstrument = testInstrumentBuilder.build(); assertThat(testInstrument).isInstanceOf(TestInstrument.class); @@ -172,10 +171,8 @@ public void setAndGetValues() { private static final class TestInstrumentBuilder extends AbstractInstrument.Builder { TestInstrumentBuilder( - String name, - MeterProviderSharedState sharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, sharedState, instrumentationLibraryInfo); + String name, MeterProviderSharedState sharedState, MeterSharedState meterSharedState) { + super(name, sharedState, meterSharedState); } @Override @@ -186,9 +183,7 @@ TestInstrumentBuilder getThis() { @Override public TestInstrument build() { return new TestInstrument( - getInstrumentDescriptor(), - getMeterProviderSharedState(), - getInstrumentationLibraryInfo()); + getInstrumentDescriptor(), getMeterProviderSharedState(), getMeterSharedState()); } } @@ -196,8 +191,8 @@ private static final class TestInstrument extends AbstractInstrument { TestInstrument( InstrumentDescriptor descriptor, MeterProviderSharedState meterProviderSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(descriptor, meterProviderSharedState, instrumentationLibraryInfo, null); + MeterSharedState meterSharedState) { + super(descriptor, meterProviderSharedState, meterSharedState, null); } @Override diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractInstrumentTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractInstrumentTest.java index 29fb56debba..5ee3242ce8c 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractInstrumentTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractInstrumentTest.java @@ -38,34 +38,33 @@ public class AbstractInstrumentTest { "1", Collections.singletonMap("key_2", "value_2"), Collections.singletonList("key")); - private static final MeterProviderSharedState METER_SHARED_STATE = + private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE = MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty()); private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO = InstrumentationLibraryInfo.create("test_abstract_instrument", ""); + private static final MeterSharedState METER_SHARED_STATE = + MeterSharedState.create(INSTRUMENTATION_LIBRARY_INFO); private static final ActiveBatcher ACTIVE_BATCHER = new ActiveBatcher(Batchers.getNoop()); @Test public void getValues() { TestInstrument testInstrument = new TestInstrument( - INSTRUMENT_DESCRIPTOR, - METER_SHARED_STATE, - INSTRUMENTATION_LIBRARY_INFO, - ACTIVE_BATCHER); + INSTRUMENT_DESCRIPTOR, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE, ACTIVE_BATCHER); assertThat(testInstrument.getDescriptor()).isSameInstanceAs(INSTRUMENT_DESCRIPTOR); - assertThat(testInstrument.getMeterProviderSharedState()).isSameInstanceAs(METER_SHARED_STATE); - assertThat(testInstrument.getInstrumentationLibraryInfo()) - .isSameInstanceAs(INSTRUMENTATION_LIBRARY_INFO); + assertThat(testInstrument.getMeterProviderSharedState()) + .isSameInstanceAs(METER_PROVIDER_SHARED_STATE); + assertThat(testInstrument.getMeterSharedState()).isSameInstanceAs(METER_SHARED_STATE); assertThat(testInstrument.getActiveBatcher()).isSameInstanceAs(ACTIVE_BATCHER); } private static final class TestInstrument extends AbstractInstrument { TestInstrument( InstrumentDescriptor descriptor, - MeterProviderSharedState meterSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterProviderSharedState meterProviderSharedState, + MeterSharedState meterSharedState, ActiveBatcher activeBatcher) { - super(descriptor, meterSharedState, instrumentationLibraryInfo, activeBatcher); + super(descriptor, meterProviderSharedState, meterSharedState, activeBatcher); } @Override diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractMeasureBuilderTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractMeasureBuilderTest.java index b75e7c3bbdb..a17c1fa81ab 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractMeasureBuilderTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractMeasureBuilderTest.java @@ -38,19 +38,19 @@ public class AbstractMeasureBuilderTest { @Rule public ExpectedException thrown = ExpectedException.none(); private static final String NAME = "name"; - private static final MeterProviderSharedState METER_SHARED_STATE = + private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE = MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty()); - private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO = - InstrumentationLibraryInfo.getEmpty(); + private static final MeterSharedState METER_SHARED_STATE = + MeterSharedState.create(InstrumentationLibraryInfo.getEmpty()); @Test public void defaultValue() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO); + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE); assertThat(testInstrumentBuilder.isAbsolute()).isTrue(); - assertThat(testInstrumentBuilder.getMeterProviderSharedState()).isEqualTo(METER_SHARED_STATE); - assertThat(testInstrumentBuilder.getInstrumentationLibraryInfo()) - .isEqualTo(INSTRUMENTATION_LIBRARY_INFO); + assertThat(testInstrumentBuilder.getMeterProviderSharedState()) + .isSameInstanceAs(METER_PROVIDER_SHARED_STATE); + assertThat(testInstrumentBuilder.getMeterSharedState()).isSameInstanceAs(METER_SHARED_STATE); TestInstrument testInstrument = testInstrumentBuilder.build(); assertThat(testInstrument).isInstanceOf(TestInstrument.class); @@ -64,7 +64,7 @@ public void defaultValue() { @Test public void setAndGetValues() { TestInstrumentBuilder testInstrumentBuilder = - new TestInstrumentBuilder(NAME, METER_SHARED_STATE, INSTRUMENTATION_LIBRARY_INFO) + new TestInstrumentBuilder(NAME, METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE) .setAbsolute(false); assertThat(testInstrumentBuilder.isAbsolute()).isFalse(); assertThat(testInstrumentBuilder.build()).isInstanceOf(TestInstrument.class); @@ -74,9 +74,9 @@ private static final class TestInstrumentBuilder extends AbstractMeasure.Builder { TestInstrumentBuilder( String name, - MeterProviderSharedState sharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, sharedState, instrumentationLibraryInfo); + MeterProviderSharedState meterProviderSharedState, + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -89,7 +89,7 @@ public TestInstrument build() { return new TestInstrument( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isAbsolute()); } } @@ -99,14 +99,14 @@ private static final class TestInstrument extends AbstractMeasure { TestInstrumentBuilder( String name, - MeterProviderSharedState sharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo) { - super(name, sharedState, instrumentationLibraryInfo); + MeterProviderSharedState meterProviderSharedState, + MeterSharedState meterSharedState) { + super(name, meterProviderSharedState, meterSharedState); } @Override @@ -86,7 +86,7 @@ public TestInstrument build() { return new TestInstrument( getInstrumentDescriptor(), getMeterProviderSharedState(), - getInstrumentationLibraryInfo(), + getMeterSharedState(), isMonotonic()); } } @@ -96,14 +96,14 @@ private static final class TestInstrument extends AbstractObserver TestInstrument( InstrumentDescriptor descriptor, - MeterProviderSharedState meterSharedState, - InstrumentationLibraryInfo instrumentationLibraryInfo, + MeterProviderSharedState meterProviderSharedState, + MeterSharedState meterSharedState, boolean monotonic) { super( descriptor, InstrumentValueType.LONG, + meterProviderSharedState, meterSharedState, - instrumentationLibraryInfo, monotonic); } diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractObserverTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractObserverTest.java index d5c6d661066..119e8dda38c 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractObserverTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/metrics/AbstractObserverTest.java @@ -64,17 +64,17 @@ private static final class TestObserverInstrument extends AbstractObserver { "1", Collections.singletonMap("key_2", "value_2"), Collections.singletonList("key")); - private static final MeterProviderSharedState METER_SHARED_STATE = + private static final MeterProviderSharedState METER_PROVIDER_SHARED_STATE = MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty()); - private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO = - InstrumentationLibraryInfo.create("test_abstract_instrument", ""); + private static final MeterSharedState METER_SHARED_STATE = + MeterSharedState.create(InstrumentationLibraryInfo.getEmpty()); TestObserverInstrument(InstrumentValueType instrumentValueType, boolean monotonic) { super( INSTRUMENT_DESCRIPTOR, instrumentValueType, + METER_PROVIDER_SHARED_STATE, METER_SHARED_STATE, - INSTRUMENTATION_LIBRARY_INFO, monotonic); } } diff --git a/sdk/src/test/java/io/opentelemetry/sdk/metrics/MeterSdkRegistryTest.java b/sdk/src/test/java/io/opentelemetry/sdk/metrics/MeterSdkRegistryTest.java index 45bd9be8ac6..ac64e236266 100644 --- a/sdk/src/test/java/io/opentelemetry/sdk/metrics/MeterSdkRegistryTest.java +++ b/sdk/src/test/java/io/opentelemetry/sdk/metrics/MeterSdkRegistryTest.java @@ -77,7 +77,7 @@ public void getSameInstanceForSameName_WithVersion() { } @Test - public void propagatesInstrumentationLibraryInfoToTracer() { + public void propagatesInstrumentationLibraryInfoToMeter() { InstrumentationLibraryInfo expected = InstrumentationLibraryInfo.create("theName", "theVersion"); MeterSdk meter = meterRegistry.get(expected.getName(), expected.getVersion());