@@ -39,7 +39,10 @@ public final class TracingUtils {
3939 * @param value the value of the annotation
4040 */
4141 public static void putAnnotation (String key , String value ) {
42- validateAnnotationKey (key );
42+ if (!isValidateAnnotationKey (key )) {
43+ LOG .warn ("Ignoring annotation with unsupported characters in key: {}" , key );
44+ return ;
45+ }
4346 AWSXRay .getCurrentSubsegmentOptional ()
4447 .ifPresent (segment -> segment .putAnnotation (key , value ));
4548 }
@@ -51,15 +54,22 @@ public static void putAnnotation(String key, String value) {
5154 * @param value the value of the annotation
5255 */
5356 public static void putAnnotation (String key , Number value ) {
54- validateAnnotationKey (key );
57+ if (!isValidateAnnotationKey (key )) {
58+ LOG .warn ("Ignoring annotation with unsupported characters in key: {}" , key );
59+ return ;
60+ }
5561 AWSXRay .getCurrentSubsegmentOptional ()
5662 .ifPresent (segment -> segment .putAnnotation (key , value ));
5763 }
5864
59- private static void validateAnnotationKey (String key ) {
60- if (!key .matches ("^[a-zA-Z0-9_]+$" )) {
61- LOG .warn ("ignoring annotation with unsupported characters in key: {}" , key );
62- }
65+ /**
66+ Make sure that the annotation key is valid according to
67+ <a href='https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-annotations'>the documentation</a>.
68+
69+ Annotation keys that are added that are invalid are ignored by x-ray.
70+ **/
71+ private static boolean isValidateAnnotationKey (String key ) {
72+ return key .matches ("^[a-zA-Z0-9_]+$" );
6373 }
6474
6575 /**
0 commit comments