io.opentracing.propagation.TextMapExtract Java Examples

The following examples show how to use io.opentracing.propagation.TextMapExtract. 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: Propagation.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@Nullable
public SpanContextShim extractTextFormat(TextMapExtract carrier) {
  Map<String, String> carrierMap = new HashMap<>();
  for (Map.Entry<String, String> entry : carrier) {
    carrierMap.put(entry.getKey(), entry.getValue());
  }

  Context context =
      propagators()
          .getHttpTextFormat()
          .extract(Context.current(), carrierMap, TextMapGetter.INSTANCE);

  io.opentelemetry.trace.Span span = TracingContextUtils.getSpan(context);
  if (!span.getContext().isValid()) {
    return null;
  }

  return new SpanContextShim(
      telemetryInfo, span.getContext(), CorrelationsContextUtils.getCorrelationContext(context));
}
 
Example #2
Source File: TracerShim.java    From opentelemetry-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ReturnMissingNullable")
@Override
public <C> SpanContext extract(Format<C> format, C carrier) {
  try {
    if (format == Format.Builtin.TEXT_MAP
        || format == Format.Builtin.TEXT_MAP_EXTRACT
        || format == Format.Builtin.HTTP_HEADERS) {
      return propagation.extractTextFormat((TextMapExtract) carrier);
    }
  } catch (Exception e) {
    logger.log(
        Level.INFO,
        "Exception caught while extracting span context; returning null. "
            + "Exception: [{0}] Message: [{1}]",
        new String[] {e.getClass().getName(), e.getMessage()});
  }

  return null;
}
 
Example #3
Source File: MockTracer.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
@Override
public <C> MockSpan.MockContext extract(Format<C> format, C carrier) {
    Long traceId = null;
    Long spanId = null;
    Map<String, String> baggage = new HashMap<>();

    if (carrier instanceof TextMapExtract) {
        TextMapExtract textMap = (TextMapExtract) carrier;
        for (Map.Entry<String, String> entry : textMap) {
            if (TRACE_ID_KEY.equals(entry.getKey())) {
                traceId = Long.valueOf(entry.getValue());
            } else if (SPAN_ID_KEY.equals(entry.getKey())) {
                spanId = Long.valueOf(entry.getValue());
            } else if (entry.getKey().startsWith(BAGGAGE_KEY_PREFIX)){
                String key = entry.getKey().substring((BAGGAGE_KEY_PREFIX.length()));
                baggage.put(key, entry.getValue());
            }
        }
    } else {
        throw new IllegalArgumentException("Unknown carrier");
    }

    if (traceId != null && spanId != null) {
        return new MockSpan.MockContext(traceId, spanId, baggage);
    }

    return null;
}
 
Example #4
Source File: TextMapPropagation.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
/** Performs case-insensitive lookup */
@Override public TraceContextOrSamplingFlags extract(TextMapExtract entries) {
  Map<String, String> cache = new LinkedHashMap<>();
  for (Iterator<Map.Entry<String, String>> it = entries.iterator(); it.hasNext(); ) {
    Map.Entry<String, String> next = it.next();
    String inputKey = next.getKey().toLowerCase(Locale.ROOT);
    if (allNames.contains(inputKey)) {
      cache.put(inputKey, next.getValue());
    }
  }
  return delegate.extract(cache);
}
 
Example #5
Source File: MockTracer.java    From opentracing-java with Apache License 2.0 5 votes vote down vote up
@Override
public <C> MockSpan.MockContext extract(Format<C> format, C carrier) {
    Long traceId = null;
    Long spanId = null;
    Map<String, String> baggage = new HashMap<>();

    if (carrier instanceof TextMapExtract) {
        TextMapExtract textMap = (TextMapExtract) carrier;
        for (Map.Entry<String, String> entry : textMap) {
            if (TRACE_ID_KEY.equals(entry.getKey())) {
                traceId = Long.valueOf(entry.getValue());
            } else if (SPAN_ID_KEY.equals(entry.getKey())) {
                spanId = Long.valueOf(entry.getValue());
            } else if (entry.getKey().startsWith(BAGGAGE_KEY_PREFIX)){
                String key = entry.getKey().substring((BAGGAGE_KEY_PREFIX.length()));
                baggage.put(key, entry.getValue());
            }
        }
    } else {
        throw new IllegalArgumentException("Unknown carrier");
    }

    if (traceId != null && spanId != null) {
        return new MockSpan.MockContext(traceId, spanId, baggage);
    }

    return null;
}
 
Example #6
Source File: TextMapPropagation.java    From brave with Apache License 2.0 5 votes vote down vote up
/** Performs case-insensitive lookup */
@Override public TraceContextOrSamplingFlags extract(TextMapExtract entries) {
  Map<String, String> cache = new LinkedHashMap<>();
  for (Iterator<Map.Entry<String, String>> it = entries.iterator(); it.hasNext(); ) {
    Map.Entry<String, String> next = it.next();
    String inputKey = next.getKey().toLowerCase(Locale.ROOT);
    if (allNames.contains(inputKey)) {
      cache.put(inputKey, next.getValue());
    }
  }
  return delegate.extract(cache);
}
 
Example #7
Source File: BraveTracer.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public <C> BraveSpanContext extract(Format<C> format, C carrier) {
  if (!(carrier instanceof TextMapExtract)) {
    throw new UnsupportedOperationException(carrier + " not instanceof TextMapExtract");
  }
  TraceContextOrSamplingFlags extractionResult = extractor.extract((TextMapExtract) carrier);
  return BraveSpanContext.create(extractionResult);
}