Skip to content

Commit

Permalink
Implement attributes advice for the rest of the instruments (#5722)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Aug 23, 2023
1 parent 32d591a commit 4b06f09
Show file tree
Hide file tree
Showing 25 changed files with 547 additions and 54 deletions.
2 changes: 2 additions & 0 deletions extensions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
subprojects {
// Workaround https://github.com/gradle/gradle/issues/847
group = "io.opentelemetry.extensions"
val proj = this
plugins.withId("java") {
configure<BasePluginExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import java.util.List;

/** Configure advice for implementation of {@link DoubleCounter}. */
public interface CounterAdviceConfigurer {
public interface DoubleCounterAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this counter. */
CounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
DoubleCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import java.util.List;

/** Configure advice for implementation of {@code DoubleGauge}. */
public interface DoubleGaugeAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this gauge. */
DoubleGaugeAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleHistogram;
import java.util.List;

Expand All @@ -13,4 +14,7 @@ public interface DoubleHistogramAdviceConfigurer {

/** Specify recommended set of explicit bucket boundaries for this histogram. */
DoubleHistogramAdviceConfigurer setExplicitBucketBoundaries(List<Double> bucketBoundaries);

/** Specify the recommended set of attribute keys to be used for this histogram. */
DoubleHistogramAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleUpDownCounter;
import java.util.List;

/** Configure advice for implementation of {@link DoubleUpDownCounter}. */
public interface DoubleUpDownCounterAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this up down counter. */
DoubleUpDownCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public interface ExtendedDoubleCounterBuilder extends DoubleCounterBuilder {

/** Specify advice for counter implementations. */
default DoubleCounterBuilder setAdvice(Consumer<CounterAdviceConfigurer> adviceConsumer) {
default DoubleCounterBuilder setAdvice(Consumer<DoubleCounterAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.DoubleGaugeBuilder;
import java.util.function.Consumer;

/** Extended {@link DoubleGaugeBuilder} with experimental APIs. */
public interface ExtendedDoubleGaugeBuilder extends DoubleGaugeBuilder {

/** Specify advice for gauge implementations. */
default DoubleGaugeBuilder setAdvice(Consumer<DoubleGaugeAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.DoubleUpDownCounterBuilder;
import java.util.function.Consumer;

/** Extended {@link DoubleUpDownCounterBuilder} with experimental APIs. */
public interface ExtendedDoubleUpDownCounterBuilder extends DoubleUpDownCounterBuilder {

/** Specify advice for up down counter implementations. */
default DoubleUpDownCounterBuilder setAdvice(
Consumer<DoubleUpDownCounterAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.LongCounterBuilder;
import java.util.function.Consumer;

/** Extended {@link LongCounterBuilder} with experimental APIs. */
public interface ExtendedLongCounterBuilder extends LongCounterBuilder {

/** Specify advice for counter implementations. */
default LongCounterBuilder setAdvice(Consumer<LongCounterAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.LongGaugeBuilder;
import java.util.function.Consumer;

/** Extended {@link LongGaugeBuilder} with experimental APIs. */
public interface ExtendedLongGaugeBuilder extends LongGaugeBuilder {

/** Specify advice for gauge implementations. */
default LongGaugeBuilder setAdvice(Consumer<LongGaugeAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.metrics.LongUpDownCounterBuilder;
import java.util.function.Consumer;

/** Extended {@link LongUpDownCounterBuilder} with experimental APIs. */
public interface ExtendedLongUpDownCounterBuilder extends LongUpDownCounterBuilder {

/** Specify advice for up down counter implementations. */
default LongUpDownCounterBuilder setAdvice(
Consumer<LongUpDownCounterAdviceConfigurer> adviceConsumer) {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.LongCounter;
import java.util.List;

/** Configure advice for implementation of {@link LongCounter}. */
public interface LongCounterAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this counter. */
LongCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import java.util.List;

/** Configure advice for implementation of {@code LongGauge}. */
public interface LongGaugeAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this gauge. */
LongGaugeAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.LongHistogram;
import java.util.List;

Expand All @@ -13,4 +14,7 @@ public interface LongHistogramAdviceConfigurer {

/** Specify recommended set of explicit bucket boundaries for this histogram. */
LongHistogramAdviceConfigurer setExplicitBucketBoundaries(List<Long> bucketBoundaries);

/** Specify the recommended set of attribute keys to be used for this histogram. */
LongHistogramAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.LongUpDownCounter;
import java.util.List;

/** Configure advice for implementation of {@link LongUpDownCounter}. */
public interface LongUpDownCounterAdviceConfigurer {

/** Specify the recommended set of attribute keys to be used for this up down counter. */
LongUpDownCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes);
}
2 changes: 2 additions & 0 deletions sdk-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
subprojects {
// Workaround https://github.com/gradle/gradle/issues/847
group = "io.opentelemetry.sdk.extensions"
val proj = this
plugins.withId("java") {
configure<BasePluginExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io.opentelemetry.api.metrics.ObservableDoubleCounter;
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
import io.opentelemetry.context.Context;
import io.opentelemetry.extension.incubator.metrics.CounterAdviceConfigurer;
import io.opentelemetry.extension.incubator.metrics.DoubleCounterAdviceConfigurer;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleCounterBuilder;
import io.opentelemetry.sdk.internal.ThrottlingLogger;
import io.opentelemetry.sdk.metrics.internal.descriptor.Advice;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void add(double increment) {

static final class SdkDoubleCounterBuilder
extends AbstractInstrumentBuilder<SdkDoubleCounterBuilder>
implements ExtendedDoubleCounterBuilder, CounterAdviceConfigurer {
implements ExtendedDoubleCounterBuilder, DoubleCounterAdviceConfigurer {

SdkDoubleCounterBuilder(
MeterProviderSharedState meterProviderSharedState,
Expand All @@ -87,7 +87,7 @@ protected SdkDoubleCounterBuilder getThis() {
}

@Override
public DoubleCounterBuilder setAdvice(Consumer<CounterAdviceConfigurer> adviceConsumer) {
public DoubleCounterBuilder setAdvice(Consumer<DoubleCounterAdviceConfigurer> adviceConsumer) {
adviceConsumer.accept(this);
return this;
}
Expand All @@ -109,7 +109,7 @@ public ObservableDoubleMeasurement buildObserver() {
}

@Override
public CounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes) {
public DoubleCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes) {
adviceBuilder.setAttributes(attributes);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@

package io.opentelemetry.sdk.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleGaugeBuilder;
import io.opentelemetry.api.metrics.LongGaugeBuilder;
import io.opentelemetry.api.metrics.ObservableDoubleGauge;
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
import io.opentelemetry.extension.incubator.metrics.DoubleGaugeAdviceConfigurer;
import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleGaugeBuilder;
import io.opentelemetry.sdk.metrics.internal.state.MeterProviderSharedState;
import io.opentelemetry.sdk.metrics.internal.state.MeterSharedState;
import java.util.List;
import java.util.function.Consumer;

final class SdkDoubleGaugeBuilder extends AbstractInstrumentBuilder<SdkDoubleGaugeBuilder>
implements DoubleGaugeBuilder {
implements ExtendedDoubleGaugeBuilder, DoubleGaugeAdviceConfigurer {

SdkDoubleGaugeBuilder(
MeterProviderSharedState meterProviderSharedState,
Expand All @@ -35,6 +39,12 @@ protected SdkDoubleGaugeBuilder getThis() {
return this;
}

@Override
public DoubleGaugeBuilder setAdvice(Consumer<DoubleGaugeAdviceConfigurer> adviceConsumer) {
adviceConsumer.accept(this);
return this;
}

@Override
public LongGaugeBuilder ofLongs() {
return swapBuilder(SdkLongGaugeBuilder::new);
Expand All @@ -49,4 +59,10 @@ public ObservableDoubleGauge buildWithCallback(Consumer<ObservableDoubleMeasurem
public ObservableDoubleMeasurement buildObserver() {
return buildObservableMeasurement(InstrumentType.OBSERVABLE_GAUGE);
}

@Override
public DoubleGaugeAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes) {
adviceBuilder.setAttributes(attributes);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.sdk.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleHistogram;
import io.opentelemetry.api.metrics.LongHistogramBuilder;
Expand Down Expand Up @@ -101,5 +102,11 @@ public DoubleHistogramAdviceConfigurer setExplicitBucketBoundaries(
adviceBuilder.setExplicitBucketBoundaries(bucketBoundaries);
return this;
}

@Override
public DoubleHistogramAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes) {
adviceBuilder.setAttributes(attributes);
return this;
}
}
}
Loading

0 comments on commit 4b06f09

Please sign in to comment.