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

Refactor advice API #5848

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleCounterBuilder;
import java.util.function.Consumer;
import java.util.List;

/** Extended {@link DoubleCounterBuilder} with experimental APIs. */
public interface ExtendedDoubleCounterBuilder extends DoubleCounterBuilder {

/** Specify advice for counter implementations. */
default DoubleCounterBuilder setAdvice(Consumer<DoubleCounterAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this counter.
*/
default ExtendedDoubleCounterBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

package io.opentelemetry.extension.incubator.metrics;

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

/** Extended {@link DoubleGaugeBuilder} with experimental APIs. */
Expand All @@ -22,8 +24,11 @@ public interface ExtendedDoubleGaugeBuilder extends DoubleGaugeBuilder {
*/
DoubleGauge build();

/** Specify advice for gauge implementations. */
default DoubleGaugeBuilder setAdvice(Consumer<DoubleGaugeAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this gauge.
*/
default ExtendedDoubleGaugeBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.DoubleHistogramBuilder;
import java.util.function.Consumer;
import java.util.List;

/** Extended {@link DoubleHistogramBuilder} with experimental APIs. */
public interface ExtendedDoubleHistogramBuilder extends DoubleHistogramBuilder {

/** Specify advice for histogram implementations. */
default DoubleHistogramBuilder setAdvice(
Consumer<DoubleHistogramAdviceConfigurer> adviceConsumer) {
/**
* Specify the explicit bucket buckets boundaries advice, which suggests the recommended set of
* explicit bucket boundaries for this histogram.
*/
default ExtendedDoubleHistogramBuilder setExplicitBucketBoundariesAdvice(
List<Double> bucketBoundaries) {
return this;

Check warning on line 21 in extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/metrics/ExtendedDoubleHistogramBuilder.java

View check run for this annotation

Codecov / codecov/patch

extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/metrics/ExtendedDoubleHistogramBuilder.java#L21

Added line #L21 was not covered by tests
}

/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this histogram.
*/
default ExtendedDoubleHistogramBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

package io.opentelemetry.extension.incubator.metrics;

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

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

/** Specify advice for up down counter implementations. */
default DoubleUpDownCounterBuilder setAdvice(
Consumer<DoubleUpDownCounterAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this up down counter.
*/
default ExtendedDoubleUpDownCounterBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

package io.opentelemetry.extension.incubator.metrics;

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

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

/** Specify advice for counter implementations. */
default LongCounterBuilder setAdvice(Consumer<LongCounterAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this counter.
*/
default ExtendedLongCounterBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

package io.opentelemetry.extension.incubator.metrics;

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

/** Extended {@link LongGaugeBuilder} with experimental APIs. */
Expand All @@ -22,8 +24,11 @@ public interface ExtendedLongGaugeBuilder extends LongGaugeBuilder {
*/
LongGauge build();

/** Specify advice for gauge implementations. */
default LongGaugeBuilder setAdvice(Consumer<LongGaugeAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this gauge.
*/
default ExtendedLongGaugeBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@

package io.opentelemetry.extension.incubator.metrics;

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.metrics.LongHistogramBuilder;
import java.util.function.Consumer;
import java.util.List;

/** Extended {@link LongHistogramBuilder} with experimental APIs. */
public interface ExtendedLongHistogramBuilder extends LongHistogramBuilder {

/** Specify advice for histogram implementations. */
default LongHistogramBuilder setAdvice(Consumer<LongHistogramAdviceConfigurer> adviceConsumer) {
/**
* Specify the explicit bucket buckets boundaries advice, which suggests the recommended set of
* explicit bucket boundaries for this histogram.
*/
default ExtendedLongHistogramBuilder setExplicitBucketBoundariesAdvice(
List<Long> bucketBoundaries) {
return this;

Check warning on line 21 in extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/metrics/ExtendedLongHistogramBuilder.java

View check run for this annotation

Codecov / codecov/patch

extensions/incubator/src/main/java/io/opentelemetry/extension/incubator/metrics/ExtendedLongHistogramBuilder.java#L21

Added line #L21 was not covered by tests
}

/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this histogram.
*/
default ExtendedLongHistogramBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@

package io.opentelemetry.extension.incubator.metrics;

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

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

/** Specify advice for up down counter implementations. */
default LongUpDownCounterBuilder setAdvice(
Consumer<LongUpDownCounterAdviceConfigurer> adviceConsumer) {
/**
* Specify the attribute advice, which suggests the recommended set of attribute keys to be used
* for this up down counter.
*/
default ExtendedLongUpDownCounterBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
return this;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleCounter;
import io.opentelemetry.api.metrics.DoubleCounterBuilder;
import io.opentelemetry.api.metrics.ObservableDoubleCounter;
import io.opentelemetry.api.metrics.ObservableDoubleMeasurement;
import io.opentelemetry.context.Context;
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 +59,7 @@ public void add(double increment) {

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

SdkDoubleCounterBuilder(
MeterProviderSharedState meterProviderSharedState,
Expand All @@ -86,12 +84,6 @@ protected SdkDoubleCounterBuilder getThis() {
return this;
}

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

@Override
public SdkDoubleCounter build() {
return buildSynchronousInstrument(SdkDoubleCounter::new);
Expand All @@ -109,7 +101,7 @@ public ObservableDoubleMeasurement buildObserver() {
}

@Override
public DoubleCounterAdviceConfigurer setAttributes(List<AttributeKey<?>> attributes) {
public ExtendedDoubleCounterBuilder setAttributesAdvice(List<AttributeKey<?>> attributes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we return this external interface without causing trouble for people using this class without the incubator code present?

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 incubator code is always present on the classpath. Its just an implementation dependency instead of api, so users have to add it as a dependency of their own to access the extended behavior. Including the incubator as a implementation dependency is acceptable because its not part of the public API of the SDK, and it doesn't include any transitive dependencies that would make it questionable.

adviceBuilder.setAttributes(attributes);
return this;
}
Expand Down
Loading