Skip to content

Commit 2c33019

Browse files
committed
updated tests according to comments
1 parent 9b5c5ab commit 2c33019

File tree

1 file changed

+57
-28
lines changed

1 file changed

+57
-28
lines changed

aws-xray/src/test/java/io/opentelemetry/contrib/awsxray/SamplingRuleApplierTest.java

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.opentelemetry.sdk.trace.samplers.SamplingDecision;
3131
import io.opentelemetry.sdk.trace.samplers.SamplingResult;
3232
import io.opentelemetry.semconv.HttpAttributes;
33+
import io.opentelemetry.semconv.ServerAttributes;
3334
import io.opentelemetry.semconv.UrlAttributes;
3435
import io.opentelemetry.semconv.incubating.CloudIncubatingAttributes;
3536
import java.io.IOException;
@@ -74,10 +75,10 @@ class ExactMatch {
7475
.put(AttributeKey.longKey("speed"), 10)
7576
.build();
7677

77-
private final Attributes newSemCovAttributes =
78+
private final Attributes stableSemConvAttributes =
7879
Attributes.builder()
7980
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET")
80-
.put(NET_HOST_NAME, "opentelemetry.io")
81+
.put(ServerAttributes.SERVER_ADDRESS, "opentelemetry.io")
8182
.put(UrlAttributes.URL_PATH, "/instrument-me")
8283
.put(AttributeKey.stringKey("animal"), "cat")
8384
.put(AttributeKey.longKey("speed"), 10)
@@ -132,10 +133,10 @@ void matches() {
132133
}
133134

134135
@Test
135-
void matchesURLFullNewSemCov() {
136-
assertThat(applier.matches(newSemCovAttributes, resource)).isTrue();
136+
void matchesURLFullStableSemConv() {
137+
assertThat(applier.matches(stableSemConvAttributes, resource)).isTrue();
137138

138-
// http.url works too
139+
// url.full works too
139140
assertThat(
140141
applier.matches(
141142
attributes.toBuilder()
@@ -167,9 +168,9 @@ void methodNotMatch() {
167168
}
168169

169170
@Test
170-
void methodNewSemCovNotMatch() {
171+
void methodStableSemConvNotMatch() {
171172
Attributes attributes =
172-
this.newSemCovAttributes.toBuilder()
173+
this.stableSemConvAttributes.toBuilder()
173174
.put(HttpAttributes.HTTP_REQUEST_METHOD, "POST")
174175
.build();
175176
assertThat(applier.matches(attributes, resource)).isFalse();
@@ -213,20 +214,20 @@ void pathNotMatch() {
213214
}
214215

215216
@Test
216-
void pathNewSemCovNotMatch() {
217+
void pathStableSemConvNotMatch() {
217218
Attributes attributes =
218-
this.newSemCovAttributes.toBuilder()
219+
this.stableSemConvAttributes.toBuilder()
219220
.put(UrlAttributes.URL_PATH, "/instrument-you")
220221
.build();
221222
assertThat(applier.matches(attributes, resource)).isFalse();
222223
attributes =
223-
this.newSemCovAttributes.toBuilder()
224+
this.stableSemConvAttributes.toBuilder()
224225
.remove(UrlAttributes.URL_PATH)
225226
.put(UrlAttributes.URL_FULL, "scheme://host:port/instrument-you")
226227
.build();
227228
assertThat(applier.matches(attributes, resource)).isFalse();
228229
attributes =
229-
this.newSemCovAttributes.toBuilder()
230+
this.stableSemConvAttributes.toBuilder()
230231
.remove(UrlAttributes.URL_PATH)
231232
.put(UrlAttributes.URL_FULL, "scheme://host:port")
232233
.build();
@@ -235,7 +236,7 @@ void pathNewSemCovNotMatch() {
235236
// Correct path, but we ignore anyways since the URL is malformed per spec, scheme is always
236237
// present.
237238
attributes =
238-
this.newSemCovAttributes.toBuilder()
239+
this.stableSemConvAttributes.toBuilder()
239240
.remove(UrlAttributes.URL_PATH)
240241
.put(UrlAttributes.URL_FULL, "host:port/instrument-me")
241242
.build();
@@ -300,10 +301,10 @@ class WildcardMatch {
300301
.put(AttributeKey.longKey("speed"), 10)
301302
.build();
302303

303-
private final Attributes newSemCovAttributes =
304+
private final Attributes stableSemConvAttributes =
304305
Attributes.builder()
305306
.put(HttpAttributes.HTTP_REQUEST_METHOD, "GET")
306-
.put(NET_HOST_NAME, "opentelemetry.io")
307+
.put(ServerAttributes.SERVER_ADDRESS, "opentelemetry.io")
307308
.put(UrlAttributes.URL_PATH, "/instrument-me?foo=bar&cat=meow")
308309
.put(AttributeKey.stringKey("animal"), "cat")
309310
.put(AttributeKey.longKey("speed"), 10)
@@ -392,26 +393,26 @@ void methodNotMatch() {
392393
}
393394

394395
@Test
395-
void newSemCovMethodMatches() {
396+
void stableSemConvMethodMatches() {
396397
Attributes attributes =
397-
this.newSemCovAttributes.toBuilder()
398+
this.stableSemConvAttributes.toBuilder()
398399
.put(HttpAttributes.HTTP_REQUEST_METHOD, "BADGETGOOD")
399400
.build();
400401
assertThat(applier.matches(attributes, resource)).isTrue();
401402
attributes =
402-
newSemCovAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "BADGET").build();
403+
stableSemConvAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "BADGET").build();
403404
assertThat(applier.matches(attributes, resource)).isTrue();
404405
attributes =
405-
newSemCovAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "GETGET").build();
406+
stableSemConvAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "GETGET").build();
406407
assertThat(applier.matches(attributes, resource)).isTrue();
407408
}
408409

409410
@Test
410-
void newSemCovMethodNotMatch() {
411+
void stableSemConvMethodNotMatch() {
411412
Attributes attributes =
412-
newSemCovAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "POST").build();
413+
stableSemConvAttributes.toBuilder().put(HttpAttributes.HTTP_REQUEST_METHOD, "POST").build();
413414
assertThat(applier.matches(attributes, resource)).isFalse();
414-
attributes = removeAttribute(newSemCovAttributes, HttpAttributes.HTTP_REQUEST_METHOD);
415+
attributes = removeAttribute(stableSemConvAttributes, HttpAttributes.HTTP_REQUEST_METHOD);
415416
assertThat(applier.matches(attributes, resource)).isFalse();
416417
}
417418

@@ -443,6 +444,34 @@ void hostNotMatch() {
443444
assertThat(applier.matches(attributes, resource)).isFalse();
444445
}
445446

447+
@Test
448+
void stableSemConvHostMatches() {
449+
Attributes attributes =
450+
this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "alpha.opentelemetry.io").build();
451+
assertThat(applier.matches(attributes, resource)).isTrue();
452+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opfdnqtelemetry.io").build();
453+
assertThat(applier.matches(attributes, resource)).isTrue();
454+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opentglemetry.io").build();
455+
assertThat(applier.matches(attributes, resource)).isTrue();
456+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opentglemry.io").build();
457+
assertThat(applier.matches(attributes, resource)).isTrue();
458+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opentglemrz.io").build();
459+
assertThat(applier.matches(attributes, resource)).isTrue();
460+
}
461+
462+
@Test
463+
void stableSemConvHostNotMatch() {
464+
Attributes attributes =
465+
this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opentelemetryfio").build();
466+
assertThat(applier.matches(attributes, resource)).isFalse();
467+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "opentgalemetry.io").build();
468+
assertThat(applier.matches(attributes, resource)).isFalse();
469+
attributes = this.stableSemConvAttributes.toBuilder().put(ServerAttributes.SERVER_ADDRESS, "alpha.oentelemetry.io").build();
470+
assertThat(applier.matches(attributes, resource)).isFalse();
471+
attributes = removeAttribute(this.stableSemConvAttributes, ServerAttributes.SERVER_ADDRESS);
472+
assertThat(applier.matches(attributes, resource)).isFalse();
473+
}
474+
446475
@Test
447476
void pathMatches() {
448477
Attributes attributes =
@@ -467,33 +496,33 @@ void pathNotMatch() {
467496
}
468497

469498
@Test
470-
void pathNewSemCovMatches() {
499+
void pathStableSemConvMatches() {
471500
Attributes attributes =
472-
newSemCovAttributes.toBuilder()
501+
stableSemConvAttributes.toBuilder()
473502
.put(UrlAttributes.URL_PATH, "/instrument-me?foo=bar&cat=")
474503
.build();
475504
assertThat(applier.matches(attributes, resource)).isTrue();
476505
// Deceptive question mark, it's actually a wildcard :-)
477506
attributes =
478-
newSemCovAttributes.toBuilder()
507+
stableSemConvAttributes.toBuilder()
479508
.put(UrlAttributes.URL_PATH, "/instrument-meafoo=bar&cat=")
480509
.build();
481510
assertThat(applier.matches(attributes, resource)).isTrue();
482511
}
483512

484513
@Test
485-
void pathNewSemCovNotMatch() {
514+
void pathStableSemConvNotMatch() {
486515
Attributes attributes =
487-
newSemCovAttributes.toBuilder()
516+
stableSemConvAttributes.toBuilder()
488517
.put(UrlAttributes.URL_PATH, "/instrument-mea?foo=bar&cat=")
489518
.build();
490519
assertThat(applier.matches(attributes, resource)).isFalse();
491520
attributes =
492-
newSemCovAttributes.toBuilder()
521+
stableSemConvAttributes.toBuilder()
493522
.put(UrlAttributes.URL_PATH, "foo/instrument-meafoo=bar&cat=")
494523
.build();
495524
assertThat(applier.matches(attributes, resource)).isFalse();
496-
attributes = removeAttribute(newSemCovAttributes, UrlAttributes.URL_PATH);
525+
attributes = removeAttribute(stableSemConvAttributes, UrlAttributes.URL_PATH);
497526
assertThat(applier.matches(attributes, resource)).isFalse();
498527
}
499528

0 commit comments

Comments
 (0)