Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id("otel.jacoco-conventions")
id("otel.japicmp-conventions")
id("otel.publish-conventions")
id("otel.nullaway-conventions")
}

group = "io.opentelemetry.instrumentation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private DefaultHttpClientInstrumenterBuilder(
String instrumentationName,
OpenTelemetry openTelemetry,
HttpClientAttributesGetter<REQUEST, RESPONSE> attributesGetter,
TextMapSetter<REQUEST> headerSetter) {
@Nullable TextMapSetter<REQUEST> headerSetter) {
this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName");
this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry");
this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private DefaultHttpServerInstrumenterBuilder(
String instrumentationName,
OpenTelemetry openTelemetry,
HttpServerAttributesGetter<REQUEST, RESPONSE> attributesGetter,
TextMapGetter<REQUEST> headerGetter) {
@Nullable TextMapGetter<REQUEST> headerGetter) {
this.instrumentationName = Objects.requireNonNull(instrumentationName, "instrumentationName");
this.openTelemetry = Objects.requireNonNull(openTelemetry, "openTelemetry");
this.attributesGetter = Objects.requireNonNull(attributesGetter, "attributesGetter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.annotation.Nullable;

/**
* This class is internal and is hence not for public use. Its APIs are unstable and can change at
Expand All @@ -41,6 +41,11 @@ public final class CommonConfig {
private final String loggingSpanIdKey;
private final String loggingTraceFlagsKey;

interface ValueProvider<T> {
Copy link
Member Author

Choose a reason for hiding this comment

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

simply adding @Nullable to the generic arg didn't work

Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed because the return type of java.util.function.Function is considered to be non-nullable?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes

@Nullable
T get(ConfigProvider configProvider);
}

public CommonConfig(InstrumentationConfig config) {
peerServiceResolver =
PeerServiceResolver.create(
Expand Down Expand Up @@ -159,12 +164,12 @@ public String getTraceFlagsKey() {

private static <T> T getFromConfigProviderOrFallback(
InstrumentationConfig config,
Function<ConfigProvider, T> getFromConfigProvider,
ValueProvider<T> getFromConfigProvider,
T defaultValue,
Supplier<T> fallback) {
ConfigProvider configProvider = config.getConfigProvider();
if (configProvider != null) {
T value = getFromConfigProvider.apply(configProvider);
T value = getFromConfigProvider.get(configProvider);
return value != null ? value : defaultValue;
}
// fallback doesn't return null, so we can safely call it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
import java.util.Collection;
import javax.annotation.Nullable;

public abstract class DbClientSpanNameExtractor<REQUEST> implements SpanNameExtractor<REQUEST> {

Expand Down Expand Up @@ -42,7 +43,8 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(

private DbClientSpanNameExtractor() {}

protected String computeSpanName(String dbName, String operation, String mainIdentifier) {
protected String computeSpanName(
@Nullable String dbName, @Nullable String operation, @Nullable String mainIdentifier) {
if (operation == null) {
return dbName == null ? DEFAULT_SPAN_NAME : dbName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.annotation.Nullable;

class MultiQuery {

private final String mainIdentifier;
private final String operation;
@Nullable private final String mainIdentifier;
@Nullable private final String operation;
private final Set<String> statements;

private MultiQuery(String mainIdentifier, String operation, Set<String> statements) {
private MultiQuery(
@Nullable String mainIdentifier, @Nullable String operation, Set<String> statements) {
this.mainIdentifier = mainIdentifier;
this.operation = operation;
this.statements = statements;
Expand All @@ -40,10 +42,12 @@ static MultiQuery analyze(
uniqueMainIdentifier.getValue(), uniqueOperation.getValue(), uniqueStatements);
}

@Nullable
public String getMainIdentifier() {
return mainIdentifier;
}

@Nullable
public String getOperation() {
return operation;
}
Expand All @@ -53,10 +57,10 @@ public Set<String> getStatements() {
}

private static class UniqueValue {
private String value;
@Nullable private String value;
private boolean valid = true;

void set(String value) {
void set(@Nullable String value) {
if (!valid) {
return;
}
Expand All @@ -67,6 +71,7 @@ void set(String value) {
}
}

@Nullable
String getValue() {
return valid ? value : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import javax.annotation.Nullable;

/**
* An interface for getting SQL database client attributes.
Expand All @@ -33,6 +34,7 @@ public interface SqlClientAttributesGetter<REQUEST, RESPONSE>
Collection<String> getRawQueryTexts(REQUEST request);

// TODO: make this required to implement
@Nullable
default Long getBatchSize(REQUEST request) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public SqlStatementInfo sanitize(@Nullable String statement, SqlDialect dialect)
CacheKey.create(statement, dialect), k -> sanitizeImpl(statement, dialect));
}

private static SqlStatementInfo sanitizeImpl(@Nullable String statement, SqlDialect dialect) {
private static SqlStatementInfo sanitizeImpl(String statement, SqlDialect dialect) {
supportability.incrementCounter(SQL_STATEMENT_SANITIZER_CACHE_MISS);
return AutoSqlSanitizer.sanitize(statement, dialect);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public interface GenAiAttributesGetter<REQUEST, RESPONSE> {
@Nullable
Double getRequestTopP(REQUEST request);

List<String> getResponseFinishReasons(REQUEST request, RESPONSE response);
List<String> getResponseFinishReasons(REQUEST request, @Nullable RESPONSE response);

@Nullable
String getResponseId(REQUEST request, RESPONSE response);
String getResponseId(REQUEST request, @Nullable RESPONSE response);

@Nullable
String getResponseModel(REQUEST request, RESPONSE response);
String getResponseModel(REQUEST request, @Nullable RESPONSE response);

@Nullable
Long getUsageInputTokens(REQUEST request, RESPONSE response);
Long getUsageInputTokens(REQUEST request, @Nullable RESPONSE response);

@Nullable
Long getUsageOutputTokens(REQUEST request, RESPONSE response);
Long getUsageOutputTokens(REQUEST request, @Nullable RESPONSE response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void onEnd(
* any time.
*/
@Override
@Nullable
public SpanKey internalGetSpanKey() {
if (operation == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public String resolveService(
@AutoValue
abstract static class ServiceMatcher {

static ServiceMatcher create(Integer port, String path) {
static ServiceMatcher create(@Nullable Integer port, @Nullable String path) {
return new AutoValue_PeerServiceResolverImpl_ServiceMatcher(port, path);
}

Expand All @@ -72,7 +72,7 @@ static ServiceMatcher create(Integer port, String path) {
@Nullable
abstract String getPath();

public boolean matches(Integer port, Supplier<String> pathSupplier) {
public boolean matches(@Nullable Integer port, @Nullable Supplier<String> pathSupplier) {
Copy link
Member

Choose a reason for hiding this comment

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

it looks like null is never passed in here (need to also remove @Nullable from calling method param)

Suggested change
public boolean matches(@Nullable Integer port, @Nullable Supplier<String> pathSupplier) {
public boolean matches(@Nullable Integer port, Supplier<String> pathSupplier) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

ah, I see, how about zeitlinger#7?

if (this.getPort() != null) {
if (!this.getPort().equals(port)) {
return false;
Expand Down