Skip to content

Commit 0dd955a

Browse files
authored
feat: #421 Support for Boolean and Number type as value in TracingUtils putAnnotation (#423)
1 parent 640bf87 commit 0dd955a

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/TracingUtils.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public final class TracingUtils {
3030

3131
/**
32-
* Put an annotation to the current subsegment.
32+
* Put an annotation to the current subsegment with a String value.
3333
*
3434
* @param key the key of the annotation
3535
* @param value the value of the annotation
@@ -39,6 +39,28 @@ public static void putAnnotation(String key, String value) {
3939
.ifPresent(segment -> segment.putAnnotation(key, value));
4040
}
4141

42+
/**
43+
* Put an annotation to the current subsegment with a Number value.
44+
*
45+
* @param key the key of the annotation
46+
* @param value the value of the annotation
47+
*/
48+
public static void putAnnotation(String key, Number value) {
49+
AWSXRay.getCurrentSubsegmentOptional()
50+
.ifPresent(segment -> segment.putAnnotation(key, value));
51+
}
52+
53+
/**
54+
* Put an annotation to the current subsegment with a Boolean value.
55+
*
56+
* @param key the key of the annotation
57+
* @param value the value of the annotation
58+
*/
59+
public static void putAnnotation(String key, Boolean value) {
60+
AWSXRay.getCurrentSubsegmentOptional()
61+
.ifPresent(segment -> segment.putAnnotation(key, value));
62+
}
63+
4264
/**
4365
* Put additional metadata for the current subsegment.
4466
*

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/TracingUtilsTest.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222

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

48-
TracingUtils.putAnnotation("key", "val");
49+
TracingUtils.putAnnotation("stringKey", "val");
50+
TracingUtils.putAnnotation("numberKey", 10);
51+
TracingUtils.putAnnotation("booleanKey", false);
4952

5053
assertThat(AWSXRay.getTraceEntity().getAnnotations())
51-
.hasSize(1)
52-
.containsEntry("key", "val");
54+
.hasSize(3)
55+
.contains(
56+
entry("stringKey", "val"),
57+
entry("numberKey", 10),
58+
entry("booleanKey", false)
59+
);
5360
}
5461

5562
@Test

0 commit comments

Comments
 (0)