Skip to content

Commit 1f7d6a5

Browse files
authored
Add APIs to determine if tracer, logger, instruments are enabled (#6502)
1 parent 9fd6bca commit 1f7d6a5

37 files changed

+773
-81
lines changed

api/incubator/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See [EventApiUsageTest](./src/test/java/io/opentelemetry/api/incubator/events/Ev
1414

1515
Features:
1616

17+
* Check if logger is enabled before emitting logs to avoid uneccessary computation
1718
* Set AnyValue log record body with arbitrarily complex data
1819

1920
See [ExtendedLogsBridgeApiUsageTest](./src/test/java/io/opentelemetry/api/incubator/logs/ExtendedLogsBridgeApiUsageTest.java).
@@ -30,6 +31,7 @@ See [ExtendedMetricsApiUsageTest](./src/test/java/io/opentelemetry/api/incubator
3031

3132
Features:
3233

34+
* Check if instrument is enabled before recording measurements to avoid uneccessary computation
3335
* Simplified injection / extraction of context
3436

3537
See [ExtendedContextPropagatorsUsageTest](./src/test/java/io/opentelemetry/api/incubator/propagation/ExtendedContextPropagatorsUsageTest.java).
@@ -38,6 +40,7 @@ See [ExtendedContextPropagatorsUsageTest](./src/test/java/io/opentelemetry/api/i
3840

3941
Features:
4042

43+
* Check if tracer is enabled before starting spans to avoid uneccessary computation
4144
* Utility methods to reduce boilerplace using span API, including extracting context, and wrapping runnables / callables with spans
4245

4346
See [ExtendedTraceApiUsageTest](./src/test/java/io/opentelemetry/api/incubator/trace/ExtendedTraceApiUsageTest.java).
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.logs;
7+
8+
import io.opentelemetry.api.logs.Logger;
9+
10+
/** Extended {@link Logger} with experimental APIs. */
11+
public interface ExtendedLogger extends Logger {
12+
13+
/**
14+
* Returns {@code true} if the logger is enabled.
15+
*
16+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
17+
* the response is subject to change over the application, callers should call this before each
18+
* call to {@link #logRecordBuilder()}.
19+
*/
20+
default boolean isEnabled() {
21+
return true;
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.DoubleCounter;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link DoubleCounter} with experimental APIs. */
13+
public interface ExtendedDoubleCounter extends DoubleCounter {
14+
15+
/**
16+
* Returns {@code true} if the counter is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
21+
* Attributes, Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.DoubleGauge;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link DoubleGauge} with experimental APIs. */
13+
public interface ExtendedDoubleGauge extends DoubleGauge {
14+
15+
/**
16+
* Returns {@code true} if the gauge is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #set(double)}, {@link #set(double, Attributes)}, or {@link #set(double,
21+
* Attributes, Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.DoubleHistogram;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link DoubleHistogram} with experimental APIs. */
13+
public interface ExtendedDoubleHistogram extends DoubleHistogram {
14+
15+
/**
16+
* Returns {@code true} if the histogram is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #record(double)}, {@link #record(double, Attributes)}, or {@link #record(double,
21+
* Attributes, Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.DoubleUpDownCounter;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link DoubleUpDownCounter} with experimental APIs. */
13+
public interface ExtendedDoubleUpDownCounter extends DoubleUpDownCounter {
14+
15+
/**
16+
* Returns {@code true} if the up down counter is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
21+
* Attributes, Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.DoubleCounter;
10+
import io.opentelemetry.api.metrics.LongCounter;
11+
import io.opentelemetry.context.Context;
12+
13+
/** Extended {@link DoubleCounter} with experimental APIs. */
14+
public interface ExtendedLongCounter extends LongCounter {
15+
16+
/**
17+
* Returns {@code true} if the counter is enabled.
18+
*
19+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
20+
* the response is subject to change over the application, callers should call this before each
21+
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
22+
* Context)}.
23+
*/
24+
default boolean isEnabled() {
25+
return true;
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.LongGauge;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link LongGauge} with experimental APIs. */
13+
public interface ExtendedLongGauge extends LongGauge {
14+
15+
/**
16+
* Returns {@code true} if the gauge is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #set(long)}, {@link #set(long, Attributes)}, or {@link #set(long, Attributes,
21+
* Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.LongHistogram;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link LongHistogram} with experimental APIs. */
13+
public interface ExtendedLongHistogram extends LongHistogram {
14+
15+
/**
16+
* Returns {@code true} if the histogram is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #record(long)}, {@link #record(long, Attributes)}, or {@link #record(long,
21+
* Attributes, Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.api.incubator.metrics;
7+
8+
import io.opentelemetry.api.common.Attributes;
9+
import io.opentelemetry.api.metrics.LongUpDownCounter;
10+
import io.opentelemetry.context.Context;
11+
12+
/** Extended {@link LongUpDownCounter} with experimental APIs. */
13+
public interface ExtendedLongUpDownCounter extends LongUpDownCounter {
14+
15+
/**
16+
* Returns {@code true} if the up down counter is enabled.
17+
*
18+
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
19+
* the response is subject to change over the application, callers should call this before each
20+
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
21+
* Context)}.
22+
*/
23+
default boolean isEnabled() {
24+
return true;
25+
}
26+
}

0 commit comments

Comments
 (0)