brave.propagation.TraceContext.newBuilder()方法的使用及代码示例

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

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

TraceContext.newBuilder介绍

暂无

代码示例

代码示例来源:origin: openzipkin/brave

@Override public void accept(CurrentTraceContext current) {
  current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build());
 }
}

代码示例来源:origin: openzipkin/brave

@Override public void accept(CurrentTraceContext current) {
  try (Scope ws = current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build())) {
  }
 }
}

代码示例来源:origin: openzipkin/brave

@Test public void restoresSpanAfterRunnable() throws Exception {
 TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build();
 try (Scope scope0 = currentTraceContext.newScope(context0)) {
  attachesSpanInRunnable();
  assertThat(currentTraceContext.get())
    .isEqualTo(context0);
  verifyImplicitContext(context0);
 }
}

代码示例来源:origin: line/armeria

/**
 * Ensures the specified {@link Tracing} uses a {@link RequestContextCurrentTraceContext}.
 *
 * @throws IllegalStateException if {@code tracing} does not use {@link RequestContextCurrentTraceContext}
 */
public static void ensureScopeUsesRequestContext(Tracing tracing) {
  final PingPongExtra extra = new PingPongExtra();
  // trace contexts are not recorded until Tracer.toSpan, so this won't end up as junk data
  final TraceContext dummyContext = TraceContext.newBuilder().traceId(1).spanId(1)
                         .extra(Collections.singletonList(extra)).build();
  final boolean scopeUsesRequestContext;
  try (Scope scope = tracing.currentTraceContext().newScope(dummyContext)) {
    scopeUsesRequestContext = extra.isPong();
  }
  if (!scopeUsesRequestContext) {
    throw new IllegalStateException(
        "Tracing.currentTraceContext is not a " + RequestContextCurrentTraceContext.class
            .getSimpleName() + " scope. " +
        "Please call Tracing.Builder.currentTraceContext(" + RequestContextCurrentTraceContext.class
            .getSimpleName() + ".INSTANCE).");
  }
}

代码示例来源:origin: openzipkin/brave

@Override public void accept(Propagation<?> propagation) {
  TraceContext.Injector<Map<Object, String>> injector = propagation.injector(Map::put);
  TraceContext.Extractor<Map<Object, String>> extractor = propagation.extractor(Map::get);
  TraceContext ctx = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false).build();
  Map<Object, String> map = new LinkedHashMap<>();
  injector.inject(ctx, map);
  assertThat(extractor.extract(map).context())
    .isEqualToIgnoringGivenFields(ctx, "traceIdString", "spanIdString");
 }
}

代码示例来源:origin: openzipkin/brave

@Override public TraceContextOrSamplingFlags extract(C carrier) {
  if (carrier == null) throw new NullPointerException("carrier == null");
  // try to extract single-header format
  TraceContextOrSamplingFlags extracted = singleExtractor.extract(carrier);
  if (!extracted.equals(TraceContextOrSamplingFlags.EMPTY)) return extracted;
  // Start by looking at the sampled state as this is used regardless
  // Official sampled value is 1, though some old instrumentation send true
  String sampled = getter.get(carrier, propagation.sampledKey);
  Boolean sampledV = sampled != null
    ? sampled.equals("1") || sampled.equalsIgnoreCase("true")
    : null;
  boolean debug = "1".equals(getter.get(carrier, propagation.debugKey));
  String traceIdString = getter.get(carrier, propagation.traceIdKey);
  // It is ok to go without a trace ID, if sampling or debug is set
  if (traceIdString == null) return TraceContextOrSamplingFlags.create(sampledV, debug);
  // Try to parse the trace IDs into the context
  TraceContext.Builder result = TraceContext.newBuilder();
  if (result.parseTraceId(traceIdString, propagation.traceIdKey)
    && result.parseSpanId(getter, carrier, propagation.spanIdKey)
    && result.parseParentId(getter, carrier, propagation.parentSpanIdKey)) {
   if (sampledV != null) result.sampled(sampledV.booleanValue());
   if (debug) result.debug(true);
   return TraceContextOrSamplingFlags.create(result.build());
  }
  return TraceContextOrSamplingFlags.EMPTY; // trace context is malformed so return empty
 }
}

