Skip to content
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

Implement stable database semantic conventions #11575

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9728c0d
Protype for db stable semconv
heyams Jun 13, 2024
46ee9f7
Update redis db.namespace value
heyams Jun 13, 2024
817dc2d
Update
heyams Jun 13, 2024
8b26641
Update
heyams Jul 31, 2024
a0464be
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Jul 31, 2024
cb4e57c
Use inline
heyams Aug 9, 2024
338549a
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Aug 9, 2024
7d718cb
Fix
heyams Aug 9, 2024
818c9c8
Fix compilation error
heyams Aug 9, 2024
13f78f4
Fix
heyams Aug 9, 2024
aeac9d2
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Aug 19, 2024
dd168ee
Update
heyams Aug 19, 2024
5106782
Fix
heyams Aug 20, 2024
27be3ed
Comment
heyams Aug 20, 2024
d4d332e
Suppress deprecation
heyams Aug 20, 2024
bd3a77d
Fix deprecation
heyams Aug 20, 2024
6714f40
Fix span name for vertxRedisClient
heyams Aug 21, 2024
fc6caa5
Fix couchbaseSpringRepositoryTest
heyams Aug 21, 2024
0cb4c9d
Fix
heyams Aug 21, 2024
9abe6e5
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Aug 21, 2024
5458730
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Aug 27, 2024
0b41bdd
Fix network_type
heyams Aug 28, 2024
fe8fe48
Fix cassandra tests
heyams Aug 28, 2024
7a4234d
Fix cassandraClient test
heyams Aug 28, 2024
76fa8be
Fix RedissonClientTest
heyams Aug 29, 2024
2007a22
Fix db.statement vs. db.query.text
heyams Aug 29, 2024
2ae1354
Fix
heyams Aug 29, 2024
ed94de3
Fix AbstractRedissonAsyncClientTest
heyams Aug 29, 2024
da00aa2
Fix
heyams Aug 29, 2024
f62fc39
Fix
heyams Aug 29, 2024
9dac540
Fix couchbase tests
heyams Aug 29, 2024
066897a
Fix
heyams Aug 29, 2024
181ee2c
Fix codenarc
heyams Aug 29, 2024
be44287
Fix cassandraclienttest 3.0
heyams Aug 29, 2024
c5b8888
Fix cassandra sync test
heyams Aug 30, 2024
dd5b1ef
Fix
heyams Aug 30, 2024
e80ead2
Fix
heyams Aug 30, 2024
0536e20
Fix
heyams Aug 30, 2024
a999f1b
Deprecate getUser and getConnectionString
heyams Sep 9, 2024
a956705
Deprecate getOperation and getStatement
heyams Sep 9, 2024
9cdd39f
Revert
heyams Sep 9, 2024
566318a
Remove supressionWarning
heyams Sep 9, 2024
616b243
Fix
heyams Sep 9, 2024
6e09209
Fix
heyams Sep 10, 2024
63261be
Fix deprecation
heyams Sep 10, 2024
78278e8
Fix
heyams Sep 10, 2024
63fad77
Fix
heyams Sep 10, 2024
a4bbdfc
Fix
heyams Sep 10, 2024
3b60339
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
heyams Sep 13, 2024
14495e3
Fix couchbase tests
heyams Sep 13, 2024
7928bb4
Fix
heyams Sep 13, 2024
60c344f
Fix
heyams Sep 16, 2024
39743eb
Fix
heyams Sep 16, 2024
4171532
Rename getOperationName to getDbOperationName
heyams Sep 17, 2024
dbc596f
Rename getNamespace to getDbNamespace
heyams Sep 17, 2024
f449cf8
Deprecate getSystem and introduce getDbSystem
heyams Sep 17, 2024
8f841e1
Delete SemconvStability.getAttributeKey
heyams Sep 17, 2024
4820887
Fix unused var
heyams Sep 17, 2024
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
39 changes: 39 additions & 0 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@ dependencies {
testImplementation("io.opentelemetry.semconv:opentelemetry-semconv-incubating")
}

