io.opentracing.Scope.span()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(310)

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

Scope.span介绍

暂无

代码示例

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

@Override
public Span activeSpan() {
  return scopeManager.active().span();
}

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

public SpanContextInformation monitorStart(MonitoredRequest monitoredRequest) {
  final long start = System.nanoTime();
  final Scope scope = monitoredRequest.createScope();
  final SpanContextInformation info = SpanContextInformation.get(scope.span());
  if (info != null) {
    info.setOverhead1(System.nanoTime() - start);
  }
  return info;
}

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

public static void setTag(String key, String value, Tracer tracer) {
  if (tracer == null) {
    tracer = GlobalTracer.get();
  }
  Scope scope = tracer.scopeManager().active();
  if (scope == null) return;
  scope.span().setTag(key, value);
}

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

public static SpanContextInformation getCurrent() {
  final Scope activeScope = GlobalTracer.get().scopeManager().active();
  if (activeScope == null) {
    return null;
  }
  return forSpan(activeScope.span());
}

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

public static void recordEvent(String event, Tracer tracer) {
  if (tracer == null) {
    tracer = GlobalTracer.get();
  }
  Scope scope = tracer.scopeManager().active();
  if (scope == null) return;
  scope.span().log(event);
}

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

@Override
public Span activeSpan() {
  return scopeManager().active() == null ? null : scopeManager().active().span();
}

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

public void monitorStop() {
  final Scope activeScope = tracingPlugin.getTracer().scopeManager().active();
  if (activeScope != null) {
    final Span currentSpan = activeScope.span();
    final SpanContextInformation info = SpanContextInformation.get(currentSpan);
    if (info != null) {
      long overhead2 = System.nanoTime();
      trackOverhead(info.getOverhead1(), overhead2);
    }
    activeScope.close();
  }
}

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

@Override
public Scope createScope() {
  final Scope scope = super.createScope();
  final Span span = scope.span();
  Tags.HTTP_URL.set(span, url);
  Tags.PEER_HOSTNAME.set(span, host);
  Tags.PEER_PORT.set(span, port);
  span.setTag(AbstractExternalRequest.EXTERNAL_REQUEST_METHOD, method);
  return scope;
}

代码示例来源: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: qunarcorp/qmq

@Override
public boolean preOnMessage(Message message, Map<String, Object> filterContext) {
  SpanContext context = TraceUtil.extract(message, tracer);
  Scope scope = tracer.buildSpan(TRACE_DESC)
      .withTag("subject", message.getSubject())
      .withTag("messageId", message.getMessageId())
      .withTag("localRetries", String.valueOf(message.localRetries()))
      .withTag("times", String.valueOf(message.times()))
      .asChildOf(context)
      .startActive(true);
  filterContext.put(TRACE_OBJECT, scope.span());
  return true;
}

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

/**
 * @return the {@link Span} of the current request or a noop {@link Span} (never <code>null</code>)
 */
public static Span getCurrentSpan() {
  final Scope activeScope = GlobalTracer.get().scopeManager().active();
  if (activeScope != null) {
    return activeScope.span();
  } else {
    return NoopTracerFactory.create().buildSpan(null).startManual();
  }
}

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

@Override
protected void handleOutboundSOAPMessage(SOAPMessageContext context) {
  if (soapTracingPlugin.isSoapServerRecordResponseMessages()) {
    final Span span = tracingPlugin.getTracer().scopeManager().active().span();
    span.setTag("soap.response", getSoapMessageAsString(context));
  }
}

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

public void recordException(Exception e) {
  final Scope activeScope = tracingPlugin.getTracer().scopeManager().active();
  if (activeScope != null) {
    SpanUtils.setException(activeScope.span(), e, tracingPlugin.getIgnoreExceptions(), tracingPlugin.getUnnestExceptions());
  }
}

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

@Override
protected void handleInboundSOAPMessage(SOAPMessageContext context) {
  if (soapTracingPlugin.isSoapClientRecordResponseMessages()) {
    final Span span = tracingPlugin.getTracer().scopeManager().active().span();
    span.setTag("soap.response", getSoapMessageAsString(context));
  }
}

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

@Test
  public void testIsRoot() throws Exception {
    final StagemonitorPlugin.InitArguments initArguments = mock(StagemonitorPlugin.InitArguments.class);
    when(initArguments.getMeasurementSession()).thenReturn(
        new MeasurementSession("JaegerTracerFactoryTest", "test", "test"));
    final JaegerTracerFactory jaegerTracerFactory = new JaegerTracerFactory();
    final Tracer tracer = jaegerTracerFactory.getTracer(initArguments);
    try (final Scope rootSpan = tracer.buildSpan("foo").startActive(true)) {
      try (final Scope childSpan = tracer.buildSpan("bar").startActive(true)) {
        assertThat(jaegerTracerFactory.isRoot(rootSpan.span())).isTrue();
        assertThat(jaegerTracerFactory.isRoot(childSpan.span())).isFalse();
      }
    }
  }
}

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

@Override
public Scope createScope() {
  final Tracer tracer = tracingPlugin.getTracer();
  final Tracer.SpanBuilder spanBuilder = tracer.buildSpan(methodSignature)
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
  final Scope scope = spanBuilder
      .withTag(SpanUtils.OPERATION_TYPE, OP_TYPE_METHOD_INVOCATION)
      .withTag(MetricsSpanEventListener.ENABLE_TRACKING_METRICS_TAG, true)
      .startActive(true);
  SpanUtils.setParameters(scope.span(), safeParameters);
  return scope;
}

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

public static void setRequestNameByHandler(Object handler) {
  final Scope activeScope = GlobalTracer.get().scopeManager().active();
  if (activeScope != null) {
    final BusinessTransactionNamingStrategy namingStrategy = Stagemonitor.getPlugin(TracingPlugin.class)
        .getBusinessTransactionNamingStrategy();
    final String requestNameFromHandler = getRequestNameFromHandler(handler, namingStrategy);
    if (requestNameFromHandler != null) {
      final Span span = activeScope.span();
      span.setTag(MetricsSpanEventListener.ENABLE_TRACKING_METRICS_TAG, true);
      span.setOperationName(requestNameFromHandler);
    }
  }
}

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

private void reportSpan() {
  final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
  request.addHeader(WidgetAjaxSpanReporter.CONNECTION_ID, connectionId);
  final MonitoredHttpRequest monitoredHttpRequest = new MonitoredHttpRequest(request,
      mock(StatusExposingByteCountingServletResponse.class), new MockFilterChain(), configuration, mock(ExecutorService.class));
  span = monitoredHttpRequest.createScope().span();
  span.setOperationName("test");
  span.finish();
}

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

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
  final Scope scope = new ExternalHttpRequest(tracingPlugin.getTracer(), request.getMethod().toString(), removeQuery(request.getURI()), request.getURI().getHost(), request.getURI().getPort()).createScope();
  try {
    Profiler.start(request.getMethod().toString() + " " + request.getURI() + " ");
    tracingPlugin.getTracer().inject(scope.span().context(), Format.Builtin.HTTP_HEADERS, new SpringHttpRequestInjectAdapter(request));
    return execution.execute(request, body);
  } finally {
    Profiler.stop();
    scope.close();
  }
}

代码示例来源: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));
}

相关文章