Skip to content

Commit 62b4f02

Browse files
Merge branch 'main' into main
2 parents 1dd3179 + 6c81831 commit 62b4f02

File tree

17 files changed

+152
-114
lines changed

17 files changed

+152
-114
lines changed

conventions/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dependencies {
6363
implementation("ru.vyarus:gradle-animalsniffer-plugin:2.0.1")
6464
implementation("org.spdx:spdx-gradle-plugin:0.9.0")
6565
// When updating, also update dependencyManagement/build.gradle.kts
66-
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.17.8")
66+
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.18.0")
6767
implementation("gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.6")
6868
implementation("me.champeau.jmh:jmh-gradle-plugin:0.7.3")
6969
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.3.0")

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ val DEPENDENCY_BOMS = listOf(
3838
val autoServiceVersion = "1.1.1"
3939
val autoValueVersion = "1.11.0"
4040
val errorProneVersion = "2.43.0"
41-
val byteBuddyVersion = "1.17.8"
41+
val byteBuddyVersion = "1.18.0"
4242
val asmVersion = "9.9"
4343
val jmhVersion = "1.37"
4444
val mockitoVersion = "4.11.0"

examples/distro/smoke-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
testImplementation("io.opentelemetry.proto:opentelemetry-proto:1.8.0-alpha")
1111
testImplementation("io.opentelemetry:opentelemetry-api")
1212

13-
testImplementation("ch.qos.logback:logback-classic:1.5.20")
13+
testImplementation("ch.qos.logback:logback-classic:1.5.21")
1414
}
1515

1616
tasks.test {

examples/extension/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ dependencies {
110110
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
111111
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
112112

113-
testRuntimeOnly("ch.qos.logback:logback-classic:1.5.20")
113+
testRuntimeOnly("ch.qos.logback:logback-classic:1.5.21")
114114

115115
//Otel Java instrumentation that we use and extend during integration tests
116116
otel("io.opentelemetry.javaagent:opentelemetry-javaagent:${versions.opentelemetryJavaagent}")

gradle-plugins/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ configurations.named("compileOnly") {
2525
extendsFrom(bbGradlePlugin)
2626
}
2727

28-
val byteBuddyVersion = "1.17.8"
28+
val byteBuddyVersion = "1.18.0"
2929
val aetherVersion = "1.1.0"
3030

3131
dependencies {

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

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66
package io.opentelemetry.instrumentation.api.incubator.semconv.db;
77

88
import static io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil.internalSet;
9+
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE;
910
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME;
1011
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY;
1112
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT;
13+
import static io.opentelemetry.semconv.DbAttributes.DB_RESPONSE_STATUS_CODE;
14+
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
15+
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
1216

1317
import io.opentelemetry.api.common.AttributeKey;
1418
import io.opentelemetry.api.common.AttributesBuilder;
1519
import io.opentelemetry.context.Context;
1620
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1721
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
22+
import io.opentelemetry.instrumentation.api.internal.SpanKey;
23+
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
24+
import javax.annotation.Nullable;
1825

1926
/**
2027
* Extractor of <a
@@ -25,12 +32,18 @@
2532
* attribute extraction from request/response objects.
2633
*/
2734
public final class DbClientAttributesExtractor<REQUEST, RESPONSE>
28-
extends DbClientCommonAttributesExtractor<
29-
REQUEST, RESPONSE, DbClientAttributesGetter<REQUEST, RESPONSE>> {
35+
implements AttributesExtractor<REQUEST, RESPONSE>, SpanKeyProvider {
3036

3137
// copied from DbIncubatingAttributes
38+
private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name");
39+
private static final AttributeKey<String> DB_SYSTEM = AttributeKey.stringKey("db.system");
40+
private static final AttributeKey<String> DB_USER = AttributeKey.stringKey("db.user");
41+
private static final AttributeKey<String> DB_CONNECTION_STRING =
42+
AttributeKey.stringKey("db.connection_string");
3243
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
33-
static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
44+
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
45+
46+
private final DbClientAttributesGetter<REQUEST, RESPONSE> getter;
3447

3548
/** Creates the database client attributes extractor with default configuration. */
3649
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
@@ -39,21 +52,71 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
3952
}
4053

4154
DbClientAttributesExtractor(DbClientAttributesGetter<REQUEST, RESPONSE> getter) {
42-
super(getter);
55+
this.getter = getter;
4356
}
4457

58+
@SuppressWarnings("deprecation") // until old db semconv are dropped
4559
@Override
4660
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
47-
super.onStart(attributes, parentContext, request);
61+
onStartCommon(attributes, getter, request);
62+
}
4863

64+
@SuppressWarnings("deprecation") // until old db semconv are dropped
65+
static <REQUEST, RESPONSE> void onStartCommon(
66+
AttributesBuilder attributes,
67+
DbClientAttributesGetter<REQUEST, RESPONSE> getter,
68+
REQUEST request) {
4969
if (SemconvStability.emitStableDatabaseSemconv()) {
70+
internalSet(
71+
attributes,
72+
DB_SYSTEM_NAME,
73+
SemconvStability.stableDbSystemName(getter.getDbSystem(request)));
74+
internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request));
5075
internalSet(attributes, DB_QUERY_TEXT, getter.getDbQueryText(request));
5176
internalSet(attributes, DB_OPERATION_NAME, getter.getDbOperationName(request));
5277
internalSet(attributes, DB_QUERY_SUMMARY, getter.getDbQuerySummary(request));
5378
}
5479
if (SemconvStability.emitOldDatabaseSemconv()) {
80+
internalSet(attributes, DB_SYSTEM, getter.getDbSystem(request));
81+
internalSet(attributes, DB_USER, getter.getUser(request));
82+
internalSet(attributes, DB_NAME, getter.getDbNamespace(request));
83+
internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request));
5584
internalSet(attributes, DB_STATEMENT, getter.getDbQueryText(request));
5685
internalSet(attributes, DB_OPERATION, getter.getDbOperationName(request));
5786
}
5887
}
88+
89+
@Override
90+
public void onEnd(
91+
AttributesBuilder attributes,
92+
Context context,
93+
REQUEST request,
94+
@Nullable RESPONSE response,
95+
@Nullable Throwable error) {
96+
onEndCommon(attributes, getter, response, error);
97+
}
98+
99+
static <REQUEST, RESPONSE> void onEndCommon(
100+
AttributesBuilder attributes,
101+
DbClientAttributesGetter<REQUEST, RESPONSE> getter,
102+
@Nullable RESPONSE response,
103+
@Nullable Throwable error) {
104+
if (SemconvStability.emitStableDatabaseSemconv()) {
105+
if (error != null) {
106+
internalSet(attributes, ERROR_TYPE, error.getClass().getName());
107+
}
108+
if (error != null || response != null) {
109+
internalSet(attributes, DB_RESPONSE_STATUS_CODE, getter.getResponseStatus(response, error));
110+
}
111+
}
112+
}
113+
114+
/**
115+
* This method is internal and is hence not for public use. Its API is unstable and can change at
116+
* any time.
117+
*/
118+
@Override
119+
public SpanKey internalGetSpanKey() {
120+
return SpanKey.DB_CLIENT;
121+
}
59122
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* from the attribute methods, but implement as many as possible for best compliance with the
1919
* OpenTelemetry specification.
2020
*/
21+
@SuppressWarnings("deprecation") // extending deprecated interface for backward compatibility
2122
public interface DbClientAttributesGetter<REQUEST, RESPONSE>
2223
extends DbClientCommonAttributesGetter<REQUEST, RESPONSE> {
2324

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

Lines changed: 0 additions & 83 deletions
This file was deleted.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
import javax.annotation.Nullable;
99

10-
/** An interface for getting attributes common to database clients. */
10+
/**
11+
* An interface for getting attributes common to database clients.
12+
*
13+
* @deprecated Use {@link DbClientAttributesGetter} instead.
14+
*/
15+
@Deprecated
1116
public interface DbClientCommonAttributesGetter<REQUEST, RESPONSE> {
1217

1318
String getDbSystem(REQUEST request);

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

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
import io.opentelemetry.context.Context;
1717
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1818
import io.opentelemetry.instrumentation.api.internal.SemconvStability;
19+
import io.opentelemetry.instrumentation.api.internal.SpanKey;
20+
import io.opentelemetry.instrumentation.api.internal.SpanKeyProvider;
1921
import io.opentelemetry.semconv.AttributeKeyTemplate;
2022
import java.util.Collection;
2123
import java.util.Map;
24+
import javax.annotation.Nullable;
2225

2326
/**
2427
* Extractor of <a
@@ -31,8 +34,7 @@
3134
* statement parameters are removed.
3235
*/
3336
public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
34-
extends DbClientCommonAttributesExtractor<
35-
REQUEST, RESPONSE, SqlClientAttributesGetter<REQUEST, RESPONSE>> {
37+
implements AttributesExtractor<REQUEST, RESPONSE>, SpanKeyProvider {
3638

3739
// copied from DbIncubatingAttributes
3840
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
@@ -57,6 +59,7 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
5759

5860
private static final String SQL_CALL = "CALL";
5961

62+
private final SqlClientAttributesGetter<REQUEST, RESPONSE> getter;
6063
private final AttributeKey<String> oldSemconvTableAttribute;
6164
private final boolean statementSanitizationEnabled;
6265
private final boolean captureQueryParameters;
@@ -66,23 +69,18 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
6669
AttributeKey<String> oldSemconvTableAttribute,
6770
boolean statementSanitizationEnabled,
6871
boolean captureQueryParameters) {
69-
super(getter);
72+
this.getter = getter;
7073
this.oldSemconvTableAttribute = oldSemconvTableAttribute;
7174
// capturing query parameters disables statement sanitization
7275
this.statementSanitizationEnabled = !captureQueryParameters && statementSanitizationEnabled;
7376
this.captureQueryParameters = captureQueryParameters;
7477
}
7578

79+
@SuppressWarnings("deprecation") // until old db semconv are dropped
7680
@Override
7781
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
78-
super.onStart(attributes, parentContext, request);
79-
8082
Collection<String> rawQueryTexts = getter.getRawQueryTexts(request);
8183

82-
if (rawQueryTexts.isEmpty()) {
83-
return;
84-
}
85-
8684
Long batchSize = getter.getBatchSize(request);
8785
boolean isBatch = batchSize != null && batchSize > 1;
8886

@@ -118,7 +116,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
118116
if (!SQL_CALL.equals(operation)) {
119117
internalSet(attributes, DB_COLLECTION_NAME, sanitizedStatement.getMainIdentifier());
120118
}
121-
} else {
119+
} else if (rawQueryTexts.size() > 1) {
122120
MultiQuery multiQuery =
123121
MultiQuery.analyze(getter.getRawQueryTexts(request), statementSanitizationEnabled);
124122
internalSet(attributes, DB_QUERY_TEXT, join("; ", multiQuery.getStatements()));
@@ -136,6 +134,11 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
136134

137135
Map<String, String> queryParameters = getter.getQueryParameters(request);
138136
setQueryParameters(attributes, isBatch, queryParameters);
137+
138+
// calling this last so explicit getDbOperationName(), getDbCollectionName(),
139+
// getDbQueryText(), and getDbQuerySummary() implementations can override
140+
// the parsed values from above
141+
DbClientAttributesExtractor.onStartCommon(attributes, getter, request);
139142
}
140143

141144
private void setQueryParameters(
@@ -160,4 +163,23 @@ private static String join(String delimiter, Collection<String> collection) {
160163
}
161164
return builder.toString();
162165
}
166+
167+
@Override
168+
public void onEnd(
169+
AttributesBuilder attributes,
170+
Context context,
171+
REQUEST request,
172+
@Nullable RESPONSE response,
173+
@Nullable Throwable error) {
174+
DbClientAttributesExtractor.onEndCommon(attributes, getter, response, error);
175+
}
176+
177+
/**
178+
* This method is internal and is hence not for public use. Its API is unstable and can change at
179+
* any time.
180+
*/
181+
@Override
182+
public SpanKey internalGetSpanKey() {
183+
return SpanKey.DB_CLIENT;
184+
}
163185
}

0 commit comments

Comments
 (0)