当前位置: 首页>>代码示例>>Java>>正文


Java Scope类代码示例

本文整理汇总了Java中io.opentracing.Scope的典型用法代码示例。如果您正苦于以下问题:Java Scope类的具体用法?Java Scope怎么用?Java Scope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Scope类属于io.opentracing包,在下文中一共展示了Scope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import io.opentracing.Scope; //导入依赖的package包/类
@Override
public Future<RecordMetadata> send(ProducerRecord<K, V> record, Callback callback) {
  /*
  // Create wrappedRecord because headers can be read only in record (if record is sent second time)
  ProducerRecord<K, V> wrappedRecord = new ProducerRecord<>(record.topic(),
      record.partition(),
      record.timestamp(),
      record.key(),
      record.value(),
      record.headers());
  */

  try (Scope scope = buildAndInjectSpan(record)) {
    Callback wrappedCallback = new TracingCallback(callback, scope);
    return producer.send(record, wrappedCallback);
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:18,代码来源:TracingKafkaProducer.java

示例2: buildSpan

import io.opentracing.Scope; //导入依赖的package包/类
private Scope buildSpan(Tracer tracer, String operationName, StatementInformation statementInformation) {
  try {
    final Scope activeScope = tracer.scopeManager().active();
    final String dbUrl =
        statementInformation.getConnectionInformation().getConnection().getMetaData().getURL();
    if (withActiveSpanOnly(dbUrl) && activeScope == null) {
      return NoopScopeManager.NoopScope.INSTANCE;
    }

    final Tracer.SpanBuilder spanBuilder = tracer
        .buildSpan(operationName)
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
    if (activeScope != null) {
      spanBuilder.asChildOf(activeScope.span());
    }
    final Scope scope = spanBuilder.startActive(true);
    decorate(scope.span(), statementInformation);
    return scope;
  } catch (SQLException e) {
    return NoopScopeManager.NoopScope.INSTANCE;
  }
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:23,代码来源:TracingP6SpyListener.java

示例3: testWithSpanOnlyWithParent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void testWithSpanOnlyWithParent() throws SQLException {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(";traceWithActiveSpanOnly=true");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(2, finishedSpans.size());
  checkSameTrace(finishedSpans);
  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:17,代码来源:SpringTest.java

示例4: jpaWithActiveSpanOnlyWithParent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void jpaWithActiveSpanOnlyWithParent() {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory =
        Persistence.createEntityManagerFactory("jpa_active_span_only");

    Employee employee = new Employee();
    EntityManager entityManager = entityManagerFactory.createEntityManager();
    entityManager.getTransaction().begin();
    entityManager.persist(employee);
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();

    assertNotNull(employee.id);
  }

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(9, finishedSpans.size());
  checkSameTrace(finishedSpans);
  assertNull(mockTracer.scopeManager().active());
}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:23,代码来源:HibernateTest.java

示例5: withActiveSpanOnlyWithParent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void withActiveSpanOnlyWithParent() throws InterruptedException {
  try (Scope activeSpan = mockTracer.buildSpan("parent").startActive(true)) {
    SessionFactory sessionFactory = createSessionFactory(";traceWithActiveSpanOnly=true");
    Session session = sessionFactory.openSession();

    Employee employee = new Employee();
    session.beginTransaction();
    session.save(employee);
    session.getTransaction().commit();
    session.close();
    sessionFactory.close();
  }

  List<MockSpan> finishedSpans = mockTracer.finishedSpans();
  assertEquals(9, finishedSpans.size());
  checkSameTrace(finishedSpans);

  assertNull(mockTracer.scopeManager().active());

}
 
开发者ID:opentracing-contrib,项目名称:java-p6spy,代码行数:22,代码来源:HibernateTest.java

示例6: buildAndInjectSpan

import io.opentracing.Scope; //导入依赖的package包/类
private Scope buildAndInjectSpan(ProducerRecord<K, V> record) {
  Tracer.SpanBuilder spanBuilder = tracer.buildSpan("send")
      .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

  SpanContext spanContext = TracingKafkaUtils.extract(record.headers(), tracer);

  if (spanContext != null) {
    spanBuilder.asChildOf(spanContext);
  }

  Scope scope = spanBuilder.startActive(false);
  SpanDecorator.onSend(record, scope.span());

  try {
    TracingKafkaUtils.inject(scope.span().context(), record.headers(), tracer);
  } catch (Exception e) {
    // it can happen if headers are read only (when record is sent second time)
    logger.error("failed to inject span context. sending record second time?", e);
  }

  return scope;
}
 
开发者ID:opentracing-contrib,项目名称:java-kafka-client,代码行数:23,代码来源:TracingKafkaProducer.java

示例7: buildChildSpan

import io.opentracing.Scope; //导入依赖的package包/类
static Scope buildChildSpan(AMQP.BasicProperties props, Tracer tracer) {
  SpanContext context = TracingUtils.extract(props, tracer);
  if (context != null) {
    Tracer.SpanBuilder spanBuilder = tracer.buildSpan("receive")
        .ignoreActiveSpan()
        .withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER);

    spanBuilder.addReference(References.FOLLOWS_FROM, context);

    Scope scope = spanBuilder.startActive(true);
    SpanDecorator.onResponse(scope.span());
    return scope;
  }

  return null;
}
 
开发者ID:opentracing-contrib,项目名称:java-rabbitmq-client,代码行数:17,代码来源:TracingUtils.java

示例8: testParentSpanSource

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void testParentSpanSource() throws IOException {
    {
        Scope parent = mockTracer.buildSpan("parent")
                .startActive(true);

        mockWebServer.enqueue(new MockResponse()
                .setResponseCode(203));

        Request request = new Request.Builder()
                .url(mockWebServer.url("bar"))
                .tag(new TagWrapper(parent.span().context()))
                .get()
                .build();

        client.newCall(request).execute();
        parent.close();
    }

    List<MockSpan> mockSpans = mockTracer.finishedSpans();
    assertOnErrors(mockSpans);
    Assert.assertEquals(3, mockSpans.size());
    Assert.assertEquals(mockSpans.get(2).context().traceId(), mockSpans.get(1).context().traceId());
    Assert.assertEquals(mockSpans.get(2).context().spanId(), mockSpans.get(1).parentId());
}
 
开发者ID:opentracing-contrib,项目名称:java-okhttp,代码行数:26,代码来源:AbstractOkHttpTest.java

示例9: buildAndFinishChildSpan

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void buildAndFinishChildSpan() {
  MockSpan span = mockTracer.buildSpan("test").start();
  mockTracer.scopeManager().activate(span, true);
  Scope span2 = TracingMessageUtils
      .buildAndFinishChildSpan(new ActiveMQTextMessage(), mockTracer);
  assertNotNull(span2);

  assertNotNull(mockTracer.activeSpan());

  assertEquals(1, mockTracer.finishedSpans().size());

  MockSpan finished = mockTracer.finishedSpans().get(0);

  assertEquals(TracingMessageUtils.OPERATION_NAME_RECEIVE, finished.operationName());
  assertEquals(Tags.SPAN_KIND_CONSUMER, finished.tags().get(Tags.SPAN_KIND.getKey()));
  assertEquals(TracingMessageUtils.COMPONENT_NAME, finished.tags().get(Tags.COMPONENT.getKey()));
  assertEquals(span.context().spanId(), finished.parentId());
  assertEquals(span.context().traceId(), finished.context().traceId());
}
 
开发者ID:opentracing-contrib,项目名称:java-jms,代码行数:21,代码来源:TracingMessageUtilsTest.java

示例10: spring_with_parent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void spring_with_parent() throws Exception {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(false);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_1 (id INTEGER)");
    jdbcTemplate.execute("CREATE TABLE with_parent_2 (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(3, spans.size());

  checkSameTrace(spans);
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:18,代码来源:SpringTest.java

示例11: spring_with_parent_and_active_span_only

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void spring_with_parent_and_active_span_only() throws Exception {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    BasicDataSource dataSource = getDataSource(true);

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_1 (id INTEGER)");
    jdbcTemplate.execute("CREATE TABLE with_parent_skip_2 (id INTEGER)");

    dataSource.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(3, spans.size());

  checkSameTrace(spans);
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:18,代码来源:SpringTest.java

示例12: jpa_with_parent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void jpa_with_parent() {

  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("jpa");

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();
    entityManager.persist(new Employee());
    entityManager.persist(new Employee());
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:22,代码来源:HibernateTest.java

示例13: jpa_with_parent_and_active_span_only

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void jpa_with_parent_and_active_span_only() {

  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    EntityManagerFactory entityManagerFactory = Persistence
        .createEntityManagerFactory("jpa_active_span_only");

    EntityManager entityManager = entityManagerFactory.createEntityManager();

    entityManager.getTransaction().begin();
    entityManager.persist(new Employee());
    entityManager.persist(new Employee());
    entityManager.getTransaction().commit();
    entityManager.close();
    entityManagerFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:23,代码来源:HibernateTest.java

示例14: hibernate_with_parent

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void hibernate_with_parent() {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    SessionFactory sessionFactory = createSessionFactory(false);
    Session session = sessionFactory.openSession();

    session.beginTransaction();
    session.save(new Employee());
    session.save(new Employee());
    session.getTransaction().commit();
    session.close();
    sessionFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:20,代码来源:HibernateTest.java

示例15: hibernate_with_parent_and_active_span_only

import io.opentracing.Scope; //导入依赖的package包/类
@Test
public void hibernate_with_parent_and_active_span_only() {
  try (Scope ignored = mockTracer.buildSpan("parent").startActive(true)) {
    SessionFactory sessionFactory = createSessionFactory(true);
    Session session = sessionFactory.openSession();

    session.beginTransaction();
    session.save(new Employee());
    session.save(new Employee());
    session.getTransaction().commit();
    session.close();
    sessionFactory.close();
  }

  List<MockSpan> spans = mockTracer.finishedSpans();
  assertEquals(11, spans.size());
  checkSameTrace(spans);
  assertNull(mockTracer.activeSpan());
}
 
开发者ID:opentracing-contrib,项目名称:java-jdbc,代码行数:20,代码来源:HibernateTest.java


注:本文中的io.opentracing.Scope类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。