-
Notifications
You must be signed in to change notification settings - Fork 1k
Deprecate DbClientCommonAttributesGetter #15139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2d367bb
8f0ce07
5ec1057
a228abb
b3f6bc0
3b3feaa
109fd7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,18 +7,25 @@ | |
|
|
||
| import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_COLLECTION_NAME; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_RESPONSE_STATUS_CODE; | ||
| import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME; | ||
| import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.AttributesBuilder; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
| import io.opentelemetry.instrumentation.api.internal.SemconvStability; | ||
| import io.opentelemetry.instrumentation.api.internal.SpanKey; | ||
| import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider; | ||
| import io.opentelemetry.semconv.AttributeKeyTemplate; | ||
| import java.util.Collection; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
| * Extractor of <a | ||
|
|
@@ -31,10 +38,14 @@ | |
| * statement parameters are removed. | ||
| */ | ||
| public final class SqlClientAttributesExtractor<REQUEST, RESPONSE> | ||
| extends DbClientCommonAttributesExtractor< | ||
| REQUEST, RESPONSE, SqlClientAttributesGetter<REQUEST, RESPONSE>> { | ||
| implements AttributesExtractor<REQUEST, RESPONSE>, SpanKeyProvider { | ||
|
Comment on lines
33
to
+37
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change is ok since |
||
|
|
||
| // copied from DbIncubatingAttributes | ||
| private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name"); | ||
| private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system"); | ||
| private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user"); | ||
| private static final AttributeKey<String> DB_CONNECTION_STRING = | ||
| AttributeKey.stringKey("db.connection_string"); | ||
| private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation"); | ||
| private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement"); | ||
| private static final AttributeKeyTemplate<String> DB_QUERY_PARAMETER = | ||
|
|
@@ -57,6 +68,7 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R | |
|
|
||
| private static final String SQL_CALL = "CALL"; | ||
|
|
||
| private final SqlClientAttributesGetter<REQUEST, RESPONSE> getter; | ||
| private final AttributeKey<String> oldSemconvTableAttribute; | ||
| private final boolean statementSanitizationEnabled; | ||
| private final boolean captureQueryParameters; | ||
|
|
@@ -66,17 +78,32 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R | |
| AttributeKey<String> oldSemconvTableAttribute, | ||
| boolean statementSanitizationEnabled, | ||
| boolean captureQueryParameters) { | ||
| super(getter); | ||
| this.getter = getter; | ||
| this.oldSemconvTableAttribute = oldSemconvTableAttribute; | ||
| // capturing query parameters disables statement sanitization | ||
| this.statementSanitizationEnabled = !captureQueryParameters && statementSanitizationEnabled; | ||
| this.captureQueryParameters = captureQueryParameters; | ||
| } | ||
|
|
||
| @SuppressWarnings("deprecation") // until old db semconv are dropped | ||
| @Override | ||
| public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) { | ||
| super.onStart(attributes, parentContext, request); | ||
| // Common attributes | ||
|
||
| if (SemconvStability.emitStableDatabaseSemconv()) { | ||
| internalSet( | ||
| attributes, | ||
| DB_SYSTEM_NAME, | ||
| SemconvStability.stableDbSystemName(getter.getDbSystem(request))); | ||
| internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request)); | ||
| } | ||
| if (SemconvStability.emitOldDatabaseSemconv()) { | ||
| internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request)); | ||
| internalSet(attributes, DB_USER, getter.getUser(request)); | ||
| internalSet(attributes, DB_NAME, getter.getDbNamespace(request)); | ||
| internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request)); | ||
| } | ||
|
|
||
| // SQL-specific attributes | ||
| Collection<String> rawQueryTexts = getter.getRawQueryTexts(request); | ||
|
|
||
| if (rawQueryTexts.isEmpty()) { | ||
|
|
@@ -160,4 +187,30 @@ private static String join(String delimiter, Collection<String> collection) { | |
| } | ||
| return builder.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| public void onEnd( | ||
| AttributesBuilder attributes, | ||
| Context context, | ||
| REQUEST request, | ||
| @Nullable RESPONSE response, | ||
| @Nullable Throwable error) { | ||
| if (SemconvStability.emitStableDatabaseSemconv()) { | ||
| if (error != null) { | ||
| internalSet(attributes, ERROR_TYPE, error.getClass().getName()); | ||
| } | ||
| if (error != null || response != null) { | ||
| internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response, error)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * This method is internal and is hence not for public use. Its API is unstable and can change at | ||
| * any time. | ||
| */ | ||
| @Override | ||
| public SpanKey internalGetSpanKey() { | ||
| return SpanKey.DB_CLIENT; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,37 @@ | |
| * OpenTelemetry specification. | ||
| */ | ||
| public interface SqlClientAttributesGetter<REQUEST, RESPONSE> | ||
| extends DbClientCommonAttributesGetter<REQUEST, RESPONSE> { | ||
| extends DbClientAttributesGetter<REQUEST, RESPONSE> { | ||
|
|
||
| /** | ||
| * SqlClientAttributesExtractor will try to populate db.operation.name based on {@link | ||
| * #getRawQueryTexts(REQUEST)}, but this can be used to explicitly provide the operation name. | ||
| */ | ||
| @Override | ||
| @Nullable | ||
| default String getDbOperationName(REQUEST request) { | ||
| return null; | ||
laurit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * SqlClientAttributesExtractor will try to populate db.operation.name based on {@link | ||
| * #getRawQueryTexts(REQUEST)}, but this can be used to explicitly provide the operation name. | ||
| */ | ||
trask marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| @Nullable | ||
| default String getDbQueryText(REQUEST request) { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * SqlClientAttributesExtractor will try to populate db.operation.name based on {@link | ||
| * #getRawQueryTexts(REQUEST)}, but this can be used to explicitly provide the operation name. | ||
| */ | ||
trask marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| @Nullable | ||
| default String getDbQuerySummary(REQUEST request) { | ||
| return null; | ||
| } | ||
|
Comment on lines
27
to
55
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these methods have same defaults in super interface, but we have comments to remove the defaults in the super interface at which time we'll still want them here |
||
|
|
||
| /** | ||
| * Get the raw SQL query texts. The values returned by this method is later sanitized by the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is ok since
DbClientCommonAttributesExtractorwasn't public