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,5 +23,10 @@ tasks {
severity.set(CheckSeverity.ERROR)
}
}
options.errorprone.nullaway {
customInitializerAnnotations.add("org.openjdk.jmh.annotations.Setup")
excludedFieldAnnotations.add("org.mockito.Mock")
excludedFieldAnnotations.add("org.mockito.InjectMocks")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public static <REQUEST, RESPONSE> MessagingAttributesExtractorBuilder<REQUEST, R
}

private final MessagingAttributesGetter<REQUEST, RESPONSE> getter;
private final MessageOperation operation;
@Nullable private final MessageOperation operation;
private final List<String> capturedHeaders;

MessagingAttributesExtractor(
MessagingAttributesGetter<REQUEST, RESPONSE> getter,
MessageOperation operation,
@Nullable MessageOperation operation,
List<String> capturedHeaders) {
this.getter = getter;
this.operation = operation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;

/** A builder of {@link MessagingAttributesExtractor}. */
public final class MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> {

final MessagingAttributesGetter<REQUEST, RESPONSE> getter;
final MessageOperation operation;
@Nullable final MessageOperation operation;
List<String> capturedHeaders = emptyList();

MessagingAttributesExtractorBuilder(
MessagingAttributesGetter<REQUEST, RESPONSE> getter, MessageOperation operation) {
MessagingAttributesGetter<REQUEST, RESPONSE> getter, @Nullable MessageOperation operation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to make the operation nullable?

this.getter = getter;
this.operation = operation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ enum TestGetter implements MessagingAttributesGetter<Map<String, String>, String
INSTANCE;

@Override
@Nullable
public String getSystem(Map<String, String> request) {
return request.get("system");
}

@Override
@Nullable
public String getDestination(Map<String, String> request) {
return request.get("destination");
}
Expand All @@ -161,6 +163,7 @@ public boolean isAnonymousDestination(Map<String, String> request) {
}

@Override
@Nullable
public String getConversationId(Map<String, String> request) {
return request.get("conversationId");
}
Expand All @@ -180,6 +183,7 @@ public Long getMessageEnvelopeSize(Map<String, String> request) {
}

@Override
@Nullable
public String getMessageId(Map<String, String> request, String response) {
return response;
}
Expand Down
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(
Comment on lines -36 to +39
Copy link
Member

Choose a reason for hiding this comment

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

why were these changes needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

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) {
Copy link
Member

Choose a reason for hiding this comment

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

just checking, is null Span ever passed in here?

Copy link
Member Author

Choose a reason for hiding this comment

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

just above: create(method, route, updatedBySourceOrder, null);

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 @@ -332,7 +337,7 @@ public boolean equals(@Nullable Object other) {
if (other instanceof WeakKey<?>) {
return ((WeakKey<?>) other).get() == get();
} else {
return other.equals(this);
return requireNonNull(other).equals(this);
}
}

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 Down Expand Up @@ -378,7 +383,7 @@ public Map.Entry<K, V> next() {
throw new NoSuchElementException();
}
try {
return new SimpleEntry(nextKey, nextEntry);
return new SimpleEntry(requireNonNull(nextKey), requireNonNull(nextEntry));
} finally {
findNext();
}
Expand Down
Loading
Loading