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 @@ -18,10 +18,19 @@ nullaway {

tasks {
withType<JavaCompile>().configureEach {
if (!name.contains("test", ignoreCase = true)) {
if (name.contains("test", ignoreCase = true)) {
options.errorprone.nullaway {
enabled = false
}
} else {
options.errorprone.nullaway {
severity.set(CheckSeverity.ERROR)
}
}
options.errorprone.nullaway {
customInitializerAnnotations.add("org.openjdk.jmh.annotations.Setup")
excludedFieldAnnotations.add("org.mockito.Mock")
excludedFieldAnnotations.add("org.mockito.InjectMocks")
}
}
}
1 change: 1 addition & 0 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
id("otel.japicmp-conventions")
id("otel.publish-conventions")
id("otel.jmh-conventions")
id("otel.nullaway-conventions")
}

group = "io.opentelemetry.instrumentation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
@State(Scope.Thread)
public class InstrumenterBenchmark {

private static final Instrumenter<Void, Void> INSTRUMENTER =
Instrumenter.<Void, Void>builder(
private static final Object REQUEST = new Object();

private static final Instrumenter<Object, Void> INSTRUMENTER =
Instrumenter.<Object, Void>builder(
OpenTelemetry.noop(),
"benchmark",
HttpSpanNameExtractor.create(ConstantHttpAttributesGetter.INSTANCE))
Expand All @@ -44,75 +46,76 @@ public class InstrumenterBenchmark {

@Benchmark
public Context start() {
return INSTRUMENTER.start(Context.root(), null);
return INSTRUMENTER.start(Context.root(), REQUEST);
}

@Benchmark
public Context startEnd() {
Context context = INSTRUMENTER.start(Context.root(), null);
INSTRUMENTER.end(context, null, null, null);
Context context = INSTRUMENTER.start(Context.root(), REQUEST);
INSTRUMENTER.end(context, REQUEST, null, null);
return context;
}

enum ConstantHttpAttributesGetter implements HttpClientAttributesGetter<Void, Void> {
enum ConstantHttpAttributesGetter implements HttpClientAttributesGetter<Object, Void> {
INSTANCE;

private static final InetSocketAddress PEER_ADDRESS =
InetSocketAddress.createUnresolved("localhost", 8080);

@Override
public String getUrlFull(Void unused) {
public String getUrlFull(Object unused) {
return "https://opentelemetry.io/benchmark";
}

@Override
public String getHttpRequestMethod(Void unused) {
public String getHttpRequestMethod(Object unused) {
return "GET";
}

@Override
public List<String> getHttpRequestHeader(Void unused, String name) {
public List<String> getHttpRequestHeader(Object unused, String name) {
if (name.equalsIgnoreCase("user-agent")) {
return Collections.singletonList("OpenTelemetryBot");
}
return Collections.emptyList();
}

@Override
public Integer getHttpResponseStatusCode(Void unused, Void unused2, @Nullable Throwable error) {
public Integer getHttpResponseStatusCode(
Object unused, Void unused2, @Nullable Throwable error) {
return 200;
}

@Override
public List<String> getHttpResponseHeader(Void unused, Void unused2, String name) {
public List<String> getHttpResponseHeader(Object unused, Void unused2, String name) {
return Collections.emptyList();
}

@Override
public String getNetworkProtocolName(Void unused, @Nullable Void unused2) {
public String getNetworkProtocolName(Object unused, @Nullable Void unused2) {
return "http";
}

@Override
public String getNetworkProtocolVersion(Void unused, @Nullable Void unused2) {
public String getNetworkProtocolVersion(Object unused, @Nullable Void unused2) {
return "2.0";
}

@Nullable
@Override
public String getServerAddress(Void request) {
public String getServerAddress(Object request) {
return null;
}

@Nullable
@Override
public Integer getServerPort(Void request) {
public Integer getServerPort(Object request) {
return null;
}

@Override
public InetSocketAddress getNetworkPeerInetSocketAddress(
Void request, @Nullable Void response) {
Object request, @Nullable Void response) {
return PEER_ADDRESS;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import javax.annotation.Nullable;

/**
* The {@link AttributesBuilder} and {@link Attributes} used by the instrumentation API. We are able
Expand All @@ -29,6 +30,7 @@ final class UnsafeAttributes extends HashMap<AttributeKey<?>, Object>

@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T get(AttributeKey<T> key) {
return (T) super.get(key);
}
Expand Down Expand Up @@ -62,7 +64,7 @@ public <T> AttributesBuilder put(AttributeKey<Long> key, int value) {

@Override
@CanIgnoreReturnValue
public <T> AttributesBuilder put(AttributeKey<T> key, T value) {
public <T> AttributesBuilder put(AttributeKey<T> key, @Nullable T value) {
super.put(key, value);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class ContextPropagationDebug {
private final Context sourceContext;
private final List<Propagation> locations;
// context after adding debug locations
private Context wrappedContext;
@Nullable private Context wrappedContext;

private ContextPropagationDebug(Context sourceContext) {
this.sourceContext = sourceContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
*/
public final class HttpProtocolUtil {

@Nullable
public static String getProtocol(@Nullable String protocol) {
if (protocol != null && protocol.startsWith("HTTP/")) {
return "http";
}
return null;
}

@Nullable
public static String getVersion(@Nullable String protocol) {
if (protocol != null && protocol.startsWith("HTTP/")) {
return normalizeHttpVersion(protocol.substring("HTTP/".length()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ public static HttpRouteState create(

// this method is used reflectively from InstrumentationApiContextBridging
public static HttpRouteState create(
@Nullable String method, @Nullable String route, int updatedBySourceOrder, Span span) {
@Nullable String method,
@Nullable String route,
int updatedBySourceOrder,
@Nullable Span span) {
return new HttpRouteState(method, route, updatedBySourceOrder, span);
}

Expand All @@ -50,7 +53,10 @@ public static HttpRouteState create(
@Nullable private volatile Span span;

private HttpRouteState(
@Nullable String method, @Nullable String route, int updatedBySourceOrder, Span span) {
@Nullable String method,
@Nullable String route,
int updatedBySourceOrder,
@Nullable Span span) {
this.method = method;
this.updatedBySourceOrder = updatedBySourceOrder;
this.route = route;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

/**
* See <a href="https://github.com/uber/NullAway/wiki/Supported-Annotations#initialization">NullAway
* spec</a>
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public @interface Initializer {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public final class InstrumenterUtil {
private static InstrumenterAccess instrumenterAccess;
private static InstrumenterBuilderAccess instrumenterBuilderAccess;

@Initializer
public static void setInstrumenterAccess(InstrumenterAccess instrumenterAccess) {
InstrumenterUtil.instrumenterAccess = instrumenterAccess;
}

@Initializer
public static void setInstrumenterBuilderAccess(
InstrumenterBuilderAccess instrumenterBuilderAccess) {
InstrumenterUtil.instrumenterBuilderAccess = instrumenterBuilderAccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMap;
import java.util.function.Function;
import javax.annotation.Nullable;

final class WeakLockFreeCache<K, V> implements Cache<K, V> {

Expand All @@ -22,6 +23,7 @@ public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction
}

@Override
@Nullable
public V get(K key) {
return delegate.getIfPresent(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package io.opentelemetry.instrumentation.api.internal.cache.weaklockfree;

import static java.util.Objects.requireNonNull;

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -81,6 +83,7 @@ protected AbstractWeakConcurrentMap(ConcurrentMap<WeakKey<K>, V> target) {
* @param key The key of the entry.
* @return The value of the entry or the default value if it did not exist.
*/
@Nullable
public V get(K key) {
if (key == null) {
throw new NullPointerException();
Expand Down Expand Up @@ -108,6 +111,7 @@ public V get(K key) {
* @param key The key of the entry.
* @return The value of the entry or null if it did not exist.
*/
@Nullable
public V getIfPresent(K key) {
if (key == null) {
throw new NullPointerException();
Expand Down Expand Up @@ -225,6 +229,7 @@ public void clear() {
* @return The default value for a key without value or {@code null} for not defining a default
* value.
*/
@Nullable
protected V defaultValue(K key) {
return null;
}
Expand Down Expand Up @@ -328,7 +333,7 @@ public int hashCode() {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
if (other instanceof WeakKey<?>) {
return ((WeakKey<?>) other).get() == get();
} else {
Expand All @@ -346,9 +351,9 @@ private class EntryIterator implements Iterator<Map.Entry<K, V>> {

private final Iterator<Map.Entry<WeakKey<K>, V>> iterator;

private Map.Entry<WeakKey<K>, V> nextEntry;
@Nullable private Map.Entry<WeakKey<K>, V> nextEntry;

private K nextKey;
@Nullable private K nextKey;

private EntryIterator(Iterator<Map.Entry<WeakKey<K>, V>> iterator) {
this.iterator = iterator;
Expand All @@ -374,11 +379,12 @@ public boolean hasNext() {

@Override
public Map.Entry<K, V> next() {
if (nextKey == null) {
K key = nextKey;
if (key == null) {
throw new NoSuchElementException();
}
try {
return new SimpleEntry(nextKey, nextEntry);
return new SimpleEntry(key, requireNonNull(nextEntry));
} finally {
findNext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected void resetLookupKey(LookupKey<K> lookupKey) {
// can't use AutoClosable/try-with-resources as this project still supports Java 6
static final class LookupKey<K> {

private K key;
@Nullable private K key;
private int hashCode;

@SuppressWarnings("OtelCanIgnoreReturnValueSuggester")
Expand All @@ -159,7 +159,7 @@ void reset() {
}

@Override
public boolean equals(@Nullable Object other) {
public boolean equals(Object other) {
if (other instanceof WeakConcurrentMap.LookupKey<?>) {
return ((LookupKey<?>) other).key == key;
} else {
Expand All @@ -183,12 +183,14 @@ public int hashCode() {
public static class WithInlinedExpunction<K, V> extends WeakConcurrentMap<K, V> {

@Override
@Nullable
public V get(K key) {
expungeStaleEntries();
return super.get(key);
}

@Override
@Nullable
public V getIfPresent(K key) {
expungeStaleEntries();
return super.getIfPresent(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

package io.opentelemetry.instrumentation.api.internal.cache.weaklockfree;

import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
* any time.
*/
public final class WeakConcurrentMapCleaner {
private static Thread thread;
@Nullable private static Thread thread;

private WeakConcurrentMapCleaner() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class ForwardedUrlSchemeProvider<REQUEST> implements Function<REQUEST, Str
}

@Override
@Nullable
public String apply(REQUEST request) {
// try Forwarded
for (String forwarded : getter.getHttpRequestHeader(request, "forwarded")) {
Expand Down
Loading
Loading