Skip to content

Commit

Permalink
Delete bound instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg committed Feb 3, 2023
1 parent 9cfdf67 commit bb8caa8
Show file tree
Hide file tree
Showing 38 changed files with 590 additions and 2,046 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleCounter;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -56,47 +54,6 @@ public void add(double increment) {
add(increment, Attributes.empty());
}

BoundDoubleCounter bind(Attributes attributes) {
return new BoundInstrument(getDescriptor(), storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundDoubleCounter {
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger);
private final InstrumentDescriptor descriptor;
private final BoundStorageHandle handle;
private final Attributes attributes;

BoundInstrument(
InstrumentDescriptor descriptor, BoundStorageHandle handle, Attributes attributes) {
this.descriptor = descriptor;
this.handle = handle;
this.attributes = attributes;
}

@Override
public void add(double increment, Context context) {
if (increment < 0) {
throttlingLogger.log(
Level.WARNING,
"Counters can only increase. Instrument "
+ descriptor.getName()
+ " has recorded a negative value.");
return;
}
handle.recordDouble(increment, attributes, context);
}

@Override
public void add(double increment) {
add(increment, Context.current());
}

@Override
public void unbind() {
handle.release();
}
}

static final class SdkDoubleCounterBuilder
extends AbstractInstrumentBuilder<SdkDoubleCounterBuilder> implements DoubleCounterBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -54,47 +52,6 @@ public void record(double value) {
record(value, Attributes.empty());
}

BoundDoubleHistogram bind(Attributes attributes) {
return new BoundInstrument(getDescriptor(), storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundDoubleHistogram {
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger);
private final InstrumentDescriptor descriptor;
private final BoundStorageHandle aggregatorHandle;
private final Attributes attributes;

BoundInstrument(
InstrumentDescriptor descriptor, BoundStorageHandle handle, Attributes attributes) {
this.descriptor = descriptor;
this.aggregatorHandle = handle;
this.attributes = attributes;
}

@Override
public void record(double value, Context context) {
if (value < 0) {
throttlingLogger.log(
Level.WARNING,
"Histograms can only record non-negative values. Instrument "
+ descriptor.getName()
+ " has recorded a negative value.");
return;
}
aggregatorHandle.recordDouble(value, attributes, context);
}

@Override
public void record(double value) {
record(value, Context.current());
}

@Override
public void unbind() {
aggregatorHandle.release();
}
}

static final class SdkDoubleHistogramBuilder
extends AbstractInstrumentBuilder<SdkDoubleHistogramBuilder>
implements DoubleHistogramBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import io.opentelemetry.api.metrics.ObservableDoubleUpDownCounter;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleUpDownCounter;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -43,35 +41,6 @@ public void add(double increment) {
add(increment, Attributes.empty());
}

BoundDoubleUpDownCounter bind(Attributes attributes) {
return new BoundInstrument(storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundDoubleUpDownCounter {
private final BoundStorageHandle handle;
private final Attributes attributes;

BoundInstrument(BoundStorageHandle handle, Attributes attributes) {
this.handle = handle;
this.attributes = attributes;
}

@Override
public void add(double increment, Context context) {
handle.recordDouble(increment, attributes, context);
}

@Override
public void add(double increment) {
add(increment, Context.current());
}

@Override
public void unbind() {
handle.release();
}
}

static final class SdkDoubleUpDownCounterBuilder
extends AbstractInstrumentBuilder<SdkDoubleUpDownCounterBuilder>
implements DoubleUpDownCounterBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -58,47 +56,6 @@ public void add(long increment) {
add(increment, Attributes.empty());
}

BoundLongCounter bind(Attributes attributes) {
return new BoundInstrument(getDescriptor(), storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundLongCounter {
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger);
private final InstrumentDescriptor descriptor;
private final BoundStorageHandle handle;
private final Attributes attributes;

BoundInstrument(
InstrumentDescriptor descriptor, BoundStorageHandle handle, Attributes attributes) {
this.descriptor = descriptor;
this.handle = handle;
this.attributes = attributes;
}

@Override
public void add(long increment, Context context) {
if (increment < 0) {
throttlingLogger.log(
Level.WARNING,
"Counters can only increase. Instrument "
+ descriptor.getName()
+ " has recorded a negative value.");
return;
}
handle.recordLong(increment, attributes, context);
}

@Override
public void add(long increment) {
add(increment, Context.current());
}

@Override
public void unbind() {
handle.release();
}
}

static final class SdkLongCounterBuilder extends AbstractInstrumentBuilder<SdkLongCounterBuilder>
implements LongCounterBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -53,47 +51,6 @@ public void record(long value) {
record(value, Attributes.empty());
}

BoundLongHistogram bind(Attributes attributes) {
return new BoundInstrument(getDescriptor(), storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundLongHistogram {
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(logger);
private final InstrumentDescriptor descriptor;
private final BoundStorageHandle handle;
private final Attributes attributes;

BoundInstrument(
InstrumentDescriptor descriptor, BoundStorageHandle handle, Attributes attributes) {
this.descriptor = descriptor;
this.handle = handle;
this.attributes = attributes;
}

@Override
public void record(long value, Context context) {
if (value < 0) {
throttlingLogger.log(
Level.WARNING,
"Histograms can only record non-negative values. Instrument "
+ descriptor.getName()
+ " has recorded a negative value.");
return;
}
handle.recordLong(value, attributes, context);
}

@Override
public void record(long value) {
record(value, Context.current());
}

@Override
public void unbind() {
handle.release();
}
}

static final class SdkLongHistogramBuilder
extends AbstractInstrumentBuilder<SdkLongHistogramBuilder> implements LongHistogramBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import io.opentelemetry.api.metrics.ObservableLongUpDownCounter;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.metrics.internal.descriptor.InstrumentDescriptor;
import io.opentelemetry.sdk.metrics.internal.instrument.BoundLongUpDownCounter;
import io.opentelemetry.sdk.metrics.internal.state.BoundStorageHandle;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import io.opentelemetry.sdk.metrics.internal.state.WriteableMetricStorage;
Expand Down Expand Up @@ -44,35 +42,6 @@ public void add(long increment) {
add(increment, Attributes.empty());
}

BoundLongUpDownCounter bind(Attributes attributes) {
return new BoundInstrument(storage.bind(attributes), attributes);
}

static final class BoundInstrument implements BoundLongUpDownCounter {
private final BoundStorageHandle handle;
private final Attributes attributes;

BoundInstrument(BoundStorageHandle handle, Attributes attributes) {
this.handle = handle;
this.attributes = attributes;
}

@Override
public void add(long increment, Context context) {
handle.recordLong(increment, attributes, context);
}

@Override
public void add(long increment) {
add(increment, Context.current());
}

@Override
public void unbind() {
handle.release();
}
}

static final class SdkLongUpDownCounterBuilder
extends AbstractInstrumentBuilder<SdkLongUpDownCounterBuilder>
implements LongUpDownCounterBuilder {
Expand Down
Loading

0 comments on commit bb8caa8

Please sign in to comment.