代码示例来源:origin: line/armeria

@Test
public void newScope_notOnEventLoop() {
  final TraceContext traceContext2 = TraceContext.newBuilder().traceId(1).spanId(2).build();
  try (SafeCloseable requestContextScope = mockRequestContext.push()) {
    try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) {
      assertThat(traceContextScope).hasToString("InitialRequestScope");
      assertThat(currentTraceContext.get()).isEqualTo(traceContext);
      when(eventLoop.inEventLoop()).thenReturn(false);
      try (Scope traceContextScope2 = currentTraceContext.newScope(traceContext2)) {
        assertThat(traceContextScope2).hasToString("ThreadLocalScope");
        assertThat(currentTraceContext.get()).isEqualTo(traceContext2);
      }
      when(eventLoop.inEventLoop()).thenReturn(true);
      assertThat(currentTraceContext.get()).isEqualTo(traceContext);
    }
    // the first scope is attached to the request context and cleared when that's destroyed
    assertThat(currentTraceContext.get()).isEqualTo(traceContext);
  }
}

代码示例来源:origin: line/armeria

@Test
  public void shouldSetPongIfOnlyExtra() {
    final PingPongExtra extra = new PingPongExtra();

    final TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1)
                         .extra(Collections.singletonList(extra)).build();

    PingPongExtra.maybeSetPong(context);

    assertThat(extra.isPong()).isTrue();
  }
}

代码示例来源:origin: line/armeria

@Test
public void newScope_respondsToPing() {
  final PingPongExtra extra = new PingPongExtra();
  final TraceContext extraContext = TraceContext.newBuilder().traceId(1).spanId(1)
                         .extra(Collections.singletonList(extra)).build();
  try (Scope traceContextScope = currentTraceContext.newScope(extraContext)) {
    assertThat(traceContextScope).hasToString("NoopScope");
    assertThat(extra.isPong()).isTrue();
  }
}

代码示例来源:origin: line/armeria

@Test
public void newScope_closeDoesntClearFirstScope() {
  final TraceContext traceContext2 = TraceContext.newBuilder().traceId(1).spanId(2).build();
  try (SafeCloseable requestContextScope = mockRequestContext.push()) {
    try (Scope traceContextScope = currentTraceContext.newScope(traceContext)) {
      assertThat(traceContextScope).hasToString("InitialRequestScope");
      assertThat(currentTraceContext.get()).isEqualTo(traceContext);
      try (Scope traceContextScope2 = currentTraceContext.newScope(traceContext2)) {
        assertThat(traceContextScope2).hasToString("RequestContextTraceContextScope");
        assertThat(currentTraceContext.get()).isEqualTo(traceContext2);
      }
      assertThat(currentTraceContext.get()).isEqualTo(traceContext);
    }
    // the first scope is attached to the request context and cleared when that's destroyed
    assertThat(currentTraceContext.get()).isEqualTo(traceContext);
  }
}

代码示例来源:origin: openzipkin/brave

TraceContext.Builder builder = TraceContext.newBuilder()
  .traceIdHigh(traceIdHigh)
  .traceId(traceId)

代码示例来源:origin: io.zipkin.brave/brave-tests

@Override public void accept(CurrentTraceContext current) {
  try (Scope ws = current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build())) {
  }
 }
}

代码示例来源:origin: io.zipkin.brave/brave-tests

@Override public void accept(CurrentTraceContext current) {
  current.newScope(TraceContext.newBuilder().traceId(1L).spanId(2L).build());
 }
}

代码示例来源:origin: io.zipkin.brave/brave-tests

