Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.lang.syntax.elements.ClassesShouldConjunction;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -27,6 +28,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@SuppressLogger(NoSharedInternalCodeTest.class)
class NoSharedInternalCodeTest {

private static final Set<String> exemptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.testing.EqualsTester;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import org.junit.jupiter.api.Test;

class BaggageEntryMetadataTest {
Expand All @@ -19,6 +20,7 @@ void getValue() {
}

@Test
@SuppressLogger(loggerName = "io.opentelemetry.usage")
void nullValue() {
assertThat(BaggageEntryMetadata.create(null)).isEqualTo(BaggageEntryMetadata.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.TracerProvider;
import io.opentelemetry.context.Context;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import java.time.Instant;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -124,6 +125,7 @@ void spanContextPropagation_fromContextThenNoParent() {

@Test
@SuppressWarnings("NullAway")
@SuppressLogger(loggerName = "io.opentelemetry.usage")
void doNotCrash_NoopImplementation() {
assertThatCode(
() -> {
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ testing {
all {
testTask.configure {
systemProperty("java.util.logging.config.class", "io.opentelemetry.internal.testing.slf4j.JulBridgeInitializer")
systemProperty("org.slf4j.simpleLogger.log.io.micrometer.core.instrument.MeterRegistry", "error")
systemProperty("org.slf4j.simpleLogger.log.tc", "error")

// Starting in java 21, dynamically attaching agents triggers warnings. Mockito depends on
// agents to redefine classes. Hence, on java 21+ we get warnings of the form:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assumptions.assumeThat;

import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
import okhttp3.OkHttp;
Expand All @@ -18,6 +19,7 @@ class OkHttpVersionTest {
private static final Logger LOGGER = Logger.getLogger(OkHttpVersionTest.class.getName());

@Test
@SuppressLogger(OkHttpVersionTest.class)
void expectedOkHttpVersion() {
String expectedVersion = System.getProperty("expected.okhttp.version");
LOGGER.log(Level.WARNING, "Testing okhttp version " + expectedVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
final class Otel2PrometheusConverter {

private static final Logger LOGGER = Logger.getLogger(Otel2PrometheusConverter.class.getName());
private static final ThrottlingLogger THROTTLING_LOGGER = new ThrottlingLogger(LOGGER);
private final ThrottlingLogger throttlingLogger = new ThrottlingLogger(LOGGER);
// Prometheus limits the total UTF-8 character count across all exemplar label names and values
// to 128. See https://github.com/open-telemetry/opentelemetry-java/issues/6770
private static final int EXEMPLAR_MAX_LABEL_SET_LENGTH = 128;
Expand Down Expand Up @@ -161,7 +161,7 @@ private MetricSnapshot convert(MetricData metricData) {
try {
return doConvert(metricData);
} catch (IllegalArgumentException e) {
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Failed to convert metric " + metricData.getName() + ". Dropping metric.",
e);
Expand Down Expand Up @@ -338,7 +338,7 @@ private HistogramSnapshot convertExponentialHistogram(
for (ExponentialHistogramPointData histogramData : dataPoints) {
int scale = histogramData.getScale();
if (scale < -4) {
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Dropping histogram "
+ metadata.getName()
Expand Down Expand Up @@ -461,7 +461,7 @@ private Exemplar convertExemplar(double value, ExemplarData exemplar) {
if (labelSetLength(labels) > EXEMPLAR_MAX_LABEL_SET_LENGTH) {
// Drop filtered attributes to stay within Prometheus 128-char exemplar label limit,
// keeping trace_id and span_id which are the most valuable for correlation.
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Exemplar attributes exceeded Prometheus limit of "
+ EXEMPLAR_MAX_LABEL_SET_LENGTH
Expand All @@ -484,7 +484,7 @@ private Exemplar convertExemplar(double value, ExemplarData exemplar) {
null, // scope attributes are only needed for point's attributes
exemplar.getFilteredAttributes());
if (labelSetLength(labels) > EXEMPLAR_MAX_LABEL_SET_LENGTH) {
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Exemplar attributes exceeded Prometheus limit of "
+ EXEMPLAR_MAX_LABEL_SET_LENGTH
Expand Down Expand Up @@ -822,7 +822,7 @@ private static void validateNormalizedMetricName(String originalName, String nor
* type. If the type differs, we log a message and drop one of them.
*/
@Nullable
private static MetricSnapshot merge(MetricSnapshot a, MetricSnapshot b) {
private MetricSnapshot merge(MetricSnapshot a, MetricSnapshot b) {
Comment thread
psx95 marked this conversation as resolved.
MetricMetadata metadata = mergeMetadata(a.getMetadata(), b.getMetadata());
if (metadata == null) {
return null;
Expand Down Expand Up @@ -854,7 +854,7 @@ private static MetricSnapshot merge(MetricSnapshot a, MetricSnapshot b) {
dataPoints.addAll(((InfoSnapshot) b).getDataPoints());
return new InfoSnapshot(metadata, dataPoints);
} else {
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Conflicting metric name "
+ a.getMetadata().getPrometheusName()
Expand All @@ -870,7 +870,7 @@ private static MetricSnapshot merge(MetricSnapshot a, MetricSnapshot b) {
}

@Nullable
private static MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b) {
private MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b) {
String name = a.getPrometheusName();
if (a.getName().equals(b.getName())) {
name = a.getName();
Expand All @@ -881,7 +881,7 @@ private static MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b)
}
Unit unit = a.getUnit();
if (unit != null && !unit.equals(b.getUnit())) {
THROTTLING_LOGGER.log(
throttlingLogger.log(
Level.WARNING,
"Conflicting metrics: Multiple metrics with name "
+ name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets;
Expand Down Expand Up @@ -61,6 +62,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -78,6 +80,7 @@
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

@SuppressLogger(Otel2PrometheusConverter.class)
class Otel2PrometheusConverterTest {

private static final Pattern PATTERN =
Expand Down Expand Up @@ -1062,7 +1065,7 @@ void validateCacheIsBounded() {
void mergeInfoSnapshotsWithSameName() throws Exception {
InfoSnapshot merged =
(InfoSnapshot)
invokePrivateStatic(
invokePrivate(
"merge",
new Class<?>[] {MetricSnapshot.class, MetricSnapshot.class},
makeInfoSnapshot("a"),
Expand All @@ -1074,7 +1077,7 @@ void mergeInfoSnapshotsWithSameName() throws Exception {
@Test
void mergeConflictingTypesReturnsNull() throws Exception {
Object merged =
invokePrivateStatic(
invokePrivate(
"merge",
new Class<?>[] {MetricSnapshot.class, MetricSnapshot.class},
makeInfoSnapshot("a"),
Expand All @@ -1088,7 +1091,7 @@ void mergeConflictingTypesReturnsNull() throws Exception {
@Test
void mergeMetadataReturnsNullForDifferentUnits() throws Exception {
Object merged =
invokePrivateStatic(
invokePrivate(
"mergeMetadata",
new Class<?>[] {MetricMetadata.class, MetricMetadata.class},
MetricMetadata.builder().name("sample").unit(new Unit("seconds")).build(),
Expand All @@ -1100,24 +1103,23 @@ void mergeMetadataReturnsNullForDifferentUnits() throws Exception {
@Test
void convertLegacyLabelNameRejectsEmptyName() {
assertThatThrownBy(
() -> invokePrivateStatic("convertLegacyLabelName", new Class<?>[] {String.class}, ""))
() -> invokePrivate("convertLegacyLabelName", new Class<?>[] {String.class}, ""))
.hasCauseInstanceOf(IllegalArgumentException.class)
.hasRootCauseMessage("label name is empty");
}

@Test
void stripReservedMetricSuffixesHandlesReservedNameOnly() throws Exception {
assertThat(
invokePrivateStatic(
"stripReservedMetricSuffixes", new Class<?>[] {String.class}, "_total"))
invokePrivate("stripReservedMetricSuffixes", new Class<?>[] {String.class}, "_total"))
.isEqualTo("total");
}

@Test
void validateNormalizedMetricNameRejectsEmptyName() {
assertThatThrownBy(
() ->
invokePrivateStatic(
invokePrivate(
"validateNormalizedMetricName",
new Class<?>[] {String.class, String.class},
"orig",
Expand All @@ -1130,7 +1132,7 @@ void validateNormalizedMetricNameRejectsEmptyName() {
void convertExponentialHistogramBucketsReturnsEmptyForNoBuckets() throws Exception {
NativeHistogramBuckets buckets =
(NativeHistogramBuckets)
invokePrivateStatic(
invokePrivate(
"convertExponentialHistogramBuckets",
new Class<?>[] {ExponentialHistogramBuckets.class, int.class},
ImmutableExponentialHistogramBuckets.create(0, 0, Collections.emptyList()),
Expand All @@ -1142,7 +1144,7 @@ void convertExponentialHistogramBucketsReturnsEmptyForNoBuckets() throws Excepti
@Test
void typeStringUsesLowerCaseClassName() throws Exception {
assertThat(
invokePrivateStatic(
invokePrivate(
"typeString", new Class<?>[] {MetricSnapshot.class}, makeInfoSnapshot("a")))
.isEqualTo("info");
}
Expand Down Expand Up @@ -1233,12 +1235,15 @@ private static InfoSnapshot makeInfoSnapshot(String id) {
Labels.of(new String[] {"id"}, new String[] {id}))));
}

private static Object invokePrivateStatic(
String methodName, Class<?>[] parameterTypes, Object... args) throws Exception {
private Object invokePrivate(String methodName, Class<?>[] parameterTypes, Object... args)
throws Exception {
Method method = Otel2PrometheusConverter.class.getDeclaredMethod(methodName, parameterTypes);
method.setAccessible(true);
// Support both static and instance methods: static methods receive null, instance methods
// receive the converter instance so that instance fields (e.g. throttlingLogger) are available.
Object instance = Modifier.isStatic(method.getModifiers()) ? null : converter;
try {
return method.invoke(null, args);
return method.invoke(instance, args);
} catch (InvocationTargetException e) {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestDeclarativeConfigurationProvider implements DeclarativeConfigur
@Override
public OpenTelemetryConfigurationModel getConfigurationModel() {
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
+ "resource:\n"
+ " detection/development:\n"
+ " detectors:\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// All tests fail due to config errors so never register a global. We can test everything here
// without separating test sets.
@SuppressLogger(loggerName = "io.opentelemetry.sdk.metrics.export.PeriodicMetricReader")
class ConfigErrorTest {

@RegisterExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.google.common.collect.ImmutableMap;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.autoconfigure.internal.SpiHelper;
import io.opentelemetry.sdk.autoconfigure.provider.TestConfigurableSamplerProvider;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigurationException;
import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties;
import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.io.Closeable;
import java.lang.reflect.Field;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
Expand Down Expand Up @@ -64,16 +67,18 @@ void samplerNotFound() {
}

@Test
void configureSampler_JaegerRemoteSampler() {
assertThat(
TracerProviderConfiguration.configureSampler(
"parentbased_jaeger_remote",
DefaultConfigProperties.createFromMap(Collections.emptyMap()),
spiHelper))
.satisfies(
sampler -> {
assertThat(sampler.getClass().getSimpleName()).isEqualTo("ParentBasedSampler");
assertThat(sampler).extracting("root").isInstanceOf(JaegerRemoteSampler.class);
});
@SuppressLogger(JaegerRemoteSampler.class)
void configureSampler_JaegerRemoteSampler() throws Exception {
Sampler sampler =
TracerProviderConfiguration.configureSampler(
"parentbased_jaeger_remote",
DefaultConfigProperties.createFromMap(Collections.emptyMap()),
spiHelper);
assertThat(sampler.getClass().getSimpleName()).isEqualTo("ParentBasedSampler");
assertThat(sampler).extracting("root").isInstanceOf(JaegerRemoteSampler.class);
// Close the inner JaegerRemoteSampler to shut down its background thread.
Field rootField = sampler.getClass().getDeclaredField("root");
rootField.setAccessible(true);
((Closeable) rootField.get(sampler)).close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class DeclarativeConfigurationTest {
@BeforeEach
void setup() throws IOException {
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand Down Expand Up @@ -189,7 +189,7 @@ void configFile_NoShutdownHook() {
@Test
void configFile_Error(@TempDir Path tempDir) throws IOException {
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void setUp(@TempDir Path tempDir) throws IOException {

String endpoint = "http://localhost:" + server.httpPort();
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
+ "resource:\n"
+ " attributes:\n"
+ " - name: service.name\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void parseAndCreate_Exception_CleansUpPartials() {
// exporter with OTLP exporter, following by invalid batch exporter which references invalid
// exporter "foo".
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
Comment thread
psx95 marked this conversation as resolved.
+ "logger_provider:\n"
+ " processors:\n"
+ " - batch:\n"
Expand All @@ -152,7 +152,7 @@ void parseAndCreate_Exception_CleansUpPartials() {
@Test
void parseAndCreate_EmptyComponentProviderConfig() {
String yaml =
"file_format: \"1.0\"\n"
"file_format: \"1.1\"\n"
+ "logger_provider:\n"
+ " processors:\n"
+ " - test:\n"
Expand All @@ -170,7 +170,7 @@ void parseAndCreate_EmptyComponentProviderConfig() {
@Test
void create_ModelCustomizer() {
OpenTelemetryConfigurationModel model = new OpenTelemetryConfigurationModel();
model.withFileFormat("1.0");
model.withFileFormat("1.1");
model.withTracerProvider(
new TracerProviderModel()
.withProcessors(
Expand Down
Loading
Loading