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

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

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

Scope介绍

[英]A Scope formalizes the activation and deactivation of a Span, usually from a CPU standpoint.

Many times a Span will be extant (in that Span#finish() has not been called) despite being in a non-runnable state from a CPU/scheduler standpoint. For instance, a Span representing the client side of an RPC will be unfinished but blocked on IO while the RPC is still outstanding. A Scope defines when a given Span is scheduled and on the path.
[中]作用域通常从CPU的角度对范围的激活和停用进行形式化。
很多时候,尽管从CPU/调度程序的角度来看处于不可运行状态,但一个Span仍然存在(在该Span中,尚未调用#finish())。例如,代表RPC客户端的跨度将未完成,但在RPC仍然未完成时在IO上被阻止。作用域定义了给定跨度*的计划时间和路径。

代码示例

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

@Override
public Span activeSpan() {
  return 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: qunarcorp/qmq

private void closeTrace() {
  if (traceScope == null) return;
  traceScope.close();
}

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

代码示例来源: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: 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
public void close(MessageContext context) {
  if (!shouldExecute(context)) {
    return;
  }
  tracingPlugin.getTracer().scopeManager().active().close();
}

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

static void ackWithTrace(PulledMessage message, Throwable throwable) {
    Scope scope = GlobalTracer.get()
        .buildSpan("Qmq.Consume.Ack")
        .withTag("subject", message.getSubject())
        .withTag("messageId", message.getMessageId())
        .withTag("consumerGroup", message.getStringProperty(BaseMessage.keys.qmq_consumerGroupName))
        .startActive(true);
    try {
      ack(message, throwable);
    } catch (Exception e) {
      scope.span().log("ack_failed");
      LOGGER.error("ack exception.", e);
      Metrics.counter("qmq_pull_ackError", SUBJECT_ARRAY, new String[]{message.getSubject()}).inc();
    } finally {
      if (scope != null) {
        scope.close();
      }
    }
  }
}

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

@Test
public void testDontMonitorClientRootSpans() throws Exception {
  MockTracer tracer = new MockTracer();
  new AbstractExternalRequest(tracer) {
    @Override
    protected String getType() {
      return "jdbc";
    }
  }.createScope().close();
  assertThat(tracer.finishedSpans().get(0).tags().get(Tags.SAMPLING_PRIORITY.getKey())).isEqualTo(0);
}

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

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

代码示例来源:origin: com.uber.jaeger/jaeger-context

/** Deactivates the current active span and returns it. If there is no active span returns null. */
@Override
public Span pop() {
 Scope scope = scopeManager.active();
 if (scope == null) {
  return null;
 }
 Span span = scope.span();
 scope.close();
 return span;
}

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

@Test
public void testHonorDoNotTrack() throws Exception {
  when(servletPlugin.isHonorDoNotTrackHeader()).thenReturn(true);
  final MockHttpServletRequest request = new MockHttpServletRequest();
  request.addHeader("dnt", "1");
  Scope activeScope = new MonitoredHttpRequest(request, mock(StatusExposingByteCountingServletResponse.class),
      mock(FilterChain.class), configuration, mock(ExecutorService.class)).createScope();
  SpanWrapper span = SpanContextInformation.getCurrent().getSpanWrapper();
  assertThat(span.getNumberTag(Tags.SAMPLING_PRIORITY.getKey())).isEqualTo(0);
  activeScope.close();
}

代码示例来源: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: io.opentracing.contrib/opentracing-jdbc

@Override
public int[] executeBatch() throws SQLException {
 Scope scope = buildScopeForBatch();
 try {
  return statement.executeBatch();
 } catch (Exception e) {
  JdbcTracingUtils.onError(e, scope.span());
  throw e;
 } finally {
  scope.close();
 }
}

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

@Test
public void testNoDoNotTrackHeader() throws Exception {
  when(servletPlugin.isHonorDoNotTrackHeader()).thenReturn(true);
  final MockHttpServletRequest request = new MockHttpServletRequest();
  Scope activeScope = new MonitoredHttpRequest(request, mock(StatusExposingByteCountingServletResponse.class),
      mock(FilterChain.class), configuration, mock(ExecutorService.class)).createScope();
  SpanWrapper span = SpanContextInformation.getCurrent().getSpanWrapper();
  assertThat(span.getNumberTag(Tags.SAMPLING_PRIORITY.getKey())).isNotEqualTo(0);
  activeScope.close();
}

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

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

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

@Override
public ResultSet executeQuery() throws SQLException {
 Scope scope = buildScope("Query", query, connectionInfo, withActiveSpanOnly, ignoredQueries,
   tracer);
 try {
  return preparedStatement.executeQuery();
 } catch (Exception e) {
  JdbcTracingUtils.onError(e, scope.span());
  throw e;
 } finally {
  scope.close();
 }
}

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

@Test
public void testDontHonorDoNotTrack() throws Exception {
  when(servletPlugin.isHonorDoNotTrackHeader()).thenReturn(false);
  final MockHttpServletRequest request = new MockHttpServletRequest();
  request.addHeader("dnt", "1");
  Scope activeScope = new MonitoredHttpRequest(request, mock(StatusExposingByteCountingServletResponse.class),
      mock(FilterChain.class), configuration, mock(ExecutorService.class)).createScope();
  SpanWrapper span = SpanContextInformation.getCurrent().getSpanWrapper();
  assertThat(span.getNumberTag(Tags.SAMPLING_PRIORITY.getKey())).isNotEqualTo(0);
  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;
}

相关文章