@Test public void restoresSpanAfterRunnable() throws Exception {
 TraceContext context0 = TraceContext.newBuilder().traceId(3L).spanId(3L).build();
 try (Scope scope0 = currentTraceContext.newScope(context0)) {
  attachesSpanInRunnable();
  assertThat(currentTraceContext.get())
    .isEqualTo(context0);
  verifyImplicitContext(context0);
 }
}

代码示例来源:origin: io.zipkin.brave/brave-tests

@Override public void accept(Propagation<?> propagation) {
  TraceContext.Injector<Map<Object, String>> injector = propagation.injector(Map::put);
  TraceContext.Extractor<Map<Object, String>> extractor = propagation.extractor(Map::get);
  TraceContext ctx = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(false).build();
  Map<Object, String> map = new LinkedHashMap<>();
  injector.inject(ctx, map);
  assertThat(extractor.extract(map).context())
    .isEqualToIgnoringGivenFields(ctx, "traceIdString", "spanIdString");
 }
}

代码示例来源:origin: io.zipkin.brave/brave

@Override public TraceContextOrSamplingFlags extract(C carrier) {
  if (carrier == null) throw new NullPointerException("carrier == null");
  // try to extract single-header format
  TraceContextOrSamplingFlags extracted = singleExtractor.extract(carrier);
  if (!extracted.equals(TraceContextOrSamplingFlags.EMPTY)) return extracted;
  // Start by looking at the sampled state as this is used regardless
  // Official sampled value is 1, though some old instrumentation send true
  String sampled = getter.get(carrier, propagation.sampledKey);
  Boolean sampledV = sampled != null
    ? sampled.equals("1") || sampled.equalsIgnoreCase("true")
    : null;
  boolean debug = "1".equals(getter.get(carrier, propagation.debugKey));
  String traceIdString = getter.get(carrier, propagation.traceIdKey);
  // It is ok to go without a trace ID, if sampling or debug is set
  if (traceIdString == null) return TraceContextOrSamplingFlags.create(sampledV, debug);
  // Try to parse the trace IDs into the context
  TraceContext.Builder result = TraceContext.newBuilder();
  if (result.parseTraceId(traceIdString, propagation.traceIdKey)
    && result.parseSpanId(getter, carrier, propagation.spanIdKey)
    && result.parseParentId(getter, carrier, propagation.parentSpanIdKey)) {
   if (sampledV != null) result.sampled(sampledV.booleanValue());
   if (debug) result.debug(true);
   return TraceContextOrSamplingFlags.create(result.build());
  }
  return TraceContextOrSamplingFlags.EMPTY; // trace context is malformed so return empty
 }
}

代码示例来源:origin: io.zipkin.brave/brave-core

public static TraceContext toTraceContext(SpanId spanId) { // visible for testing
 if (spanId == null) throw new NullPointerException("spanId == null");
 return TraceContext.newBuilder()
   .traceIdHigh(spanId.traceIdHigh)
   .traceId(spanId.traceId)
   .parentId(spanId.nullableParentId())
   .spanId(spanId.spanId)
   .debug(spanId.debug())
   .sampled(spanId.sampled()).build();
}

代码示例来源:origin: jiangmin168168/jim-framework

Tracer tracer= zipkinCollectorConfigurationFactory.getTracing().tracer();
TraceContext traceContext= TraceContext.newBuilder()
    .traceId(RpcTraceContext.getTraceId())
    .parentId(RpcTraceContext.getParentId())

代码示例来源:origin: openzipkin/zipkin-gcp

} else {
 result = TraceContextOrSamplingFlags.create(
   TraceContext.newBuilder()
     .traceIdHigh(traceId[0])
     .traceId(traceId[1])

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-grpc

TraceContext.Builder builder = TraceContext.newBuilder()
  .traceIdHigh(traceIdHigh)
  .traceId(traceId)

相关文章