Skip to content

Commit d926221

Browse files
committed
up
1 parent 8d4d16c commit d926221

File tree

3 files changed

+14
-59
lines changed

3 files changed

+14
-59
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
6565
@Override
6666
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
6767
onStartCommon(attributes, getter, request);
68+
serverAttributesExtractor.onStart(attributes, parentContext, request);
6869
}
6970

7071
@SuppressWarnings("deprecation") // until old db semconv are dropped
@@ -90,7 +91,6 @@ static <REQUEST, RESPONSE> void onStartCommon(
9091
internalSet(attributes, DB_STATEMENT, getter.getDbQueryText(request));
9192
internalSet(attributes, DB_OPERATION, getter.getDbOperationName(request));
9293
}
93-
serverAttributesExtractor.onStart(attributes, parentContext, request);
9494
}
9595

9696
@Override
@@ -100,6 +100,7 @@ public void onEnd(
100100
REQUEST request,
101101
@Nullable RESPONSE response,
102102
@Nullable Throwable error) {
103+
internalNetworkExtractor.onEnd(attributes, request, response);
103104
onEndCommon(attributes, getter, response, error);
104105
}
105106

@@ -108,7 +109,6 @@ static <REQUEST, RESPONSE> void onEndCommon(
108109
DbClientAttributesGetter<REQUEST, RESPONSE> getter,
109110
@Nullable RESPONSE response,
110111
@Nullable Throwable error) {
111-
internalNetworkExtractor.onEnd(attributes, request, response);
112112
if (SemconvStability.emitStableDatabaseSemconv()) {
113113
if (error != null) {
114114
internalSet(attributes, ERROR_TYPE, error.getClass().getName());

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/DbClientAttributesGetter.java

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,11 @@
2020
* from the attribute methods, but implement as many as possible for best compliance with the
2121
* OpenTelemetry specification.
2222
*/
23+
@SuppressWarnings("deprecation") // until DbClientCommonAttributesGetter is removed
2324
public interface DbClientAttributesGetter<REQUEST, RESPONSE>
24-
extends NetworkAttributesGetter<REQUEST, RESPONSE>, ServerAttributesGetter<REQUEST> {
25-
26-
@Deprecated
27-
@Nullable
28-
default String getSystem(REQUEST request) {
29-
return null;
30-
}
31-
32-
// TODO: make this required to implement
33-
@Nullable
34-
default String getDbSystem(REQUEST request) {
35-
return getSystem(request);
36-
}
37-
38-
@Deprecated
39-
@Nullable
40-
default String getUser(REQUEST request) {
41-
return null;
42-
}
43-
44-
/**
45-
* @deprecated Use {@link #getDbNamespace(Object)} instead.
46-
*/
47-
@Deprecated
48-
@Nullable
49-
default String getName(REQUEST request) {
50-
return null;
51-
}
52-
53-
// TODO: make this required to implement
54-
@Nullable
55-
default String getDbNamespace(REQUEST request) {
56-
return getName(request);
57-
}
58-
59-
@Deprecated
60-
@Nullable
61-
default String getConnectionString(REQUEST request) {
62-
return null;
63-
}
25+
extends DbClientCommonAttributesGetter<REQUEST, RESPONSE>,
26+
NetworkAttributesGetter<REQUEST, RESPONSE>,
27+
ServerAttributesGetter<REQUEST> {
6428

6529
/**
6630
* @deprecated Use {@link #getDbQueryText(REQUEST)} instead.
@@ -96,9 +60,4 @@ default String getDbOperationName(REQUEST request) {
9660
default String getDbQuerySummary(REQUEST request) {
9761
return null;
9862
}
99-
100-
@Nullable
101-
default String getResponseStatus(@Nullable RESPONSE response, @Nullable Throwable error) {
102-
return null;
103-
}
10463
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/SqlClientAttributesExtractor.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
99
import static io.opentelemetry.semconv.DbAttributes.DB_COLLECTION_NAME;
10+
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE;
1011
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
1112
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
1213
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT;
14+
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
1315

1416
import io.opentelemetry.api.common.AttributeKey;
1517
import io.opentelemetry.api.common.AttributesBuilder;
@@ -41,6 +43,11 @@ public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
4143
// copied from DbIncubatingAttributes
4244
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
4345
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
46+
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
47+
private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user");
48+
private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name");
49+
private static final AttributeKey<String> DB_CONNECTION_STRING =
50+
AttributeKey.stringKey("db.connection_string");
4451
private static final AttributeKeyTemplate<String> DB_QUERY_PARAMETER =
4552
AttributeKeyTemplate.stringKeyTemplate("db.query.parameter");
4653

@@ -194,19 +201,8 @@ public void onEnd(
194201
REQUEST request,
195202
@Nullable RESPONSE response,
196203
@Nullable Throwable error) {
197-
<<<<<<< HEAD
198-
DbClientAttributesExtractor.onEndCommon(attributes, getter, response, error);
199-
=======
200204
internalNetworkExtractor.onEnd(attributes, request, response);
201-
if (SemconvStability.emitStableDatabaseSemconv()) {
202-
if (error != null) {
203-
internalSet(attributes, ERROR_TYPE, error.getClass().getName());
204-
}
205-
if (error != null || response != null) {
206-
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response, error));
207-
}
208-
}
209-
>>>>>>> 491840ef70 (Consolidate network attribute extraction into DbClientAttributesGetter)
205+
DbClientAttributesExtractor.onEndCommon(attributes, getter, response, error);
210206
}
211207

212208
/**

0 commit comments

Comments
 (0)