Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public final class TracingUtils {

/**
* Put an annotation to the current subsegment.
* Put an annotation to the current subsegment with a String value.
*
* @param key the key of the annotation
* @param value the value of the annotation
Expand All @@ -39,6 +39,28 @@ public static void putAnnotation(String key, String value) {
.ifPresent(segment -> segment.putAnnotation(key, value));
}

/**
* Put an annotation to the current subsegment with a Number value.
*
* @param key the key of the annotation
* @param value the value of the annotation
*/
public static void putAnnotation(String key, Number value) {
AWSXRay.getCurrentSubsegmentOptional()
.ifPresent(segment -> segment.putAnnotation(key, value));
}

/**
* Put an annotation to the current subsegment with a Boolean value.
*
* @param key the key of the annotation
* @param value the value of the annotation
*/
public static void putAnnotation(String key, Boolean value) {
AWSXRay.getCurrentSubsegmentOptional()
.ifPresent(segment -> segment.putAnnotation(key, value));
}

/**
* Put additional metadata for the current subsegment.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static software.amazon.lambda.powertools.tracing.TracingUtils.withEntitySubsegment;
Expand All @@ -45,11 +46,17 @@ void tearDown() {
void shouldSetAnnotationOnCurrentSubSegment() {
AWSXRay.beginSubsegment("subSegment");

TracingUtils.putAnnotation("key", "val");
TracingUtils.putAnnotation("stringKey", "val");
TracingUtils.putAnnotation("numberKey", 10);
TracingUtils.putAnnotation("booleanKey", false);

assertThat(AWSXRay.getTraceEntity().getAnnotations())
.hasSize(1)
.containsEntry("key", "val");
.hasSize(3)
.contains(
entry("stringKey", "val"),
entry("numberKey", 10),
entry("booleanKey", false)
);
}

@Test
Expand Down