diff --git a/sdk/src/main/java/io/opentelemetry/sdk/metrics/BaseInstrument.java b/sdk/src/main/java/io/opentelemetry/sdk/metrics/BaseInstrument.java index 7ad76cefd06..dc005da293c 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/BaseInstrument.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/BaseInstrument.java @@ -24,13 +24,20 @@ abstract class BaseInstrument implements Instrument { private final String name; private final String description; + private final String unit; private final Map constantLabels; private final List labelKeys; + // All arguments cannot be null because they are checked in the abstract builder classes. BaseInstrument( - String name, String description, Map constantLabels, List labelKeys) { + String name, + String description, + String unit, + Map constantLabels, + List labelKeys) { this.name = name; this.description = description; + this.unit = unit; this.constantLabels = constantLabels; this.labelKeys = labelKeys; } @@ -46,26 +53,20 @@ public boolean equals(Object o) { BaseInstrument that = (BaseInstrument) o; - if (name != null ? !name.equals(that.name) : that.name != null) { - return false; - } - if (description != null ? !description.equals(that.description) : that.description != null) { - return false; - } - if (constantLabels != null - ? !constantLabels.equals(that.constantLabels) - : that.constantLabels != null) { - return false; - } - return labelKeys != null ? labelKeys.equals(that.labelKeys) : that.labelKeys == null; + return name.equals(that.name) + && description.equals(that.description) + && unit.equals(that.unit) + && constantLabels.equals(that.constantLabels) + && labelKeys.equals(that.labelKeys); } @Override public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (description != null ? description.hashCode() : 0); - result = 31 * result + (constantLabels != null ? constantLabels.hashCode() : 0); - result = 31 * result + (labelKeys != null ? labelKeys.hashCode() : 0); + int result = name.hashCode(); + result = 31 * result + description.hashCode(); + result = 31 * result + unit.hashCode(); + result = 31 * result + constantLabels.hashCode(); + result = 31 * result + labelKeys.hashCode(); return result; } } 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 5e086104a9c..84a8bcc0420 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleCounterSdk.java @@ -29,10 +29,11 @@ final class DoubleCounterSdk extends BaseInstrument implements DoubleCounter { private DoubleCounterSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean monotonic) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.monotonic = monotonic; } @@ -113,7 +114,12 @@ Builder getThis() { @Override public DoubleCounter build() { return new DoubleCounterSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + isMonotonic()); } } } 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 a2f9e53f885..aa72e3d1fc1 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleMeasureSdk.java @@ -29,10 +29,11 @@ final class DoubleMeasureSdk extends BaseInstrument implements DoubleMeasure { private DoubleMeasureSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean absolute) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.absolute = absolute; } @@ -113,7 +114,12 @@ Builder getThis() { @Override public DoubleMeasure build() { return new DoubleMeasureSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isAbsolute()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + 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 168653bd2fb..116a7a237f5 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/DoubleObserverSdk.java @@ -26,10 +26,11 @@ final class DoubleObserverSdk extends BaseInstrument implements DoubleObserver { DoubleObserverSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean monotonic) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.monotonic = monotonic; } @@ -82,7 +83,12 @@ Builder getThis() { @Override public DoubleObserver build() { return new DoubleObserverSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + 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 b689fd62496..faa41b4c8dd 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongCounterSdk.java @@ -29,10 +29,11 @@ final class LongCounterSdk extends BaseInstrument implements LongCounter { private LongCounterSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean monotonic) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.monotonic = monotonic; } @@ -113,7 +114,12 @@ Builder getThis() { @Override public LongCounter build() { return new LongCounterSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + 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 c94e8fcde0d..e74d4dddfb5 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongMeasureSdk.java @@ -29,10 +29,11 @@ final class LongMeasureSdk extends BaseInstrument implements LongMeasure { private LongMeasureSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean absolute) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.absolute = absolute; } @@ -113,7 +114,12 @@ Builder getThis() { @Override public LongMeasure build() { return new LongMeasureSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isAbsolute()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + 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 e2af093bcdc..724dbd77c8e 100644 --- a/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java +++ b/sdk/src/main/java/io/opentelemetry/sdk/metrics/LongObserverSdk.java @@ -26,10 +26,11 @@ final class LongObserverSdk extends BaseInstrument implements LongObserver { LongObserverSdk( String name, String description, + String unit, Map constantLabels, List labelKeys, boolean monotonic) { - super(name, description, constantLabels, labelKeys); + super(name, description, unit, constantLabels, labelKeys); this.monotonic = monotonic; } @@ -82,7 +83,12 @@ Builder getThis() { @Override public LongObserver build() { return new LongObserverSdk( - getName(), getDescription(), getConstantLabels(), getLabelKeys(), isMonotonic()); + getName(), + getDescription(), + getUnit(), + getConstantLabels(), + getLabelKeys(), + isMonotonic()); } } }