-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance AWS DynamoDB instrumentation (#1191)
- Loading branch information
Jakub Wach
authored
Sep 18, 2020
1 parent
bc8224f
commit e8b5488
Showing
25 changed files
with
372 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ibrary/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/DbRequestDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.awssdk.v2_2; | ||
|
||
import io.opentelemetry.trace.Span; | ||
import io.opentelemetry.trace.attributes.SemanticAttributes; | ||
import software.amazon.awssdk.core.SdkRequest; | ||
import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute; | ||
|
||
final class DbRequestDecorator implements SdkRequestDecorator { | ||
|
||
@Override | ||
public void decorate(Span span, SdkRequest sdkRequest, ExecutionAttributes attributes) { | ||
|
||
span.setAttribute(SemanticAttributes.DB_SYSTEM.key(), "dynamodb"); | ||
// decorate with TableName as db.name (DynamoDB equivalent - not for batch) | ||
sdkRequest | ||
.getValueForField("TableName", String.class) | ||
.ifPresent(val -> span.setAttribute(SemanticAttributes.DB_NAME.key(), val)); | ||
|
||
String operation = attributes.getAttribute(SdkExecutionAttribute.OPERATION_NAME); | ||
if (operation != null) { | ||
span.setAttribute(SemanticAttributes.DB_OPERATION.key(), operation); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...k-2.2/library/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/RequestType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.awssdk.v2_2; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
import software.amazon.awssdk.core.SdkRequest; | ||
|
||
enum RequestType { | ||
S3("S3Request", "Bucket"), | ||
SQS("SqsRequest", "QueueUrl", "QueueName"), | ||
Kinesis("KinesisRequest", "StreamName"), | ||
DynamoDB("DynamoDbRequest", "TableName"); | ||
|
||
private final String requestClass; | ||
private final String[] fields; | ||
|
||
RequestType(String requestClass, String... fields) { | ||
this.requestClass = requestClass; | ||
this.fields = fields; | ||
} | ||
|
||
String[] getFields() { | ||
return fields; | ||
} | ||
|
||
@Nullable | ||
static RequestType ofSdkRequest(SdkRequest request) { | ||
// exact request class should be 1st level child of request type | ||
String typeName = | ||
(request.getClass().getSuperclass() == null | ||
? request.getClass() | ||
: request.getClass().getSuperclass()) | ||
.getSimpleName(); | ||
for (RequestType type : values()) { | ||
if (type.requestClass.equals(typeName)) { | ||
return type; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...brary/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/SdkRequestDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.awssdk.v2_2; | ||
|
||
import io.opentelemetry.trace.Span; | ||
import software.amazon.awssdk.core.SdkRequest; | ||
import software.amazon.awssdk.core.interceptor.ExecutionAttributes; | ||
|
||
interface SdkRequestDecorator { | ||
|
||
void decorate(Span span, SdkRequest sdkRequest, ExecutionAttributes attributes); | ||
} |
Oops, something went wrong.