use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project core-java by SpineEventEngine.
the class StreamObserversShould method return_Error_extracted_form_StatusException_metadata.
@Test
public void return_Error_extracted_form_StatusException_metadata() {
final Error expectedError = Error.getDefaultInstance();
final Metadata metadata = MetadataConverter.toMetadata(expectedError);
final StatusException statusException = INVALID_ARGUMENT.asException(metadata);
assertEquals(expectedError, StreamObservers.fromStreamError(statusException).get());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project grakn by graknlabs.
the class GrpcClient method convertStatusRuntimeException.
private static RuntimeException convertStatusRuntimeException(StatusRuntimeException error) {
Status status = error.getStatus();
Metadata trailers = error.getTrailers();
ErrorType errorType = trailers.get(ErrorType.KEY);
if (errorType != null) {
String message = status.getDescription();
return errorType.toException(message);
} else {
return error;
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project brave by openzipkin.
the class ITTracingServerInterceptor method usesExistingTraceId.
@Test
public void usesExistingTraceId() throws Exception {
final String traceId = "463ac35c9f6413ad";
final String parentId = traceId;
final String spanId = "48485a3953bb6124";
Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
super.start(responseListener, headers);
}
};
}
});
GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
Span span = spans.take();
assertThat(span.traceId()).isEqualTo(traceId);
assertThat(span.parentId()).isEqualTo(parentId);
assertThat(span.id()).isEqualTo(spanId);
assertThat(span.shared()).isTrue();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project brave by openzipkin.
the class ITTracingServerInterceptor method createsChildWhenJoinDisabled.
@Test
public void createsChildWhenJoinDisabled() throws Exception {
grpcTracing = GrpcTracing.create(tracingBuilder(NEVER_SAMPLE).supportsJoin(false).build());
init();
final String traceId = "463ac35c9f6413ad";
final String parentId = traceId;
final String spanId = "48485a3953bb6124";
Channel channel = ClientInterceptors.intercept(client, new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(Key.of("X-B3-TraceId", ASCII_STRING_MARSHALLER), traceId);
headers.put(Key.of("X-B3-ParentSpanId", ASCII_STRING_MARSHALLER), parentId);
headers.put(Key.of("X-B3-SpanId", ASCII_STRING_MARSHALLER), spanId);
headers.put(Key.of("X-B3-Sampled", ASCII_STRING_MARSHALLER), "1");
super.start(responseListener, headers);
}
};
}
});
GreeterGrpc.newBlockingStub(channel).sayHello(HELLO_REQUEST);
Span span = spans.take();
assertThat(span.traceId()).isEqualTo(traceId);
assertThat(span.parentId()).isEqualTo(spanId);
assertThat(span.id()).isNotEqualTo(spanId);
assertThat(span.shared()).isNull();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Metadata in project incubator-skywalking by apache.
the class StreamCallClientInterceptor method start.
@Override
public void start(Listener responseListener, Metadata headers) {
final ContextCarrier contextCarrier = new ContextCarrier();
final AbstractSpan span = ContextManager.createExitSpan(serviceName, contextCarrier, remotePeer);
span.setComponent(ComponentsDefine.GRPC);
SpanLayer.asRPCFramework(span);
CarrierItem contextItem = contextCarrier.items();
while (contextItem.hasNext()) {
contextItem = contextItem.next();
Metadata.Key<String> headerKey = Metadata.Key.of(contextItem.getHeadKey(), Metadata.ASCII_STRING_MARSHALLER);
headers.put(headerKey, contextItem.getHeadValue());
}
delegate().start(new CallListener(responseListener, ContextManager.capture()), headers);
ContextManager.stopSpan();
}
Aggregations