use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITTracingFilter_Consumer method usesParentFromInvocationTime.
/**
* This tests that the parent is determined at the time the request was made, not when the request
* was executed.
*/
@Test
public void usesParentFromInvocationTime() {
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
RpcContext.getContext().asyncCall(() -> client.get().sayHello("jorge"));
RpcContext.getContext().asyncCall(() -> client.get().sayHello("romeo"));
}
try (Scope scope = currentTraceContext.newScope(null)) {
// complete within a different scope
for (int i = 0; i < 2; i++) {
TraceContext extracted = server.takeRequest().context();
assertChildOf(extracted, parent);
}
}
// The spans may report in a different order than the requests
for (int i = 0; i < 2; i++) {
assertChildOf(testSpanHandler.takeRemoteSpan(CLIENT), parent);
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITTracingFilter_Consumer method propagatesBaggage_unsampled.
@Test
public void propagatesBaggage_unsampled() {
TraceContext parent = newTraceContext(SamplingFlags.NOT_SAMPLED);
try (Scope scope = currentTraceContext.newScope(parent)) {
BAGGAGE_FIELD.updateValue(parent, "joey");
client.get().sayHello("jorge");
}
TraceContext extracted = server.takeRequest().context();
assertThat(BAGGAGE_FIELD.getValue(extracted)).isEqualTo("joey");
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITTracingFilter_Consumer method customParser.
@Test
public void customParser() {
Tag<DubboResponse> javaValue = new Tag<DubboResponse>("dubbo.result_value") {
@Override
protected String parseValue(DubboResponse input, TraceContext context) {
Result result = input.result();
if (result == null)
return null;
Object value = result.getValue();
if (value instanceof JavaBeanDescriptor) {
return String.valueOf(((JavaBeanDescriptor) value).getProperty("value"));
}
return null;
}
};
RpcTracing rpcTracing = RpcTracing.newBuilder(tracing).clientResponseParser((res, context, span) -> {
RpcResponseParser.DEFAULT.parse(res, context, span);
if (res instanceof DubboResponse) {
javaValue.tag((DubboResponse) res, span);
}
}).build();
init().setRpcTracing(rpcTracing);
String javaResult = client.get().sayHello("jorge");
assertThat(testSpanHandler.takeRemoteSpan(CLIENT).tags()).containsEntry("dubbo.result_value", javaResult);
}
use of brave.propagation.TraceContext in project curiostack by curioswitch.
the class ServerModule method decorateService.
private static HttpService decorateService(HttpService service, Tracing tracing, Lazy<FirebaseAuthorizer> firebaseAuthorizer, Lazy<JwtAuthorizer.Factory> jwtAuthorizer, Optional<SslCommonNamesProvider> sslCommonNamesProvider, ServerConfig serverConfig, FirebaseAuthConfig authConfig) {
if (sslCommonNamesProvider.isPresent() && !serverConfig.isDisableSslAuthorization()) {
AuthServiceBuilder authServiceBuilder = AuthService.builder();
authServiceBuilder.add(new SslAuthorizer(sslCommonNamesProvider.get()));
service = service.decorate(authServiceBuilder.newDecorator());
}
if (serverConfig.isEnableIapAuthorization()) {
service = service.decorate((delegate, ctx, req) -> {
DecodedJWT jwt = ctx.attr(JwtAuthorizer.DECODED_JWT);
String loggedInUserEmail = jwt != null ? jwt.getClaim("email").asString() : "unknown";
RequestLoggingContext.put(ctx, "logged_in_user", loggedInUserEmail);
return delegate.serve(ctx, req);
}).decorate(AuthService.builder().addTokenAuthorizer(headers -> OAuth2Token.of(headers.get(HttpHeaderNames.of("x-goog-iap-jwt-assertion"))), jwtAuthorizer.get().create(Algorithm.ES256, "https://www.gstatic.com/iap/verify/public_key")).newDecorator());
}
if (!authConfig.getServiceAccountBase64().isEmpty()) {
FirebaseAuthorizer authorizer = firebaseAuthorizer.get();
service = service.decorate(AuthService.builder().addOAuth2(authorizer).onFailure(authorizer).newDecorator());
}
service = service.decorate(MetricCollectingService.newDecorator(RpcMetricLabels.grpcRequestLabeler("grpc_services"))).decorate(BraveService.newDecorator(tracing)).decorate((delegate, ctx, req) -> {
TraceContext traceCtx = tracing.currentTraceContext().get();
if (traceCtx != null) {
RequestLoggingContext.put(ctx, "traceId", traceCtx.traceIdString());
RequestLoggingContext.put(ctx, "spanId", traceCtx.spanIdString());
}
return delegate.serve(ctx, req);
});
return service;
}
use of brave.propagation.TraceContext in project reactor-netty by reactor.
the class TracingChannelOutboundHandler method flush.
@Override
@SuppressWarnings("try")
public void flush(ChannelHandlerContext ctx) {
Span span = ctx.channel().attr(SPAN_ATTR_KEY).get();
if (span != null) {
try (Scope scope = currentTraceContext.maybeScope(span.context())) {
ctx.flush();
}
return;
} else {
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
if (ops instanceof HttpClientRequest) {
TraceContext parent = ((HttpClientRequest) ops).currentContextView().getOrDefault(TraceContext.class, null);
if (parent != null) {
try (Scope scope = currentTraceContext.maybeScope(parent)) {
ctx.flush();
}
return;
}
}
}
ctx.flush();
}
Aggregations