testing {
suites {
val testStableDatabaseSemconv by registering(JvmTestSuite::class) {
dependencies {
implementation(project())
implementation(project(":testing-common"))
implementation("io.opentelemetry:opentelemetry-sdk")
implementation("io.opentelemetry:opentelemetry-sdk-testing")
}
targets {
all {
testTask.configure {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
}
}
}
}
val testBothDatabaseSemconv by registering(JvmTestSuite::class) {
dependencies {
implementation(project())
implementation(project(":testing-common"))
implementation("io.opentelemetry:opentelemetry-sdk")
implementation("io.opentelemetry:opentelemetry-sdk-testing")
}
targets {
all {
testTask.configure {
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup")
}
}
}
}
}
}

tasks {
// exclude auto-generated code
named<Checkstyle>("checkstyleMain") {
Expand All @@ -40,4 +75,8 @@ tasks {
sourcesJar {
dependsOn("generateJflex")
}

check {
dependsOn(testing.suites)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;

/**
* Extractor of <a
Expand All @@ -26,7 +27,11 @@ public final class DbClientAttributesExtractor<REQUEST, RESPONSE>

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");

private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_OPERATION_NAME =
AttributeKey.stringKey("db.operation.name");

/** Creates the database client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand All @@ -38,11 +43,18 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
super(getter);
}

@SuppressWarnings("deprecation") // until old db semconv are dropped
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

internalSet(attributes, DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, DB_OPERATION, getter.getOperation(request));
if (SemconvStability.emitStableDatabaseSemconv()) {
internalSet(attributes, DB_QUERY_TEXT, getter.getDbQueryText(request));
internalSet(attributes, DB_OPERATION_NAME, getter.getDbOperationName(request));
}
if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(attributes, DB_STATEMENT, getter.getStatement(request));
internalSet(attributes, DB_OPERATION, getter.getOperation(request));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,23 @@
*/
public interface DbClientAttributesGetter<REQUEST> extends DbClientCommonAttributesGetter<REQUEST> {

/**
* @deprecated Use {@link #getDbQueryText(REQUEST)} instead.
*/
@Deprecated
@Nullable
String getStatement(REQUEST request);
Copy link
Member

Choose a reason for hiding this comment

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

since this was just a rename, I think could add default implementation that delegates to getDbQueryText, then wouldn't need to override this everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's better to use @deprecate so that when old semconv is removed, we can use it to clean it up.


@Nullable
String getDbQueryText(REQUEST request);

/**
* @deprecated Use {@link #getDbOperationName(REQUEST)} instead.
*/
@Deprecated
@Nullable
String getOperation(REQUEST request);
Copy link
Member

Choose a reason for hiding this comment

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

similar here could add default method calling getDbOperationName


@Nullable
String getDbOperationName(REQUEST request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 javax.annotation.Nullable;
Expand All @@ -21,6 +22,7 @@ abstract class DbClientCommonAttributesExtractor<

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_NAME = AttributeKey.stringKey("db.name");
private static final AttributeKey<String> DB_NAMESPACE = AttributeKey.stringKey("db.namespace");
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 =
Expand All @@ -32,12 +34,18 @@ abstract class DbClientCommonAttributesExtractor<
this.getter = getter;
}

@SuppressWarnings("deprecation") // until old db semconv are dropped
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
if (SemconvStability.emitStableDatabaseSemconv()) {
internalSet(attributes, DB_NAMESPACE, getter.getDbNamespace(request));
}
if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(attributes, DB_USER, getter.getUser(request));
internalSet(attributes, DB_NAME, getter.getName(request));
internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request));
}
internalSet(attributes, DB_SYSTEM, getter.getSystem(request));
internalSet(attributes, DB_USER, getter.getUser(request));
internalSet(attributes, DB_NAME, getter.getName(request));
internalSet(attributes, DB_CONNECTION_STRING, getter.getConnectionString(request));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
/** An interface for getting attributes common to database clients. */
public interface DbClientCommonAttributesGetter<REQUEST> {

@Deprecated
@Nullable
String getSystem(REQUEST request);
heyams marked this conversation as resolved.
Show resolved Hide resolved

@Nullable
String getDbSystem(REQUEST request);

@Deprecated
@Nullable
String getUser(REQUEST request);
heyams marked this conversation as resolved.
Show resolved Hide resolved

/**
* @deprecated Use {@link #getDbNamespace(Object)} instead.
*/
@Deprecated
@Nullable
String getName(REQUEST request);

@Nullable
String getDbNamespace(REQUEST request);

@Deprecated
@Nullable
String getConnectionString(REQUEST request);
heyams marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ 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#getOperation(Object) used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#getName(Object) used to extract {@code <db.name>}.
* @see DbClientAttributesGetter#getDbOperationName(Object) used to extract {@code
* <db.operation.name>}.
* @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code <db.namespace>}.
*/
public static <REQUEST> SpanNameExtractor<REQUEST> create(
DbClientAttributesGetter<REQUEST> getter) {
Expand All @@ -25,8 +26,8 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(
* Returns a {@link SpanNameExtractor} that constructs the span name according to DB semantic
* conventions: {@code <db.operation> <db.name>.<identifier>}.
*
* @see SqlStatementInfo#getOperation() used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#getName(Object) used to extract {@code <db.name>}.
* @see SqlStatementInfo#getOperation() () used to extract {@code <db.operation>}.
* @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code <db.namespace>}.
* @see SqlStatementInfo#getMainIdentifier() used to extract {@code <db.table>} or stored
* procedure name.
*/
Expand Down Expand Up @@ -72,8 +73,8 @@ private GenericDbClientSpanNameExtractor(DbClientAttributesGetter<REQUEST> gette

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

@Override
public String extract(REQUEST request) {
String dbName = getter.getName(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
String dbName = getter.getDbNamespace(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawQueryText(request));
return computeSpanName(
dbName, sanitizedStatement.getOperation(), sanitizedStatement.getMainIdentifier());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;

/**
* Extractor of <a
Expand All @@ -19,7 +20,7 @@
*
* <p>It sets the same set of attributes as {@link DbClientAttributesExtractor} plus an additional
* <code>db.sql.table</code> attribute. The raw SQL statements returned by the {@link
* SqlClientAttributesGetter#getRawStatement(Object)} method are sanitized before use, all statement
* SqlClientAttributesGetter#getRawQueryText(Object)} method are sanitized before use, all statement
* parameters are removed.
*/
public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>
Expand All @@ -28,7 +29,10 @@ public final class SqlClientAttributesExtractor<REQUEST, RESPONSE>

// copied from DbIncubatingAttributes
private static final AttributeKey<String> DB_OPERATION = AttributeKey.stringKey("db.operation");
private static final AttributeKey<String> DB_OPERATION_NAME =
AttributeKey.stringKey("db.operation.name");
private static final AttributeKey<String> DB_STATEMENT = AttributeKey.stringKey("db.statement");
private static final AttributeKey<String> DB_QUERY_TEXT = AttributeKey.stringKey("db.query.text");

/** Creates the SQL client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand Down Expand Up @@ -61,18 +65,30 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
this.statementSanitizationEnabled = statementSanitizationEnabled;
}

@SuppressWarnings("deprecation") // until old semconv are dropped
@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

String rawStatement = getter.getRawStatement(request);
String rawStatement =
SemconvStability.emitStableDatabaseSemconv()
? getter.getRawQueryText(request)
: getter.getRawStatement(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawStatement);
String operation = sanitizedStatement.getOperation();
internalSet(
attributes,
DB_STATEMENT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawStatement);
internalSet(attributes, DB_OPERATION, operation);
if (SemconvStability.emitStableDatabaseSemconv()) {
internalSet(
attributes,
DB_QUERY_TEXT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawStatement);
internalSet(attributes, DB_OPERATION_NAME, operation);
} else if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(
attributes,
DB_STATEMENT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawStatement);
internalSet(attributes, DB_OPERATION, operation);
}
if (!SQL_CALL.equals(operation)) {
internalSet(attributes, dbTableAttribute, sanitizedStatement.getMainIdentifier());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ public interface SqlClientAttributesGetter<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.
*
* @deprecated Use {@link #getRawQueryText(Object)} instead.
*/
@Deprecated
@Nullable
String getRawStatement(REQUEST request);

@Nullable
String getRawQueryText(REQUEST request);
}
Loading
Loading