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 some of the stable database semantic conventions #11575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
7025846
Protype for db stable semconv
heyams Jun 13, 2024
89395e0
Update redis db.namespace value
heyams Jun 13, 2024
e021f5e
Update
heyams Oct 3, 2024
08c882e
Update
heyams Jul 31, 2024
a414139
Use inline
heyams Aug 9, 2024
b42b8bf
Fix
heyams Aug 9, 2024
4b7c2c0
Fix compilation error
heyams Aug 9, 2024
52e0880
Fix
heyams Aug 9, 2024
2344545
Update
heyams Aug 19, 2024
c8b69a7
Fix
heyams Aug 20, 2024
7004ada
Comment
heyams Aug 20, 2024
5ac1986
Suppress deprecation
heyams Aug 20, 2024
d4aedae
Fix deprecation
heyams Aug 20, 2024
eedb882
Fix span name for vertxRedisClient
heyams Aug 21, 2024
fea0cc7
Fix
heyams Aug 21, 2024
844f068
Fix network_type
heyams Aug 28, 2024
7418c42
Fix cassandra tests
heyams Aug 28, 2024
9f1412e
Fix cassandraClient test
heyams Aug 28, 2024
02dab03
Fix RedissonClientTest
heyams Aug 29, 2024
267ea56
Fix db.statement vs. db.query.text
heyams Aug 29, 2024
08d4ffd
Fix
heyams Aug 29, 2024
e7dba95
Fix AbstractRedissonAsyncClientTest
heyams Aug 29, 2024
630ae93
Fix
heyams Aug 29, 2024
2db670b
Fix couchbase tests
heyams Aug 29, 2024
52a654b
Fix
heyams Aug 29, 2024
4bad928
Fix cassandraclienttest 3.0
heyams Aug 29, 2024
d387c64
Fix cassandra sync test
heyams Aug 30, 2024
ef407b4
Fix
heyams Aug 30, 2024
5d942c3
Fix
heyams Aug 30, 2024
e105565
Fix
heyams Aug 30, 2024
0caa7aa
Deprecate getUser and getConnectionString
heyams Sep 9, 2024
5cf662c
Deprecate getOperation and getStatement
heyams Sep 9, 2024
d563d8e
Revert
heyams Sep 9, 2024
5595a6f
Remove supressionWarning
heyams Sep 9, 2024
1e951ef
Fix
heyams Sep 9, 2024
f30ff36
Fix
heyams Sep 10, 2024
39694d4
Fix deprecation
heyams Sep 10, 2024
463795f
Fix
heyams Sep 10, 2024
b973402
Fix
heyams Sep 10, 2024
e4b9235
Fix
heyams Sep 10, 2024
7a99334
Fix couchbase tests
heyams Sep 13, 2024
65ea5fb
Fix
heyams Sep 13, 2024
c7ec850
Fix
heyams Sep 16, 2024
7553f8e
Fix
heyams Sep 16, 2024
e743724
Rename getOperationName to getDbOperationName
heyams Sep 17, 2024
59abf36
Rename getNamespace to getDbNamespace
heyams Sep 17, 2024
f9120c5
Deprecate getSystem and introduce getDbSystem
heyams Sep 17, 2024
b4aaa84
Delete SemconvStability.getAttributeKey
heyams Sep 17, 2024
c737e88
Fix unused var
heyams Sep 17, 2024
b65bf89
Address comments
heyams Sep 30, 2024
0b635f4
Revert
heyams Sep 30, 2024
bcc81e2
Use default method and only implement the new methods
heyams Sep 30, 2024
1015c37
Fix tests
heyams Sep 30, 2024
e5c0806
Fix
heyams Sep 30, 2024
72c426d
Comments
heyams Oct 1, 2024
f884994
Comments
heyams Oct 2, 2024
e527073
Reorder annotation
heyams Oct 2, 2024
43745f9
Be consistent
heyams Oct 2, 2024
aba9d32
Reduce the number of unnecessary diffs
trask Oct 2, 2024
da55c3b
spotless
trask Oct 2, 2024
3b2da5b
oops
trask Oct 2, 2024
41eded3
Rename
heyams Oct 2, 2024
618b7ae
Comments
heyams Oct 3, 2024
d12901c
Fix
heyams Oct 3, 2024
1005ef9
Update instrumentation/cassandra/cassandra-3.0/javaagent/src/main/jav…
trask Oct 3, 2024
23511d7
Reduce unnecessary diffs
trask Oct 3, 2024
a17b1d2
Capture db.namespace in the db attributes getter
trask Oct 3, 2024
76e277b
Reduce diffs
trask Oct 3, 2024
98d20fc
Remove incorrect mapping
trask Oct 3, 2024
535b06f
spotless
trask Oct 3, 2024
b7a2f1d
fixup! Capture db.namespace in the db attributes getter
trask Oct 3, 2024
e610e5a
test stable semconv
trask Oct 3, 2024
96904fc
spotless
trask Oct 3, 2024
30bb310
Emit both db.collection.name and db.sql.table under database/dup
trask Oct 4, 2024
e691bd2
database/dup tests aren't running and fixes
trask Oct 4, 2024
10ca2ea
comment
trask Oct 4, 2024
b774178
simplify
trask Oct 4, 2024
6eea8fe
spotless
trask Oct 6, 2024
c08e617
Remove network attributes not present in stable semconv
trask Oct 6, 2024
043f4f9
Simplify test
trask Oct 6, 2024
48fd7ef
Handle database/dup
trask Oct 6, 2024
d327900
Simplify test
trask Oct 6, 2024
996d150
spotless
trask Oct 6, 2024
151019b
Remove unnecessary diff
trask Oct 6, 2024
8717d51
simplify
trask Oct 6, 2024
ed8133f
Fix stable semconv assertion
trask Oct 7, 2024
4cc0a8f
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
trask Oct 26, 2024
038fbec
Remove jvm arg from module with no tests
trask Oct 27, 2024
d580bba
not general network conventions
trask Oct 28, 2024
9e34fe1
revert a bit, will implement differently later
trask Oct 28, 2024
51b318c
fixup! revert a bit, will implement differently later
trask Oct 28, 2024
a7257ea
Merge remote-tracking branch 'upstream/main' into heya/implement-data…
trask Oct 28, 2024
b6b1150
feedback
trask Oct 28, 2024
49a67c4
Fix CI
trask Oct 28, 2024
468ec83
Fix
trask Oct 28, 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
13 changes: 13 additions & 0 deletions instrumentation-api-incubator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ tasks {
sourcesJar {
dependsOn("generateJflex")
}

val testStableSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database")
}

