io.opentracing.propagation.TextMapInject Java Examples

The following examples show how to use io.opentracing.propagation.TextMapInject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BraveTracer.java    From brave-opentracing with Apache License 2.0 6 votes vote down vote up
/**
 * Injects the underlying context using B3 encoding by default.
 */
@Override public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
  BraveSpanContext braveContext = ((BraveSpanContext) spanContext);
  if (carrier instanceof BinaryInject) {
    BinaryCodec.INSTANCE.inject(braveContext.unwrap(), (BinaryInject) carrier);
    return;
  }
  if (!(carrier instanceof TextMapInject)) {
    throw new UnsupportedOperationException(carrier + " not instanceof TextMapInject");
  }
  Kind kind = braveContext.kind;
  Injector<TextMapInject> injector = null;
  if (Kind.CLIENT.equals(kind)) {
    injector = formatToClientInjector.get(format);
  } else if (Kind.PRODUCER.equals(kind)) {
    injector = formatToProducerInjector.get(format);
  } else if (Kind.CONSUMER.equals(kind)) {
    injector = formatToConsumerInjector.get(format);
  }
  if (injector == null) injector = formatToInjector.get(format);
  if (injector == null) {
    throw new UnsupportedOperationException(format + " not in " + formatToInjector.keySet());
  }
  injector.inject(braveContext.unwrap(), (TextMapInject) carrier);
}
 
Example #2
Source File: BraveTracer.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
  if (!(carrier instanceof TextMapInject)) {
    throw new UnsupportedOperationException(carrier + " not instanceof TextMapInject");
  }
  BraveSpanContext braveContext = ((BraveSpanContext) spanContext);
  Kind kind = braveContext.kind;
  Injector<TextMapInject> injector;
  if (Kind.CLIENT.equals(kind)) {
    injector = clientInjector;
  } else if (Kind.PRODUCER.equals(kind)) {
    injector = producerInjector;
  } else if (Kind.CONSUMER.equals(kind)) {
    injector = consumerInjector;
  } else {
    injector = this.injector;
  }
  injector.inject(braveContext.context, (TextMapInject) carrier);
}
 
Example #3
Source File: Propagation.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
public void injectTextFormat(SpanContextShim contextShim, TextMapInject carrier) {
  Context context =
      TracingContextUtils.withSpan(
          DefaultSpan.create(contextShim.getSpanContext()), Context.current());
  context =
      CorrelationsContextUtils.withCorrelationContext(
          contextShim.getCorrelationContext(), context);

  propagators().getHttpTextFormat().inject(context, carrier, TextMapSetter.INSTANCE);
}
 
Example #4
Source File: TracerShim.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Override
public <C> void inject(SpanContext context, Format<C> format, C carrier) {
  if (context == null) {
    logger.log(Level.INFO, "Cannot inject a null span context.");
    return;
  }

  SpanContextShim contextShim = getContextShim(context);

  if (format == Format.Builtin.TEXT_MAP
      || format == Format.Builtin.TEXT_MAP_INJECT
      || format == Format.Builtin.HTTP_HEADERS) {
    propagation.injectTextFormat(contextShim, (TextMapInject) carrier);
  }
}
 
Example #5
Source File: MockTracer.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public <C> void inject(MockSpan.MockContext ctx, Format<C> format, C carrier) {
    if (carrier instanceof TextMapInject) {
        TextMapInject textMap = (TextMapInject) carrier;
        for (Map.Entry<String, String> entry : ctx.baggageItems()) {
            textMap.put(BAGGAGE_KEY_PREFIX + entry.getKey(), entry.getValue());
        }
        textMap.put(SPAN_ID_KEY, String.valueOf(ctx.spanId()));
        textMap.put(TRACE_ID_KEY, String.valueOf(ctx.traceId()));
    } else {
        throw new IllegalArgumentException("Unknown carrier");
    }
}
 
Example #6
Source File: MockTracer.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
@Override
public <C> void inject(MockSpan.MockContext ctx, Format<C> format, C carrier) {
    if (carrier instanceof TextMapInject) {
        TextMapInject textMap = (TextMapInject) carrier;
        for (Map.Entry<String, String> entry : ctx.baggageItems()) {
            textMap.put(BAGGAGE_KEY_PREFIX + entry.getKey(), entry.getValue());
        }
        textMap.put(SPAN_ID_KEY, String.valueOf(ctx.spanId()));
        textMap.put(TRACE_ID_KEY, String.valueOf(ctx.traceId()));
    } else {
        throw new IllegalArgumentException("Unknown carrier");
    }
}
 
Example #7
Source File: Propagation.java    From opentelemetry-java with Apache License 2.0 4 votes vote down vote up
@Override
public void set(TextMapInject carrier, String key, String value) {
  carrier.put(key, value);
}
 
Example #8
Source File: TextMapPropagation.java    From brave-opentracing with Apache License 2.0 4 votes vote down vote up
@Override public void put(TextMapInject request, String key, String value) {
  SETTER.put(request, key, value);
}
 
Example #9
Source File: TextMapPropagation.java    From brave with Apache License 2.0 4 votes vote down vote up
@Override public void put(TextMapInject request, String key, String value) {
  SETTER.put(request, key, value);
}