-
Notifications
You must be signed in to change notification settings - Fork 64
[semconv]: Add support for new formal DB semantic convention keys #1162
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,6 +15,10 @@ | |||||
|
||||||
package software.amazon.opentelemetry.javaagent.providers; | ||||||
|
||||||
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE; | ||||||
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_NAME; | ||||||
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_TEXT; | ||||||
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME; | ||||||
import static io.opentelemetry.semconv.HttpAttributes.HTTP_REQUEST_METHOD; | ||||||
import static io.opentelemetry.semconv.HttpAttributes.HTTP_RESPONSE_STATUS_CODE; | ||||||
import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; | ||||||
|
@@ -26,7 +30,6 @@ | |||||
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.34.0/semconv-incubating/src/main/java/io/opentelemetry/semconv/incubating/DbIncubatingAttributes.java#L322-L327 | ||||||
// They have been replaced with new keys: | ||||||
// https://github.com/open-telemetry/semantic-conventions-java/blob/release/v1.34.0/semconv/src/main/java/io/opentelemetry/semconv/DbAttributes.java#L77 | ||||||
// TODO: Supporting new keys. Cannot do this now as new keys are not available in OTel Agent 2.11. | ||||||
// TODO: Delete deprecated keys once they no longer exist in binding version of the upstream code. | ||||||
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_CONNECTION_STRING; | ||||||
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; | ||||||
|
@@ -93,6 +96,7 @@ | |||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_OPERATION; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_OPERATION; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.UNKNOWN_REMOTE_SERVICE; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.getKeyValueWithFallback; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isAwsSDKSpan; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isDBSpan; | ||||||
import static software.amazon.opentelemetry.javaagent.providers.AwsSpanProcessingUtil.isKeyPresent; | ||||||
|
@@ -285,11 +289,12 @@ private static void setRemoteServiceAndOperation(SpanData span, AttributesBuilde | |||||
remoteOperation = getRemoteOperation(span, RPC_METHOD); | ||||||
|
||||||
} else if (isDBSpan(span)) { | ||||||
remoteService = getRemoteService(span, DB_SYSTEM); | ||||||
if (isKeyPresent(span, DB_OPERATION)) { | ||||||
remoteOperation = getRemoteOperation(span, DB_OPERATION); | ||||||
remoteService = getRemoteServiceWithFallback(span, DB_SYSTEM_NAME, DB_SYSTEM); | ||||||
if (isKeyPresentWithFallback(span, DB_OPERATION_NAME, DB_OPERATION)) { | ||||||
remoteOperation = getRemoteOperationWithFallback(span, DB_OPERATION_NAME, DB_OPERATION); | ||||||
} else { | ||||||
remoteOperation = getDBStatementRemoteOperation(span, DB_STATEMENT); | ||||||
String dbStatement = getKeyValueWithFallback(span, DB_QUERY_TEXT, DB_STATEMENT); | ||||||
remoteOperation = getDBStatementRemoteOperation(span, dbStatement); | ||||||
} | ||||||
} else if (isKeyPresent(span, FAAS_INVOKED_NAME) || isKeyPresent(span, FAAS_TRIGGER)) { | ||||||
remoteService = getRemoteService(span, FAAS_INVOKED_NAME); | ||||||
|
@@ -349,10 +354,7 @@ private static void setRemoteEnvironment(SpanData span, AttributesBuilder builde | |||||
private static String generateRemoteOperation(SpanData span) { | ||||||
String remoteOperation = UNKNOWN_REMOTE_OPERATION; | ||||||
if (isKeyPresent(span, URL_FULL) || isKeyPresent(span, HTTP_URL)) { | ||||||
String httpUrl = | ||||||
isKeyPresent(span, URL_FULL) | ||||||
? span.getAttributes().get(URL_FULL) | ||||||
: span.getAttributes().get(HTTP_URL); | ||||||
String httpUrl = getKeyValueWithFallback(span, URL_FULL, HTTP_URL); | ||||||
try { | ||||||
URL url; | ||||||
if (httpUrl != null) { | ||||||
|
@@ -363,11 +365,8 @@ private static String generateRemoteOperation(SpanData span) { | |||||
logger.log(Level.FINEST, "invalid http.url attribute: ", httpUrl); | ||||||
} | ||||||
} | ||||||
if (isKeyPresent(span, HTTP_REQUEST_METHOD) || isKeyPresent(span, HTTP_METHOD)) { | ||||||
String httpMethod = | ||||||
isKeyPresent(span, HTTP_REQUEST_METHOD) | ||||||
? span.getAttributes().get(HTTP_REQUEST_METHOD) | ||||||
: span.getAttributes().get(HTTP_METHOD); | ||||||
if (isKeyPresentWithFallback(span, HTTP_REQUEST_METHOD, HTTP_METHOD)) { | ||||||
String httpMethod = getKeyValueWithFallback(span, HTTP_REQUEST_METHOD, HTTP_METHOD); | ||||||
remoteOperation = httpMethod + " " + remoteOperation; | ||||||
} | ||||||
if (remoteOperation.equals(UNKNOWN_REMOTE_OPERATION)) { | ||||||
|
@@ -791,7 +790,7 @@ private static Optional<String> getSnsResourceNameFromArn(Optional<String> strin | |||||
* provided. | ||||||
*/ | ||||||
private static Optional<String> getDbConnection(SpanData span) { | ||||||
String dbName = span.getAttributes().get(DB_NAME); | ||||||
String dbName = getKeyValueWithFallback(span, DB_NAMESPACE, DB_NAME); | ||||||
Optional<String> dbConnection = Optional.empty(); | ||||||
|
||||||
if (isKeyPresent(span, SERVER_ADDRESS)) { | ||||||
|
@@ -949,6 +948,15 @@ private static String getRemoteService(SpanData span, AttributeKey<String> remot | |||||
return remoteService; | ||||||
} | ||||||
|
||||||
static String getRemoteServiceWithFallback( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not blocking: you could just update the signature of |
||||||
SpanData span, AttributeKey<String> remoteSvcKey, AttributeKey<String> remoteSvcFallbackKey) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets try to follow class convention, don't abbreviate:
Suggested change
|
||||||
String remoteService = span.getAttributes().get(remoteSvcKey); | ||||||
if (remoteService == null) { | ||||||
return getRemoteService(span, remoteSvcFallbackKey); | ||||||
} | ||||||
return remoteService; | ||||||
} | ||||||
|
||||||
private static String getRemoteOperation(SpanData span, AttributeKey<String> remoteOperationKey) { | ||||||
String remoteOperation = span.getAttributes().get(remoteOperationKey); | ||||||
if (remoteOperation == null) { | ||||||
|
@@ -972,9 +980,8 @@ static String getRemoteOperationWithFallback( | |||||
* statement and compare to a regex list of known SQL keywords. The substring length is determined | ||||||
* by the longest known SQL keywords. | ||||||
*/ | ||||||
private static String getDBStatementRemoteOperation( | ||||||
SpanData span, AttributeKey<String> remoteOperationKey) { | ||||||
String remoteOperation = span.getAttributes().get(remoteOperationKey); | ||||||
private static String getDBStatementRemoteOperation(SpanData span, String dbStatement) { | ||||||
String remoteOperation = dbStatement; | ||||||
if (remoteOperation == null) { | ||||||
remoteOperation = UNKNOWN_REMOTE_OPERATION; | ||||||
} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests in this class are intentionally robust as the logic is complex and we really want to be sure what it is doing. Lets take the effort and update relevant tests with these new variables. Namely:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking: If you're changing the below code, may as well update this code to use
isKeyPresentWithFallback
.