val testBothSemconv by registering(Test::class) {
jvmArgs("-Dotel.semconv-stability.opt-in=database/dup")
}

check {
dependsOn(testStableSemconv)
dependsOn(testBothSemconv)
}
}
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 @@ -42,7 +47,13 @@ public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
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.getDbQueryText(request));
internalSet(attributes, DB_OPERATION, getter.getDbOperationName(request));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,33 @@
*/
public interface DbClientAttributesGetter<REQUEST> extends DbClientCommonAttributesGetter<REQUEST> {

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

// TODO: make this required to implement
@Nullable
String getOperation(REQUEST request);
default String getDbQueryText(REQUEST request) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
return getStatement(request);
}

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

// TODO: make this required to implement
@Nullable
default String getDbOperationName(REQUEST request) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
return getOperation(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) {
internalSet(attributes, DB_SYSTEM, getter.getSystem(request));
heyams marked this conversation as resolved.
Show resolved Hide resolved
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.getDbSystem(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.getDbNamespace(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,38 @@
/** An interface for getting attributes common to database clients. */
public interface DbClientCommonAttributesGetter<REQUEST> {

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

// TODO: make this required to implement
@Nullable
default String getDbSystem(REQUEST request) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
return getSystem(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
default String getName(REQUEST request) {
return null;
}

// TODO: make this required to implement
@Nullable
String getName(REQUEST request);
default String getDbNamespace(REQUEST request) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
return getName(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 @@ -26,7 +27,7 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(
* 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 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,9 +73,9 @@ private GenericDbClientSpanNameExtractor(DbClientAttributesGetter<REQUEST> gette

@Override
public String extract(REQUEST request) {
String dbName = getter.getName(request);
String operation = getter.getOperation(request);
return computeSpanName(dbName, operation, null);
String namespace = getter.getDbNamespace(request);
String operationName = getter.getDbOperationName(request);
return computeSpanName(namespace, operationName, null);
}
}

Expand All @@ -92,10 +93,10 @@ private SqlClientSpanNameExtractor(SqlClientAttributesGetter<REQUEST> getter) {

@Override
public String extract(REQUEST request) {
String dbName = getter.getName(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawStatement(request));
String namespace = getter.getDbNamespace(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(getter.getRawQueryText(request));
return computeSpanName(
dbName, sanitizedStatement.getOperation(), sanitizedStatement.getMainIdentifier());
namespace, sanitizedStatement.getOperation(), sanitizedStatement.getMainIdentifier());
}
}
}
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,12 @@ 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");
private static final AttributeKey<String> DB_COLLECTION_NAME =
AttributeKey.stringKey("db.collection.name");

/** Creates the SQL client attributes extractor with default configuration. */
public static <REQUEST, RESPONSE> AttributesExtractor<REQUEST, RESPONSE> create(
Expand All @@ -49,32 +55,46 @@ public static <REQUEST, RESPONSE> SqlClientAttributesExtractorBuilder<REQUEST, R
// sanitizer is also used to extract operation and table name, so we have it always enable here
private static final SqlStatementSanitizer sanitizer = SqlStatementSanitizer.create(true);

private final AttributeKey<String> dbTableAttribute;
private final AttributeKey<String> oldSemconvTableAttribute;
private final boolean statementSanitizationEnabled;

SqlClientAttributesExtractor(
SqlClientAttributesGetter<REQUEST> getter,
AttributeKey<String> dbTableAttribute,
AttributeKey<String> oldSemconvTableAttribute,
boolean statementSanitizationEnabled) {
super(getter);
this.dbTableAttribute = dbTableAttribute;
this.oldSemconvTableAttribute = oldSemconvTableAttribute;
this.statementSanitizationEnabled = statementSanitizationEnabled;
}

@Override
public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST request) {
super.onStart(attributes, parentContext, request);

String rawStatement = getter.getRawStatement(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawStatement);
String rawQueryText = getter.getRawQueryText(request);
SqlStatementInfo sanitizedStatement = sanitizer.sanitize(rawQueryText);
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() : rawQueryText);
internalSet(attributes, DB_OPERATION_NAME, operation);
}
if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(
attributes,
DB_STATEMENT,
statementSanitizationEnabled ? sanitizedStatement.getFullStatement() : rawQueryText);
internalSet(attributes, DB_OPERATION, operation);
}
if (!SQL_CALL.equals(operation)) {
internalSet(attributes, dbTableAttribute, sanitizedStatement.getMainIdentifier());
if (SemconvStability.emitStableDatabaseSemconv()) {
internalSet(attributes, DB_COLLECTION_NAME, sanitizedStatement.getMainIdentifier());
}
if (SemconvStability.emitOldDatabaseSemconv()) {
internalSet(attributes, oldSemconvTableAttribute, sanitizedStatement.getMainIdentifier());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,21 @@ public final class SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> {
private static final AttributeKey<String> DB_SQL_TABLE = AttributeKey.stringKey("db.sql.table");

final SqlClientAttributesGetter<REQUEST> getter;
AttributeKey<String> dbTableAttribute = DB_SQL_TABLE;
AttributeKey<String> oldSemconvTableAttribute = DB_SQL_TABLE;
boolean statementSanitizationEnabled = true;

SqlClientAttributesExtractorBuilder(SqlClientAttributesGetter<REQUEST> getter) {
this.getter = getter;
}

/**
* Configures the extractor to set the table value extracted by the {@link
* SqlClientAttributesExtractor} under the {@code dbTableAttribute} key. By default, the <code>
* db.sql.table</code> attribute is used.
*
* @param dbTableAttribute The {@link AttributeKey} under which the table extracted by the {@link
* SqlClientAttributesExtractor} will be stored.
* @deprecated not needed anymore since the new semantic conventions always use db.collection.name
*/
@CanIgnoreReturnValue
@Deprecated
public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setTableAttribute(
AttributeKey<String> dbTableAttribute) {
this.dbTableAttribute = requireNonNull(dbTableAttribute);
AttributeKey<String> oldSemconvTableAttribute) {
this.oldSemconvTableAttribute = requireNonNull(oldSemconvTableAttribute);
return this;
}

Expand All @@ -58,6 +54,6 @@ public SqlClientAttributesExtractorBuilder<REQUEST, RESPONSE> setStatementSaniti
*/
public AttributesExtractor<REQUEST, RESPONSE> build() {
return new SqlClientAttributesExtractor<>(
getter, dbTableAttribute, statementSanitizationEnabled);
getter, oldSemconvTableAttribute, statementSanitizationEnabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,18 @@ 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);
default String getRawStatement(REQUEST request) {
return null;
}

// TODO: make this required to implement
@Nullable
default String getRawQueryText(REQUEST request) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
return getRawStatement(request);
}
}
Loading
Loading