Skip to content

Commit

Permalink
Rename all methods in all Getters to use the get*() naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek committed Jan 19, 2023
1 parent b2f42ec commit dbd944e
Show file tree
Hide file tree
Showing 230 changed files with 1,915 additions and 1,199 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ private CodeAttributesExtractor(CodeAttributesGetter<REQUEST> getter) {

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
Class<?> cls = getter.codeClass(request);
Class<?> cls = getter.getCodeClass(request);
if (cls != null) {
internalSet(attributes, SemanticAttributes.CODE_NAMESPACE, cls.getName());
}
internalSet(attributes, SemanticAttributes.CODE_FUNCTION, getter.methodName(request));
internalSet(attributes, SemanticAttributes.CODE_FUNCTION, getter.getMethodName(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,36 @@
public interface CodeAttributesGetter<REQUEST> {

@Nullable
Class<?> codeClass(REQUEST request);
default Class<?> getCodeClass(REQUEST request) {
return codeClass(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getCodeClass(Object)} instead.
*/
@Deprecated
@Nullable
String methodName(REQUEST request);
default Class<?> codeClass(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

@Nullable
default String getMethodName(REQUEST request) {
return methodName(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getMethodName(Object)} instead.
*/
@Deprecated
@Nullable
default String methodName(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ private CodeSpanNameExtractor(CodeAttributesGetter<REQUEST> getter) {

@Override
public String extract(REQUEST request) {
Class<?> cls = getter.codeClass(request);
Class<?> cls = getter.getCodeClass(request);
String className = cls != null ? ClassNames.simpleName(cls) : "<unknown>";
int lambdaIdx = className.indexOf("$$Lambda$");
if (lambdaIdx > -1) {
// need to produce low-cardinality name, since lambda class names change with each restart
className = className.substring(0, lambdaIdx + "$$Lambda$".length());
}
String methodName = getter.methodName(request);
String methodName = getter.getMethodName(request);
if (methodName == null) {
return className;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static <REQUEST, RESPONSE> DbClientAttributesExtractor<REQUEST, RESPONSE>
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalSet(attributes, SemanticAttributes.DB_STATEMENT, getter.statement(request));
internalSet(attributes, SemanticAttributes.DB_OPERATION, getter.operation(request));
internalSet(attributes, SemanticAttributes.DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, SemanticAttributes.DB_OPERATION, getter.getOperation(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,36 @@
public interface DbClientAttributesGetter<REQUEST> extends DbClientCommonAttributesGetter<REQUEST> {

@Nullable
String statement(REQUEST request);
default String getStatement(REQUEST request) {
return statement(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getStatement(Object)} instead.
*/
@Deprecated
@Nullable
String operation(REQUEST request);
default String statement(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

@Nullable
default String getOperation(REQUEST request) {
return operation(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getOperation(Object)} instead.
*/
@Deprecated
@Nullable
default String operation(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ abstract class DbClientCommonAttributesExtractor<

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
internalSet(attributes, SemanticAttributes.DB_SYSTEM, getter.system(request));
internalSet(attributes, SemanticAttributes.DB_USER, getter.user(request));
internalSet(attributes, SemanticAttributes.DB_NAME, getter.name(request));
internalSet(attributes, SemanticAttributes.DB_SYSTEM, getter.getSystem(request));
internalSet(attributes, SemanticAttributes.DB_USER, getter.getUser(request));
internalSet(attributes, SemanticAttributes.DB_NAME, getter.getName(request));
internalSet(
attributes, SemanticAttributes.DB_CONNECTION_STRING, getter.connectionString(request));
attributes, SemanticAttributes.DB_CONNECTION_STRING, getter.getConnectionString(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,70 @@
public interface DbClientCommonAttributesGetter<REQUEST> {

@Nullable
String system(REQUEST request);
default String getSystem(REQUEST request) {
return system(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getSystem(Object)} instead.
*/
@Deprecated
@Nullable
String user(REQUEST request);
default String system(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

@Nullable
String name(REQUEST request);
default String getUser(REQUEST request) {
return user(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getUser(Object)} instead.
*/
@Deprecated
@Nullable
String connectionString(REQUEST request);
default String user(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

@Nullable
default String getName(REQUEST request) {
return name(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getName(Object)} instead.
*/
@Deprecated
@Nullable
default String name(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

@Nullable
default String getConnectionString(REQUEST request) {
return connectionString(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getConnectionString(Object)} instead.
*/
@Deprecated
@Nullable
default String connectionString(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public abstract class DbClientSpanNameExtractor<REQUEST> implements SpanNameExtr
* Returns a {@link SpanNameExtractor} that constructs the span name according to DB semantic
* conventions: {@code <db.operation> <db.name>}.
*
* @see DbClientAttributesGetter#operation(Object) used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#name(Object) used to extract {@code <db.name>}.
* @see DbClientAttributesGetter#getOperation(Object) used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#getName(Object) used to extract {@code <db.name>}.
*/
public static <REQUEST> SpanNameExtractor<REQUEST> create(
DbClientAttributesGetter<REQUEST> getter) {
Expand All @@ -28,7 +28,7 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(
* conventions: {@code <db.operation> <db.name>.<table>}.
*
* @see SqlStatementInfo#getOperation() used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#name(Object) used to extract {@code <db.name>}.
* @see DbClientAttributesGetter#getName(Object) used to extract {@code <db.name>}.
* @see SqlStatementInfo#getTable() used to extract {@code <db.table>}.
*/
public static <REQUEST> SpanNameExtractor<REQUEST> create(
Expand Down Expand Up @@ -73,8 +73,8 @@ private GenericDbClientSpanNameExtractor(DbClientAttributesGetter<REQUEST> gette

@Override
public String extract(REQUEST request) {
String dbName = getter.name(request);
String operation = getter.operation(request);
String dbName = getter.getName(request);
String operation = getter.getOperation(request);
return computeSpanName(dbName, operation, null);
}
}
Expand All @@ -93,8 +93,8 @@ private SqlClientSpanNameExtractor(SqlClientAttributesGetter<REQUEST> getter) {

@Override
public String extract(REQUEST request) {
String dbName = getter.name(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.rawStatement(request));
String dbName = getter.getName(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
return computeSpanName(
dbName, sanitizedStatement.getOperation(), sanitizedStatement.getTable());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* <p>It sets the same set of attributes as {@link DbClientAttributesExtractor} plus an additional
* <code>{@linkplain SemanticAttributes#DB_SQL_TABLE db.sql.table}</code> attribute. The raw SQL
* statements returned by the {@link SqlClientAttributesGetter#rawStatement(Object)} method are
* statements returned by the {@link SqlClientAttributesGetter#getRawStatement(Object)} method are
* sanitized before use, all statement parameters are removed.
*/
public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
Expand Down Expand Up @@ -59,7 +59,7 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.rawStatement(request));
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
internalSet(attributes, SemanticAttributes.DB_STATEMENT, sanitizedStatement.getFullStatement());
internalSet(attributes, SemanticAttributes.DB_OPERATION, sanitizedStatement.getOperation());
internalSet(attributes, dbTableAttribute, sanitizedStatement.getTable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,22 @@ public interface SqlClientAttributesGetter<REQUEST>
* SqlClientAttributesExtractor} before being set as span attribute.
*/
@Nullable
String rawStatement(REQUEST request);
default String getRawStatement(REQUEST request) {
return rawStatement(request);
}

/**
* Get the raw SQL statement. The value returned by this method is later sanitized by the {@link
* SqlClientAttributesExtractor} before being set as span attribute.
*
* <p>This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getRawStatement(Object)} instead.
*/
@Deprecated
@Nullable
default String rawStatement(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ public static <REQUEST, RESPONSE> HttpClientAttributesExtractorBuilder<REQUEST,
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalSet(attributes, SemanticAttributes.HTTP_URL, stripSensitiveData(getter.url(request)));
internalSet(
attributes, SemanticAttributes.HTTP_URL, stripSensitiveData(getter.getUrl(request)));

internalNetExtractor.onStart(attributes, request);
}

private boolean shouldCapturePeerPort(int port, REQUEST request) {
String url = getter.url(request);
String url = getter.getUrl(request);
if (url == null) {
return true;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ public void onEnd(
@Nullable Throwable error) {
super.onEnd(attributes, context, request, response, error);

internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.flavor(request, response));
internalSet(attributes, SemanticAttributes.HTTP_FLAVOR, getter.getFlavor(request, response));

internalNetExtractor.onEnd(attributes, request, response);
}
Expand All @@ -179,19 +180,19 @@ private static final class NoopNetClientAttributesGetter<REQUEST, RESPONSE>

@Nullable
@Override
public String transport(REQUEST request, @Nullable RESPONSE response) {
public String getTransport(REQUEST request, @Nullable RESPONSE response) {
return null;
}

@Nullable
@Override
public String peerName(REQUEST request) {
public String getPeerName(REQUEST request) {
return null;
}

@Nullable
@Override
public Integer peerPort(REQUEST request) {
public Integer getPeerPort(REQUEST request) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
// Attributes that always exist in a request

@Nullable
String url(REQUEST request);
default String getUrl(REQUEST request) {
return url(request);
}

/**
* This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getUrl(Object)} instead.
*/
@Deprecated
@Nullable
default String url(REQUEST request) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}

// Attributes which are not always available when the request is ready.

Expand All @@ -33,5 +47,24 @@ public interface HttpClientAttributesGetter<REQUEST, RESPONSE>
* {@code response} is {@code null} or not.
*/
@Nullable
String flavor(REQUEST request, @Nullable RESPONSE response);
default String getFlavor(REQUEST request, @Nullable RESPONSE response) {
return flavor(request, response);
}

/**
* Extracts the {@code http.flavor} span attribute.
*
* <p>This is called from {@link Instrumenter#end(Context, Object, Object, Throwable)}, whether
* {@code response} is {@code null} or not.
*
* <p>This method is deprecated and will be removed in the subsequent release.
*
* @deprecated Use {@link #getFlavor(Object, Object)}.
*/
@Deprecated
@Nullable
default String flavor(REQUEST request, @Nullable RESPONSE response) {
throw new UnsupportedOperationException(
"This method is deprecated and will be removed in the subsequent release.");
}
}
Loading

0 comments on commit dbd944e

Please sign in to comment.