Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ static Logger getInstance() {
return INSTANCE;
}

@Override
public boolean isEnabled(Severity severity, Context context) {
return false;
}

@Override
public LogRecordBuilder logRecordBuilder() {
return NOOP_LOG_RECORD_BUILDER;
Expand Down
18 changes: 18 additions & 0 deletions api/all/src/main/java/io/opentelemetry/api/logs/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.api.logs;

import io.opentelemetry.context.Context;
import javax.annotation.concurrent.ThreadSafe;

/**
Expand All @@ -22,6 +23,23 @@
@ThreadSafe
public interface Logger {

/**
* Returns {@code true} if the logger is enabled for the given {@code context} and {@code
* severity}.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #logRecordBuilder()}.
*/
default boolean isEnabled(Severity severity, Context context) {
return true;
}

/** Overload of {@link #isEnabled(Severity, Context)} assuming {@link Context#current()}. */
default boolean isEnabled(Severity severity) {
return isEnabled(severity, Context.current());
}

/**
* Return a {@link LogRecordBuilder} to emit a log record.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public BatchCallback batchCallback(
private DefaultMeter() {}

private static class NoopLongCounter implements LongCounter {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void add(long value, Attributes attributes, Context context) {}

Expand All @@ -78,6 +83,11 @@ public void add(long value) {}
}

private static class NoopDoubleCounter implements DoubleCounter {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void add(double value, Attributes attributes, Context context) {}

Expand Down Expand Up @@ -159,6 +169,11 @@ public ObservableDoubleMeasurement buildObserver() {
}

private static class NoopLongUpDownCounter implements LongUpDownCounter {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void add(long value, Attributes attributes, Context context) {}

Expand All @@ -170,6 +185,11 @@ public void add(long value) {}
}

private static class NoopDoubleUpDownCounter implements DoubleUpDownCounter {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void add(double value, Attributes attributes, Context context) {}

Expand Down Expand Up @@ -253,6 +273,11 @@ public ObservableDoubleMeasurement buildObserver() {
}

private static class NoopDoubleHistogram implements DoubleHistogram {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void record(double value, Attributes attributes, Context context) {}

Expand All @@ -264,6 +289,11 @@ public void record(double value) {}
}

private static class NoopLongHistogram implements LongHistogram {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void record(long value, Attributes attributes, Context context) {}

Expand Down Expand Up @@ -357,6 +387,11 @@ public DoubleGauge build() {
}

private static class NoopDoubleGauge implements DoubleGauge {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void set(double value) {}

Expand Down Expand Up @@ -398,6 +433,11 @@ public LongGauge build() {
}

private static class NoopLongGauge implements LongGauge {
@Override
public boolean isEnabled() {
return false;
}

@Override
public void set(long value) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
*/
@ThreadSafe
public interface DoubleCounter {

/**
* Returns {@code true} if the counter is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
*/
@ThreadSafe
public interface DoubleGauge {

/**
* Returns {@code true} if the gauge is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #set(double)}, {@link #set(double, Attributes)}, or {@link #set(double,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Set the gauge value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
@ThreadSafe
public interface DoubleHistogram {

/**
* Returns {@code true} if the histogram is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #record(double)}, {@link #record(double, Attributes)}, or {@link #record(double,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
*/
@ThreadSafe
public interface DoubleUpDownCounter {

/**
* Returns {@code true} if the up down counter is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
@ThreadSafe
public interface LongCounter {

/**
* Returns {@code true} if the counter is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
* Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
*/
@ThreadSafe
public interface LongGauge {

/**
* Returns {@code true} if the gauge is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #set(long)}, {@link #set(long, Attributes)}, or {@link #set(long, Attributes,
* Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Set the gauge value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
@ThreadSafe
public interface LongHistogram {

/**
* Returns {@code true} if the histogram is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #record(long)}, {@link #record(long, Attributes)}, or {@link #record(long,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
*/
@ThreadSafe
public interface LongUpDownCounter {

/**
* Returns {@code true} if the up down counter is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #add(long)}, {@link #add(long, Attributes)}, or {@link #add(long, Attributes,
* Context)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Records a value.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ static Tracer getInstance() {
return INSTANCE;
}

@Override
public boolean isEnabled() {
return false;
}

@Override
public SpanBuilder spanBuilder(String spanName) {
return NoopSpanBuilder.create();
Expand Down
11 changes: 11 additions & 0 deletions api/all/src/main/java/io/opentelemetry/api/trace/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
@ThreadSafe
public interface Tracer {

/**
* Returns {@code true} if the tracer is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #spanBuilder(String)}.
*/
default boolean isEnabled() {
return true;
}

/**
* Returns a {@link SpanBuilder} to create and start a new {@link Span}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,10 @@
package io.opentelemetry.api.incubator.logs;

import io.opentelemetry.api.logs.Logger;
import io.opentelemetry.api.logs.Severity;
import io.opentelemetry.context.Context;

/** Extended {@link Logger} with experimental APIs. */
public interface ExtendedLogger extends Logger {

/**
* Returns {@code true} if the logger is enabled for the given {@code context} and {@code
* severity}.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #logRecordBuilder()}.
*/
default boolean isEnabled(Severity severity, Context context) {
return true;
}

/** Overload of {@link #isEnabled(Severity, Context)} assuming {@link Context#current()}. */
default boolean isEnabled(Severity severity) {
return isEnabled(severity, Context.current());
}

/**
* Overload of {@link #isEnabled(Severity, Context)} assuming {@link
* Severity#UNDEFINED_SEVERITY_NUMBER} and {@link Context#current()}.
*
* @deprecated for removal after 1.55.0. Use {@link #isEnabled(Severity, Context)} or {@link
* #isEnabled(Severity)} instead.
*/
@Deprecated
Copy link
Member Author

Choose a reason for hiding this comment

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

Note, also removing this deprecated API

default boolean isEnabled() {
return isEnabled(Severity.UNDEFINED_SEVERITY_NUMBER);
}

@Override
ExtendedLogRecordBuilder logRecordBuilder();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@

package io.opentelemetry.api.incubator.metrics;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.metrics.DoubleCounter;
import io.opentelemetry.context.Context;

/** Extended {@link DoubleCounter} with experimental APIs. */
public interface ExtendedDoubleCounter extends DoubleCounter {

/**
* Returns {@code true} if the counter is enabled.
*
* <p>This allows callers to avoid unnecessary compute when nothing is consuming the data. Because
* the response is subject to change over the application, callers should call this before each
* call to {@link #add(double)}, {@link #add(double, Attributes)}, or {@link #add(double,
* Attributes, Context)}.
*/
default boolean isEnabled() {
return true;
}
// keep this class even if it is empty, since experimental methods may be added in the future.
}
Loading
Loading