Skip to content

Commit 2191bdc

Browse files
committed
up
1 parent 671952f commit 2191bdc

File tree

3 files changed

+21
-38
lines changed

3 files changed

+21
-38
lines changed

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

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(
2424
/**
2525
* Returns a {@link SpanNameExtractor} that constructs the span name according to DB semantic
2626
* conventions.
27-
*
28-
* @see SqlStatementInfo#getOperationName() used to extract {@code <db.operation.name>}.
29-
* @see DbClientAttributesGetter#getDbNamespace(Object) used to extract {@code <db.namespace>}.
30-
* @see SqlStatementInfo#getCollectionName() used to extract table name.
31-
* @see SqlStatementInfo#getStoredProcedureName() used to extract stored procedure name.
3227
*/
3328
public static <REQUEST> SpanNameExtractor<REQUEST> create(
3429
SqlClientAttributesGetter<REQUEST, ?> getter) {
@@ -40,32 +35,30 @@ public static <REQUEST> SpanNameExtractor<REQUEST> create(
4035
private DbClientSpanNameExtractor() {}
4136

4237
protected String computeSpanName(
43-
@Nullable String dbName,
44-
@Nullable String operation,
38+
@Nullable String namespace,
39+
@Nullable String operationName,
4540
@Nullable String collectionName,
4641
@Nullable String storedProcedureName) {
47-
// Use whichever identifier is available (they're mutually exclusive)
48-
String mainIdentifier = collectionName != null ? collectionName : storedProcedureName;
49-
50-
if (operation == null) {
51-
return dbName == null ? DEFAULT_SPAN_NAME : dbName;
42+
if (operationName == null) {
43+
return namespace == null ? DEFAULT_SPAN_NAME : namespace;
5244
}
5345

54-
StringBuilder name = new StringBuilder(operation);
55-
if (dbName != null || mainIdentifier != null) {
56-
name.append(' ');
46+
StringBuilder spanName = new StringBuilder(operationName);
47+
String mainIdentifier = collectionName != null ? collectionName : storedProcedureName;
48+
if (namespace != null || mainIdentifier != null) {
49+
spanName.append(' ');
5750
}
58-
// skip db name if mainIdentifier already has namespace prefixed to it
59-
if (dbName != null && (mainIdentifier == null || mainIdentifier.indexOf('.') == -1)) {
60-
name.append(dbName);
51+
// skip namespace if identifier already has a namespace prefixed to it
52+
if (namespace != null && (mainIdentifier == null || mainIdentifier.indexOf('.') == -1)) {
53+
spanName.append(namespace);
6154
if (mainIdentifier != null) {
62-
name.append('.');
55+
spanName.append('.');
6356
}
6457
}
6558
if (mainIdentifier != null) {
66-
name.append(mainIdentifier);
59+
spanName.append(mainIdentifier);
6760
}
68-
return name.toString();
61+
return spanName.toString();
6962
}
7063

7164
/**
@@ -191,29 +184,23 @@ public String extract(REQUEST request) {
191184
if (rawQueryTexts.size() == 1) {
192185
SqlStatementInfo sanitizedStatement =
193186
SqlStatementSanitizerUtil.sanitize(rawQueryTexts.iterator().next());
194-
String operation = sanitizedStatement.getOperationName();
187+
String operationName = sanitizedStatement.getOperationName();
195188
if (isBatch(request)) {
196-
operation = operation != null ? "BATCH " + operation : "BATCH";
189+
operationName = "BATCH " + operationName;
197190
}
198191
return computeSpanNameStable(
199192
getter,
200193
request,
201-
operation,
194+
operationName,
202195
sanitizedStatement.getCollectionName(),
203196
sanitizedStatement.getStoredProcedureName());
204197
}
205198

206199
MultiQuery multiQuery = MultiQuery.analyze(rawQueryTexts, false);
207-
String operation = multiQuery.getOperationName();
208-
if (operation != null) {
209-
operation = "BATCH " + operation;
210-
} else {
211-
operation = "BATCH";
212-
}
213200
return computeSpanNameStable(
214201
getter,
215202
request,
216-
operation,
203+
multiQuery.getOperationName(),
217204
multiQuery.getCollectionName(),
218205
multiQuery.getStoredProcedureName());
219206
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ static MultiQuery analyze(
4646
statementSanitizationEnabled ? sanitizedStatement.getQueryText() : rawQueryText);
4747
}
4848

49+
String operationName = uniqueOperationName.getValue();
4950
return new MultiQuery(
5051
uniqueCollectionName.getValue(),
5152
uniqueStoredProcedureName.getValue(),
52-
uniqueOperationName.getValue(),
53+
operationName == null ? "BATCH" : "BATCH " + operationName,
5354
uniqueQueryTexts);
5455
}
5556

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ public void onStart(AttributesBuilder attributes, Context parentContext, REQUEST
124124
MultiQuery multiQuery =
125125
MultiQuery.analyze(getter.getRawQueryTexts(request), statementSanitizationEnabled);
126126
internalSet(attributes, DB_QUERY_TEXT, join("; ", multiQuery.getQueryTexts()));
127-
128-
String operationName =
129-
multiQuery.getOperationName() != null
130-
? "BATCH " + multiQuery.getOperationName()
131-
: "BATCH";
132-
internalSet(attributes, DB_OPERATION_NAME, operationName);
127+
internalSet(attributes, DB_OPERATION_NAME, multiQuery.getOperationName());
133128
internalSet(attributes, DB_COLLECTION_NAME, multiQuery.getCollectionName());
134129
internalSet(attributes, DB_STORED_PROCEDURE_NAME, multiQuery.getStoredProcedureName());
135130
}

0 commit comments

Comments
 (0)