Skip to content

Commit

Permalink
Convert all logging statements from slf4j to jul - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Mar 21, 2022
1 parent 60180b5 commit 31c2c57
Show file tree
Hide file tree
Showing 69 changed files with 370 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ evaluationDependsOn(":testing:agent-for-testing")
dependencies {
annotationProcessor("com.google.auto.service:auto-service")
compileOnly("com.google.auto.service:auto-service")
compileOnly("org.slf4j:slf4j-api")

testImplementation("org.testcontainers:testcontainers")
}
Expand Down
2 changes: 0 additions & 2 deletions instrumentation-api-annotation-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ dependencies {
api("io.opentelemetry:opentelemetry-api")
api("io.opentelemetry:opentelemetry-semconv")

implementation("org.slf4j:slf4j-api")

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

Expand Down
2 changes: 0 additions & 2 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ dependencies {
api("io.opentelemetry:opentelemetry-api")
api("io.opentelemetry:opentelemetry-semconv")

implementation("org.slf4j:slf4j-api")

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Represents the global agent configuration consisting of system properties, environment variables,
Expand All @@ -28,7 +28,7 @@
*/
@AutoValue
public abstract class Config {
private static final Logger logger = LoggerFactory.getLogger(Config.class);
private static final Logger logger = Logger.getLogger(Config.class.getName());

// lazy initialized, so that javaagent can set it, and library instrumentation can fall back and
// read system properties
Expand All @@ -53,7 +53,7 @@ static Config create(Map<String, String> allProperties) {
*/
public static void internalInitializeConfig(Config config) {
if (instance != null) {
logger.warn("Config#INSTANCE was already set earlier");
logger.warning("Config#INSTANCE was already set earlier");
return;
}
instance = requireNonNull(config);
Expand Down Expand Up @@ -166,7 +166,9 @@ private <T> T safeGetTypedProperty(String name, ConfigValueParser<T> parser, T d
T value = getTypedProperty(name, parser);
return value == null ? defaultValue : value;
} catch (RuntimeException t) {
logger.debug("Error occurred during parsing: {}", t.getMessage(), t);
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, "Error occurred during parsing: " + t.getMessage(), t);
}
return defaultValue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.instrumentation.api.instrumenter.RequestMetrics;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link RequestListener} which keeps track of <a
Expand All @@ -33,7 +33,7 @@ public final class HttpClientMetrics implements RequestListener {
private static final ContextKey<State> HTTP_CLIENT_REQUEST_METRICS_STATE =
ContextKey.named("http-client-request-metrics-state");

private static final Logger logger = LoggerFactory.getLogger(HttpClientMetrics.class);
private static final Logger logger = Logger.getLogger(HttpClientMetrics.class.getName());

/**
* Returns a {@link RequestMetrics} which can be used to enable recording of {@link
Expand Down Expand Up @@ -67,8 +67,13 @@ public Context start(Context context, Attributes startAttributes, long startNano
public void end(Context context, Attributes endAttributes, long endNanos) {
State state = context.get(HTTP_CLIENT_REQUEST_METRICS_STATE);
if (state == null) {
logger.debug(
"No state present when ending context {}. Cannot record HTTP request metrics.", context);
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"No state present when ending context "
+ context
+ ". Cannot record HTTP request metrics.");
}
return;
}
duration.record(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.instrumentation.api.instrumenter.RequestMetrics;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link RequestListener} which keeps track of <a
Expand All @@ -35,7 +35,7 @@ public final class HttpServerMetrics implements RequestListener {
private static final ContextKey<State> HTTP_SERVER_REQUEST_METRICS_STATE =
ContextKey.named("http-server-request-metrics-state");

private static final Logger logger = LoggerFactory.getLogger(HttpServerMetrics.class);
private static final Logger logger = Logger.getLogger(HttpServerMetrics.class.getName());

/**
* Returns a {@link RequestMetrics} which can be used to enable recording of {@link
Expand Down Expand Up @@ -79,8 +79,13 @@ public Context start(Context context, Attributes startAttributes, long startNano
public void end(Context context, Attributes endAttributes, long endNanos) {
State state = context.get(HTTP_SERVER_REQUEST_METRICS_STATE);
if (state == null) {
logger.debug(
"No state present when ending context {}. Cannot reset HTTP request metrics.", context);
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"No state present when ending context "
+ context
+ ". Cannot record HTTP request metrics.");
}
return;
}
activeRequests.add(-1, applyActiveRequestsView(state.startAttributes()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.instrumentation.api.instrumenter.RequestMetrics;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link RequestListener} which keeps track of <a
Expand All @@ -33,7 +33,7 @@ public final class RpcClientMetrics implements RequestListener {
private static final ContextKey<RpcClientMetrics.State> RPC_CLIENT_REQUEST_METRICS_STATE =
ContextKey.named("rpc-client-request-metrics-state");

private static final Logger logger = LoggerFactory.getLogger(RpcClientMetrics.class);
private static final Logger logger = Logger.getLogger(RpcClientMetrics.class.getName());

private final DoubleHistogram clientDurationHistogram;

Expand Down Expand Up @@ -67,8 +67,13 @@ public Context start(Context context, Attributes startAttributes, long startNano
public void end(Context context, Attributes endAttributes, long endNanos) {
State state = context.get(RPC_CLIENT_REQUEST_METRICS_STATE);
if (state == null) {
logger.debug(
"No state present when ending context {}. Cannot record RPC request metrics.", context);
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"No state present when ending context "
+ context
+ ". Cannot record RPC request metrics.");
}
return;
}
clientDurationHistogram.record(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import io.opentelemetry.instrumentation.api.instrumenter.RequestListener;
import io.opentelemetry.instrumentation.api.instrumenter.RequestMetrics;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* {@link RequestListener} which keeps track of <a
Expand All @@ -33,7 +33,7 @@ public final class RpcServerMetrics implements RequestListener {
private static final ContextKey<RpcServerMetrics.State> RPC_SERVER_REQUEST_METRICS_STATE =
ContextKey.named("rpc-server-request-metrics-state");

private static final Logger logger = LoggerFactory.getLogger(RpcServerMetrics.class);
private static final Logger logger = Logger.getLogger(RpcServerMetrics.class.getName());

private final DoubleHistogram serverDurationHistogram;

Expand Down Expand Up @@ -67,8 +67,13 @@ public Context start(Context context, Attributes startAttributes, long startNano
public void end(Context context, Attributes endAttributes, long endNanos) {
State state = context.get(RPC_SERVER_REQUEST_METRICS_STATE);
if (state == null) {
logger.debug(
"No state present when ending context {}. Cannot record RPC request metrics.", context);
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"No state present when ending context "
+ context
+ ". Cannot record RPC request metrics.");
}
return;
}
serverDurationHistogram.record(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class ContextPropagationDebug {
private static final Logger logger = LoggerFactory.getLogger(ContextPropagationDebug.class);
private static final Logger logger = Logger.getLogger(ContextPropagationDebug.class.getName());

// locations where the context was propagated to another thread (tracking multiple steps is
// helpful in akka where there is so much recursive async spawning of new work)
Expand Down Expand Up @@ -71,10 +70,10 @@ public static void debugContextLeakIfEnabled() {

Context current = Context.current();
if (current != Context.root()) {
logger.error("Unexpected non-root current context found when extracting remote context!");
logger.severe("Unexpected non-root current context found when extracting remote context!");
Span currentSpan = Span.fromContextOrNull(current);
if (currentSpan != null) {
logger.error("It contains this span: {}", currentSpan);
logger.severe("It contains this span: " + currentSpan);
}

debugContextPropagation(current);
Expand Down Expand Up @@ -121,7 +120,7 @@ private static void debugContextPropagation(Context context) {
sb.append("\nwhich was propagated from:");
}
}
logger.error("a context leak was detected. it was propagated from:{}", sb);
logger.severe("a context leak was detected. it was propagated from: " + sb);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

import io.opentelemetry.instrumentation.api.cache.Cache;
import io.opentelemetry.instrumentation.api.field.VirtualField;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class RuntimeVirtualFieldSupplier {

private static final Logger logger = LoggerFactory.getLogger(RuntimeVirtualFieldSupplier.class);
private static final Logger logger =
Logger.getLogger(RuntimeVirtualFieldSupplier.class.getName());

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
Expand All @@ -34,7 +34,7 @@ public interface VirtualFieldSupplier {
public static void set(VirtualFieldSupplier virtualFieldSupplier) {
// only overwrite the default, cache-based supplier
if (instance != DEFAULT) {
logger.warn(
logger.warning(
"Runtime VirtualField supplier has already been set up, further set() calls are ignored");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.logging.Logger;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class SupportabilityMetrics {
private static final Logger logger = LoggerFactory.getLogger(SupportabilityMetrics.class);
private static final Logger logger = Logger.getLogger(SupportabilityMetrics.class.getName());
private final boolean agentDebugEnabled;
private final Consumer<String> reporter;

private final ConcurrentMap<String, KindCounters> suppressionCounters = new ConcurrentHashMap<>();
private final ConcurrentMap<String, AtomicLong> counters = new ConcurrentHashMap<>();

private static final SupportabilityMetrics INSTANCE =
new SupportabilityMetrics(Config.get(), logger::debug).start();
new SupportabilityMetrics(Config.get(), logger::fine).start();

public static SupportabilityMetrics instance() {
return INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
/**
* This class contains several constants used in logging libraries' Mapped Diagnostic Context
* instrumentations.
*
* @see org.slf4j.MDC
*/
public final class LoggingContextConstants {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.apache.camel.Exchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Utility class for managing active contexts as a stack associated with an exchange. */
class ActiveContextManager {

private static final String ACTIVE_CONTEXT_PROPERTY = "OpenTelemetry.activeContext";

private static final Logger logger = LoggerFactory.getLogger(ActiveContextManager.class);
private static final Logger logger = Logger.getLogger(ActiveContextManager.class.getName());

private ActiveContextManager() {}

Expand All @@ -53,7 +53,9 @@ public static void activate(Context context, CamelRequest request) {
ContextWithScope parent = exchange.getProperty(ACTIVE_CONTEXT_PROPERTY, ContextWithScope.class);
ContextWithScope contextWithScope = ContextWithScope.activate(parent, context, request);
exchange.setProperty(ACTIVE_CONTEXT_PROPERTY, contextWithScope);
logger.debug("Activated a span: {}", contextWithScope);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Activated a span: " + contextWithScope);
}
}

/**
Expand All @@ -70,7 +72,9 @@ public static Context deactivate(Exchange exchange) {
if (contextWithScope != null) {
contextWithScope.deactivate(exchange.getException());
exchange.setProperty(ACTIVE_CONTEXT_PROPERTY, contextWithScope.getParent());
logger.debug("Deactivated span: {}", contextWithScope);
if (logger.isLoggable(Level.FINE)) {
logger.fine("Deactivated span: " + contextWithScope);
}
return contextWithScope.context;
}

Expand Down
Loading

0 comments on commit 31c2c57

Please sign in to comment.