I have 2 applications communicating via grps. When I try to send a span context, I always get null in extracted.
Map<String, String> tracingMetadata = new HashMap<>();
tracingMetadata.put("trace-id", traceId);
tracingMetadata.put("span-id", spanId);
SpanContext extracted = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(tracingMetadata));
Therefore, I send it via metadata in ClientIntercaptor like that.
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(Metadata.Key.of("trace-id", Metadata.ASCII_STRING_MARSHALLER), traceId);
headers.put(Metadata.Key.of("span-id", Metadata.ASCII_STRING_MARSHALLER), spanId);
...
When I try to create a context span from this data, it either talks about incompatible types, or context doesn't change. In pre and after equal context.
private void injectParentContext(Span span) {
final String traceId = HeadersServerInterceptor.getTraceIdHeader();
final String spanId = HeadersServerInterceptor.getSpanIdHeader();
final Map<String, String> contextValues = new HashMap<>();
contextValues.put("x-b3-trace-id", traceId);
contextValues.put("x-b3-spanid", spanId);
final SpanContext pre=span.context();
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMapAdapter(contextValues));
final SpanContext after= span.context();
}
I tried different Format.Builtin and Adapter, nothing works.
What am I doing wrong?