use of brave.baggage.BaggagePropagationConfig.SingleBaggageField in project brave by openzipkin.
the class BaggagePropagationTest method dupesNotOk.
@Test
public void dupesNotOk() {
SingleBaggageField userIdConfig = SingleBaggageField.local(BaggageField.create("userId"));
BaggagePropagation.FactoryBuilder builder = newFactoryBuilder(B3Propagation.FACTORY).add(userIdConfig);
assertThatThrownBy(() -> builder.add(userIdConfig)).isInstanceOf(IllegalArgumentException.class);
}
use of brave.baggage.BaggagePropagationConfig.SingleBaggageField in project brave by openzipkin.
the class BaggagePropagationTest method extract_field_multiple_key_names.
@Test
public void extract_field_multiple_key_names() {
// switch to case insensitive as this example is about http :P
request = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
BaggageField userId = BaggageField.create("userId");
BaggageField sessionId = BaggageField.create("sessionId");
SingleBaggageField userIdConfig = SingleBaggageField.newBuilder(userId).addKeyName("baggage-userId").addKeyName("baggage_userId").build();
SingleBaggageField sessionIdConfig = SingleBaggageField.newBuilder(sessionId).addKeyName("baggage-sessionId").addKeyName("baggage_sessionId").build();
factory = newFactoryBuilder(B3Propagation.FACTORY).add(userIdConfig).add(sessionIdConfig).build();
initialize();
injector.inject(context, request);
request.put("baggage-userId", "bob");
request.put("baggage-sessionId", "12345");
context = extractor.extract(request).context();
assertThat(userId.getValue(context)).isEqualTo("bob");
assertThat(sessionId.getValue(context)).isEqualTo("12345");
}
use of brave.baggage.BaggagePropagationConfig.SingleBaggageField in project brave by openzipkin.
the class BaggagePropagationTest method newFactory_sharingRemoteName.
@Test
public void newFactory_sharingRemoteName() {
BaggagePropagation.FactoryBuilder builder = newFactoryBuilder(B3Propagation.FACTORY);
SingleBaggageField userName = SingleBaggageField.newBuilder(BaggageField.create("userName")).addKeyName("baggage").build();
SingleBaggageField userId = SingleBaggageField.newBuilder(BaggageField.create("userId")).addKeyName("baggage").build();
builder.add(userName);
assertThatThrownBy(() -> builder.add(userId)).isInstanceOf(IllegalArgumentException.class).hasMessage("Propagation key already in use: baggage");
}
use of brave.baggage.BaggagePropagationConfig.SingleBaggageField in project brave by openzipkin.
the class BaggagePropagationTest method clear_and_add.
@Test
public void clear_and_add() {
SingleBaggageField requestIdConfig = SingleBaggageField.newBuilder(vcapRequestId).addKeyName("request-id").addKeyName("request_id").build();
SingleBaggageField traceIdConfig = SingleBaggageField.remote(amznTraceId);
BaggagePropagation.FactoryBuilder builder = newFactoryBuilder(B3Propagation.FACTORY).add(requestIdConfig).add(traceIdConfig);
Set<BaggagePropagationConfig> configs = builder.configs();
builder.clear();
configs.forEach(builder::add);
assertThat(builder).usingRecursiveComparison().isEqualTo(newFactoryBuilder(B3Propagation.FACTORY).add(requestIdConfig).add(traceIdConfig));
}
use of brave.baggage.BaggagePropagationConfig.SingleBaggageField in project brave by openzipkin.
the class BaggagePropagationTest method inject_field_multiple_key_names.
@Test
public void inject_field_multiple_key_names() {
BaggageField userId = BaggageField.create("userId");
BaggageField sessionId = BaggageField.create("sessionId");
SingleBaggageField userIdConfig = SingleBaggageField.newBuilder(userId).addKeyName("userId").addKeyName("baggage-userId").addKeyName("baggage_userId").build();
SingleBaggageField sessionIdConfig = SingleBaggageField.newBuilder(sessionId).addKeyName("sessionId").addKeyName("baggage-sessionId").addKeyName("baggage_sessionId").build();
factory = newFactoryBuilder(B3SinglePropagation.FACTORY).add(userIdConfig).add(sessionIdConfig).build();
initialize();
userId.updateValue(context, "bob");
sessionId.updateValue(context, "12345");
injector.inject(context, request);
// NOTE: the labels are downcased
assertThat(request).containsOnly(entry("b3", B3SingleFormat.writeB3SingleFormat(context)), entry("userid", "bob"), entry("sessionid", "12345"), entry("baggage-userid", "bob"), entry("baggage-sessionid", "12345"), entry("baggage_userid", "bob"), entry("baggage_sessionid", "12345"));
}
Aggregations