本文整理汇总了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);
}
}
示例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;
}
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}