io.opentracing.Tracer类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(296)

本文整理了Java中io.opentracing.Tracer类的一些代码示例,展示了Tracer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer类的具体详情如下:
包路径:io.opentracing.Tracer
类名称:Tracer

Tracer介绍

[英]Tracer is a simple, thin interface for Span creation and propagation across arbitrary transports.
[中]Tracer是一个简单、薄的接口,用于跨任意传输创建和传播跨度。

代码示例

代码示例来源:origin: weibocom/motan

protected Span extractTraceInfo(Request request, Tracer tracer) {
  String operationName = buildOperationName(request);
  SpanBuilder span = tracer.buildSpan(operationName);
  try {
    SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
    if (spanContext != null) {
      span.asChildOf(spanContext);
    }
  } catch (Exception e) {
    span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
  }
  return span.start();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
  delegate.inject(spanContext, format, carrier);
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public ScopeManager scopeManager() {
  return delegate.scopeManager();
}

代码示例来源:origin: qunarcorp/qmq

public static void inject(Message message, Tracer tracer) {
  Scope scope = tracer.scopeManager().active();
  if (scope == null) return;
  tracer.inject(scope.span().context(), Format.Builtin.TEXT_MAP, new QmqMessageInjectAdapter(message));
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public SpanBuilder buildSpan(String operationName) {
  return tracer.buildSpan(operationName);
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
protected void handleOutboundSOAPMessage(SOAPMessageContext context) {
  final Tracer.SpanBuilder spanBuilder = tracingPlugin.getTracer()
      .buildSpan(getOperationName(context))
      .withTag(SpanUtils.OPERATION_TYPE, "soap")
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
  if (soapTracingPlugin.isSoapClientRecordRequestMessages()) {
    spanBuilder.withTag("soap.request", getSoapMessageAsString(context));
  }
  final Span span = spanBuilder.startActive(true).span();
  tracingPlugin.getTracer().inject(span.context(), Format.Builtin.HTTP_HEADERS, new SOAPMessageInjectAdapter(context));
}

代码示例来源:origin: io.opentracing.contrib/opentracing-concurrent

public TracedRunnable(Runnable delegate, Tracer tracer) {
 this.delegate = delegate;
 this.tracer = tracer;
 this.span = tracer.activeSpan();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
  public <C> SpanContext extract(Format<C> format, C carrier) {
    return tracer.extract(format, carrier);
  }
}

代码示例来源:origin: io.opentracing.contrib/opentracing-redis-common

private static Scope buildScope(String command, boolean withActiveSpanOnly,
                Tracer tracer) {
  Tracer currentTracer = getNullSafeTracer(tracer);
  if (withActiveSpanOnly && currentTracer.activeSpan() == null) {
    return NoopScope.INSTANCE;
  }
  Tracer.SpanBuilder spanBuilder = currentTracer.buildSpan(command)
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
  Scope scope = spanBuilder.startActive(true);
  decorate(scope.span());
  return scope;
}

代码示例来源:origin: teiid/teiid

public Scope activateSpan(Span span) {
  Tracer tr = getTracer(); 
  if (tr.activeSpan() == span) {
    //when a workitem adds itself to a queue the span will already be active
    return null;
  }
  return tr.scopeManager().activate(span, false);
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public SpanWrappingSpanBuilder buildSpan(String operationName) {
  return new SpanWrappingSpanBuilder(delegate.buildSpan(operationName), operationName, createSpanInterceptors());
}

代码示例来源:origin: jersey/jersey

@Override
  public void filter(ClientRequestContext requestContext) throws IOException {
    Tracer.SpanBuilder spanBuilder = GlobalTracer.get()
        .buildSpan(LocalizationMessages.OPENTRACING_SPAN_PREFIX_CLIENT() + requestContext.getMethod())
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
        .withTag(Tags.HTTP_URL.getKey(), requestContext.getUri().toASCIIString())
        .withTag(Tags.HTTP_METHOD.getKey(), requestContext.getMethod())
        .withTag(LocalizationMessages.OPENTRACING_TAG_HAS_REQUEST_ENTITY(), requestContext.hasEntity())
        .withTag(LocalizationMessages.OPENTRACING_TAG_ACCEPTABLE_MEDIA_TYPES(), requestContext.getAcceptableMediaTypes()
            .stream()
            .map(MediaType::toString)
            .collect(Collectors.joining(", ")))
        .withTag(LocalizationMessages.OPENTRACING_TAG_REQUEST_HEADERS(),
            OpenTracingUtils.headersAsString(requestContext.getHeaders()));

    // if pre-stored "span" property is found, propagate the stored context
    final Object property = requestContext.getProperty(OpenTracingFeature.SPAN_CONTEXT_PROPERTY);
    if (property != null && property instanceof SpanContext) {
      spanBuilder = spanBuilder.asChildOf((SpanContext) property);
    }
    Span span = spanBuilder.startManual();

    requestContext.setProperty(OpenTracingFeature.SPAN_CONTEXT_PROPERTY, span);
    Map<String, String> addedHeaders = new HashMap<>();
    GlobalTracer.get().inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(addedHeaders));
    addedHeaders.forEach((key, value) -> requestContext.getHeaders().add(key, value));
  }
}

代码示例来源:origin: io.opentracing.contrib/opentracing-concurrent

public TracedCallable(Callable<V> delegate, Tracer tracer) {
 this.delegate = delegate;
 this.tracer = tracer;
 this.span = tracer.activeSpan();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public <C> SpanContext extract(Format<C> format, C carrier) {
  try {
    return delegate.extract(format, carrier);
  } catch (NumberFormatException e) {
    logger.error("error parsing span id, possible XSS attack: " + e.getMessage(), e);
    return null;
  }
}

代码示例来源:origin: org.teiid/teiid-engine

public Scope activateSpan(Span span) {
  Tracer tr = getTracer(); 
  if (tr.activeSpan() == span) {
    //when a workitem adds itself to a queue the span will already be active
    return null;
  }
  return tr.scopeManager().activate(span, false);
}

代码示例来源:origin: oracle/helidon

private Span createRequestSpan(Tracer tracer, BareRequest request) {
  Tracer.SpanBuilder spanBuilder = tracer.buildSpan("HTTP Request")
      .withTag(Tags.COMPONENT.getKey(), "helidon-webserver")
      .withTag(Tags.HTTP_METHOD.getKey(), request.method().name())
      .withTag(Tags.HTTP_URL.getKey(), request.uri().toString());
  Map<String, String> headersMap = request.headers()
                      .entrySet()
                      .stream()
                      .filter(entry -> !entry.getValue().isEmpty())
                      .collect(Collectors.toMap(Map.Entry::getKey,
                                   entry -> entry.getValue().get(0)));
  SpanContext spanContext = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(headersMap));
  if (spanContext != null) {
    spanBuilder.asChildOf(spanContext);
  }
  return spanBuilder.start();
}

代码示例来源:origin: jersey/jersey

@Override
  public void filter(ContainerRequestContext requestContext) throws IOException {
    Span span = OpenTracingUtils
        .getRequestSpan(requestContext)
        .orElse(GlobalTracer.get().buildSpan("ad-hoc-span-reqB").startManual());
    span.log("ReqFilterB.filter() invoked");
  }
}

代码示例来源:origin: sixt/ja-micro

span = tracer.buildSpan(client.getMethodName()).asChildOf(spanContext).start();
} else {
  span = tracer.buildSpan(client.getMethodName()).start();
  span.setTag("correlation_id", orangeContext.getCorrelationId());
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapInjectAdapter(request.getHeaders()));

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
  tracer.inject(spanContext, format, carrier);
}

代码示例来源:origin: qunarcorp/qmq

@Override
  public void postOnMessage(Message message, Throwable e, Map<String, Object> filterContext) {
    Object o = filterContext.get(TRACE_OBJECT);
    if (!(o instanceof Span)) return;
    Scope scope = tracer.scopeManager().activate((Span) o, true);
    scope.close();
  }
}

相关文章