• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AttributeValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addAnnotation

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Override
public void addAnnotation(String description, Map<String, AttributeValue> attributes) {
  if (!getOptions().contains(Options.RECORD_EVENTS)) {
    return;
  }
  synchronized (this) {
    if (hasBeenEnded) {
      logger.log(Level.FINE, "Calling addAnnotation() on an ended Span.");
      return;
    }
    getInitializedAnnotations()
        .addEvent(
            new EventWithNanoTime<Annotation>(
                clock.nowNanos(),
                Annotation.fromDescriptionAndAttributes(description, attributes)));
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:18,代码来源:SpanImpl.java


示例2: emitSpans

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
/** Emits the list of SampledRequets with a header. */
private static void emitSpans(PrintWriter out, Formatter formatter, Collection<SpanData> spans) {
  out.write("<pre>\n");
  formatter.format("%-23s %18s%n", "When", "Elapsed(s)");
  out.write("-------------------------------------------\n");
  for (SpanData span : spans) {
    tracer
        .getCurrentSpan()
        .addAnnotation(
            "Render span.",
            ImmutableMap.<String, AttributeValue>builder()
                .put(
                    "SpanId",
                    AttributeValue.stringAttributeValue(
                        BaseEncoding.base16()
                            .lowerCase()
                            .encode(span.getContext().getSpanId().getBytes())))
                .build());

    emitSingleSpan(out, formatter, span);
  }
  out.write("</pre>\n");
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:24,代码来源:TracezZPageHandler.java


示例3: renderAttributes

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
private static String renderAttributes(Map<String, AttributeValue> attributes) {
  StringBuilder stringBuilder = new StringBuilder();
  stringBuilder.append("Attributes:{");
  boolean first = true;
  for (Map.Entry<String, AttributeValue> entry : attributes.entrySet()) {
    if (first) {
      first = false;
      stringBuilder.append(entry.getKey());
      stringBuilder.append("=");
      stringBuilder.append(attributeValueToString(entry.getValue()));
    } else {
      stringBuilder.append(", ");
      stringBuilder.append(entry.getKey());
      stringBuilder.append("=");
      stringBuilder.append(attributeValueToString(entry.getValue()));
    }
  }
  stringBuilder.append("}");
  return stringBuilder.toString();
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:21,代码来源:TracezZPageHandler.java


示例4: attributeValueToString

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
private static String attributeValueToString(AttributeValue attributeValue) {
  return attributeValue.match(
      new Function<String, String>() {
        @Override
        public String apply(String stringValue) {
          return stringValue;
        }
      },
      new Function<Boolean, String>() {
        @Override
        public String apply(Boolean booleanValue) {
          return booleanValue.toString();
        }
      },
      new Function<Long, String>() {
        @Override
        public String apply(Long longValue) {
          return longValue.toString();
        }
      },
      Functions.<String>returnNull());
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:23,代码来源:TracezZPageHandler.java


示例5: handle

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Override
public final void handle(HttpExchange httpExchange) throws IOException {
  try (Scope ss =
      tracer
          .spanBuilderWithExplicitParent(httpServerSpanName, null)
          .setRecordEvents(true)
          .startScopedSpan()) {
    tracer
        .getCurrentSpan()
        .putAttribute(
            "/http/method ",
            AttributeValue.stringAttributeValue(httpExchange.getRequestMethod()));
    httpExchange.sendResponseHeaders(200, 0);
    zpageHandler.emitHtml(
        uriQueryToMap(httpExchange.getRequestURI()), httpExchange.getResponseBody());
  } finally {
    httpExchange.close();
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:20,代码来源:ZPageHttpHandler.java


示例6: create

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
/**
 * Returns a new immutable {@code Attributes}.
 *
 * @param attributeMap the set of attributes.
 * @param droppedAttributesCount the number of dropped attributes.
 * @return a new immutable {@code Attributes}.
 */
public static Attributes create(
    Map<String, AttributeValue> attributeMap, int droppedAttributesCount) {
  // TODO(bdrutu): Consider to use LinkedHashMap here and everywhere else, less test flakes
  // for others on account of determinism.
  return new AutoValue_SpanData_Attributes(
      Collections.unmodifiableMap(
          new HashMap<String, AttributeValue>(checkNotNull(attributeMap, "attributeMap"))),
      droppedAttributesCount);
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:17,代码来源:SpanData.java


示例7: setUp

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Before
public void setUp() {
  attributesMap.put("MyAttributeKey1", AttributeValue.longAttributeValue(10));
  attributesMap.put("MyAttributeKey2", AttributeValue.booleanAttributeValue(true));
  attributes = Attributes.create(attributesMap, 1);
  annotationsList.add(SpanData.TimedEvent.create(eventTimestamp1, annotation));
  annotationsList.add(SpanData.TimedEvent.create(eventTimestamp3, annotation));
  annotations = TimedEvents.create(annotationsList, 2);
  networkEventsList.add(SpanData.TimedEvent.create(eventTimestamp1, recvNetworkEvent));
  networkEventsList.add(SpanData.TimedEvent.create(eventTimestamp2, sentNetworkEvent));
  networkEvents = TimedEvents.create(networkEventsList, 3);
  linksList.add(Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN));
  links = Links.create(linksList, 0);
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:15,代码来源:SpanDataTest.java


示例8: spanData_AllDataEmpty

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void spanData_AllDataEmpty() {
  SpanData spanData =
      SpanData.create(
          spanContext,
          parentSpanId,
          false,
          SPAN_NAME,
          startTimestamp,
          Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<Annotation>>emptyList(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<NetworkEvent>>emptyList(), 0),
          Links.create(Collections.<Link>emptyList(), 0),
          0,
          status,
          endTimestamp);
  assertThat(spanData.getContext()).isEqualTo(spanContext);
  assertThat(spanData.getParentSpanId()).isEqualTo(parentSpanId);
  assertThat(spanData.getHasRemoteParent()).isFalse();
  assertThat(spanData.getName()).isEqualTo(SPAN_NAME);
  assertThat(spanData.getStartTimestamp()).isEqualTo(startTimestamp);
  assertThat(spanData.getAttributes().getAttributeMap().isEmpty()).isTrue();
  assertThat(spanData.getAnnotations().getEvents().isEmpty()).isTrue();
  assertThat(spanData.getNetworkEvents().getEvents().isEmpty()).isTrue();
  assertThat(spanData.getLinks().getLinks().isEmpty()).isTrue();
  assertThat(spanData.getChildSpanCount()).isEqualTo(0);
  assertThat(spanData.getStatus()).isEqualTo(status);
  assertThat(spanData.getEndTimestamp()).isEqualTo(endTimestamp);
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:30,代码来源:SpanDataTest.java


示例9: putAttribute

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
/** This benchmark attempts to measure performance of adding an attribute to the span. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public Span putAttribute() {
  span.putAttribute(ATTRIBUTE_KEY, AttributeValue.stringAttributeValue(ATTRIBUTE_VALUE));
  return span;
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:9,代码来源:RecordTraceEventsNonSampledSpanBenchmark.java


示例10: toSpanData

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
/**
 * Returns an immutable representation of all the data from this {@code Span}.
 *
 * @return an immutable representation of all the data from this {@code Span}.
 * @throws IllegalStateException if the Span doesn't have RECORD_EVENTS option.
 */
public SpanData toSpanData() {
  checkState(
      getOptions().contains(Options.RECORD_EVENTS),
      "Getting SpanData for a Span without RECORD_EVENTS option.");
  synchronized (this) {
    SpanData.Attributes attributesSpanData =
        attributes == null
            ? SpanData.Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0)
            : SpanData.Attributes.create(attributes, attributes.getNumberOfDroppedAttributes());
    SpanData.TimedEvents<Annotation> annotationsSpanData =
        createTimedEvents(getInitializedAnnotations(), timestampConverter);
    SpanData.TimedEvents<NetworkEvent> networkEventsSpanData =
        createTimedEvents(getInitializedNetworkEvents(), timestampConverter);
    SpanData.Links linksSpanData =
        links == null
            ? SpanData.Links.create(Collections.<Link>emptyList(), 0)
            : SpanData.Links.create(
                new ArrayList<Link>(links.events), links.getNumberOfDroppedEvents());
    return SpanData.create(
        getContext(),
        parentSpanId,
        hasRemoteParent,
        name,
        CheckerFrameworkUtils.castNonNull(timestampConverter).convertNanoTime(startNanoTime),
        attributesSpanData,
        annotationsSpanData,
        networkEventsSpanData,
        linksSpanData,
        null, // Not supported yet.
        hasBeenEnded ? getStatusWithDefault() : null,
        hasBeenEnded
            ? CheckerFrameworkUtils.castNonNull(timestampConverter).convertNanoTime(endNanoTime)
            : null);
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:42,代码来源:SpanImpl.java


示例11: putAttribute

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Override
public void putAttribute(String key, AttributeValue value) {
  if (!getOptions().contains(Options.RECORD_EVENTS)) {
    return;
  }
  synchronized (this) {
    if (hasBeenEnded) {
      logger.log(Level.FINE, "Calling putAttributes() on an ended Span.");
      return;
    }
    getInitializedAttributes().putAttribute(key, value);
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:14,代码来源:SpanImpl.java


示例12: putAttributes

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Override
public void putAttributes(Map<String, AttributeValue> attributes) {
  if (!getOptions().contains(Options.RECORD_EVENTS)) {
    return;
  }
  synchronized (this) {
    if (hasBeenEnded) {
      logger.log(Level.FINE, "Calling putAttributes() on an ended Span.");
      return;
    }
    getInitializedAttributes().putAttributes(attributes);
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:14,代码来源:SpanImpl.java


示例13: setUp

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  attributes.put(
      "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  attributes.put("MyLongAttributeKey", AttributeValue.longAttributeValue(123L));
  attributes.put("MyBooleanAttributeKey", AttributeValue.booleanAttributeValue(false));
  expectedAttributes.putAll(attributes);
  expectedAttributes.put(
      "MySingleStringAttributeKey",
      AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:13,代码来源:SpanImplTest.java


示例14: noEventsRecordedAfterEnd

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void noEventsRecordedAfterEnd() {
  SpanImpl span =
      SpanImpl.startSpan(
          spanContext,
          recordSpanOptions,
          SPAN_NAME,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  span.end();
  // Check that adding trace events after Span#end() does not throw any exception and are not
  // recorded.
  span.putAttributes(attributes);
  span.putAttribute(
      "MySingleStringAttributeKey",
      AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
  span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  span.addNetworkEvent(
      NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build());
  span.addLink(Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN));
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getStartTimestamp()).isEqualTo(timestamp);
  assertThat(spanData.getAttributes().getAttributeMap()).isEmpty();
  assertThat(spanData.getAnnotations().getEvents()).isEmpty();
  assertThat(spanData.getNetworkEvents().getEvents()).isEmpty();
  assertThat(spanData.getLinks().getLinks()).isEmpty();
  assertThat(spanData.getStatus()).isEqualTo(Status.OK);
  assertThat(spanData.getEndTimestamp()).isEqualTo(timestamp);
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:35,代码来源:SpanImplTest.java


示例15: spanDataEquals

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void spanDataEquals() {
  SpanData allSpanData1 =
      SpanData.create(
          spanContext,
          parentSpanId,
          false,
          SPAN_NAME,
          startTimestamp,
          attributes,
          annotations,
          networkEvents,
          links,
          CHILD_SPAN_COUNT,
          status,
          endTimestamp);
  SpanData allSpanData2 =
      SpanData.create(
          spanContext,
          parentSpanId,
          false,
          SPAN_NAME,
          startTimestamp,
          attributes,
          annotations,
          networkEvents,
          links,
          CHILD_SPAN_COUNT,
          status,
          endTimestamp);
  SpanData emptySpanData =
      SpanData.create(
          spanContext,
          parentSpanId,
          false,
          SPAN_NAME,
          startTimestamp,
          Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<Annotation>>emptyList(), 0),
          TimedEvents.create(Collections.<SpanData.TimedEvent<NetworkEvent>>emptyList(), 0),
          Links.create(Collections.<Link>emptyList(), 0),
          0,
          status,
          endTimestamp);
  new EqualsTester()
      .addEqualityGroup(allSpanData1, allSpanData2)
      .addEqualityGroup(emptySpanData)
      .testEquals();
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:50,代码来源:SpanDataTest.java


示例16: removeEldestEntry

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Override
protected boolean removeEldestEntry(Map.Entry<String, AttributeValue> eldest) {
  return size() > this.capacity;
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:5,代码来源:SpanImpl.java


示例17: toSpanData_ActiveSpan

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void toSpanData_ActiveSpan() {
  SpanImpl span =
      SpanImpl.startSpan(
          spanContext,
          recordSpanOptions,
          SPAN_NAME,
          parentSpanId,
          true,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span);
  span.putAttribute(
      "MySingleStringAttributeKey",
      AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
  span.putAttributes(attributes);
  testClock.advanceTime(Duration.create(0, 100));
  span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  testClock.advanceTime(Duration.create(0, 100));
  span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  testClock.advanceTime(Duration.create(0, 100));
  NetworkEvent networkEvent =
      NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build();
  span.addNetworkEvent(networkEvent);
  testClock.advanceTime(Duration.create(0, 100));
  Link link = Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN);
  span.addLink(link);
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getContext()).isEqualTo(spanContext);
  assertThat(spanData.getName()).isEqualTo(SPAN_NAME);
  assertThat(spanData.getParentSpanId()).isEqualTo(parentSpanId);
  assertThat(spanData.getHasRemoteParent()).isTrue();
  assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(0);
  assertThat(spanData.getAttributes().getAttributeMap()).isEqualTo(expectedAttributes);
  assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(0);
  assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(2);
  assertThat(spanData.getAnnotations().getEvents().get(0).getTimestamp())
      .isEqualTo(timestamp.addNanos(100));
  assertThat(spanData.getAnnotations().getEvents().get(0).getEvent())
      .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp())
      .isEqualTo(timestamp.addNanos(200));
  assertThat(spanData.getAnnotations().getEvents().get(1).getEvent())
      .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes));
  assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0);
  assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);
  assertThat(spanData.getNetworkEvents().getEvents().get(0).getTimestamp())
      .isEqualTo(timestamp.addNanos(300));
  assertThat(spanData.getNetworkEvents().getEvents().get(0).getEvent()).isEqualTo(networkEvent);
  assertThat(spanData.getLinks().getDroppedLinksCount()).isEqualTo(0);
  assertThat(spanData.getLinks().getLinks().size()).isEqualTo(1);
  assertThat(spanData.getLinks().getLinks().get(0)).isEqualTo(link);
  assertThat(spanData.getStartTimestamp()).isEqualTo(timestamp);
  assertThat(spanData.getStatus()).isNull();
  assertThat(spanData.getEndTimestamp()).isNull();
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:59,代码来源:SpanImplTest.java


示例18: toSpanData_EndedSpan

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void toSpanData_EndedSpan() {
  SpanImpl span =
      SpanImpl.startSpan(
          spanContext,
          recordSpanOptions,
          SPAN_NAME,
          parentSpanId,
          false,
          TraceParams.DEFAULT,
          startEndHandler,
          timestampConverter,
          testClock);
  Mockito.verify(startEndHandler, Mockito.times(1)).onStart(span);
  span.putAttribute(
      "MySingleStringAttributeKey",
      AttributeValue.stringAttributeValue("MySingleStringAttributeValue"));
  span.putAttributes(attributes);
  testClock.advanceTime(Duration.create(0, 100));
  span.addAnnotation(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  testClock.advanceTime(Duration.create(0, 100));
  span.addAnnotation(ANNOTATION_DESCRIPTION, attributes);
  testClock.advanceTime(Duration.create(0, 100));
  NetworkEvent networkEvent =
      NetworkEvent.builder(NetworkEvent.Type.RECV, 1).setUncompressedMessageSize(3).build();
  span.addNetworkEvent(networkEvent);
  Link link = Link.fromSpanContext(spanContext, Link.Type.CHILD_LINKED_SPAN);
  span.addLink(link);
  testClock.advanceTime(Duration.create(0, 100));
  span.end(EndSpanOptions.builder().setStatus(Status.CANCELLED).build());
  Mockito.verify(startEndHandler, Mockito.times(1)).onEnd(span);
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getContext()).isEqualTo(spanContext);
  assertThat(spanData.getName()).isEqualTo(SPAN_NAME);
  assertThat(spanData.getParentSpanId()).isEqualTo(parentSpanId);
  assertThat(spanData.getHasRemoteParent()).isFalse();
  assertThat(spanData.getAttributes().getDroppedAttributesCount()).isEqualTo(0);
  assertThat(spanData.getAttributes().getAttributeMap()).isEqualTo(expectedAttributes);
  assertThat(spanData.getAnnotations().getDroppedEventsCount()).isEqualTo(0);
  assertThat(spanData.getAnnotations().getEvents().size()).isEqualTo(2);
  assertThat(spanData.getAnnotations().getEvents().get(0).getTimestamp())
      .isEqualTo(timestamp.addNanos(100));
  assertThat(spanData.getAnnotations().getEvents().get(0).getEvent())
      .isEqualTo(Annotation.fromDescription(ANNOTATION_DESCRIPTION));
  assertThat(spanData.getAnnotations().getEvents().get(1).getTimestamp())
      .isEqualTo(timestamp.addNanos(200));
  assertThat(spanData.getAnnotations().getEvents().get(1).getEvent())
      .isEqualTo(Annotation.fromDescriptionAndAttributes(ANNOTATION_DESCRIPTION, attributes));
  assertThat(spanData.getNetworkEvents().getDroppedEventsCount()).isEqualTo(0);
  assertThat(spanData.getNetworkEvents().getEvents().size()).isEqualTo(1);
  assertThat(spanData.getNetworkEvents().getEvents().get(0).getTimestamp())
      .isEqualTo(timestamp.addNanos(300));
  assertThat(spanData.getNetworkEvents().getEvents().get(0).getEvent()).isEqualTo(networkEvent);
  assertThat(spanData.getLinks().getDroppedLinksCount()).isEqualTo(0);
  assertThat(spanData.getLinks().getLinks().size()).isEqualTo(1);
  assertThat(spanData.getLinks().getLinks().get(0)).isEqualTo(link);
  assertThat(spanData.getStartTimestamp()).isEqualTo(timestamp);
  assertThat(spanData.getStatus()).isEqualTo(Status.CANCELLED);
  assertThat(spanData.getEndTimestamp()).isEqualTo(timestamp.addNanos(400));
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:61,代码来源:SpanImplTest.java


示例19: droppingAttributes

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
@Test
public void droppingAttributes() {
  final int maxNumberOfAttributes = 8;
  TraceParams traceParams =
      TraceParams.DEFAULT.toBuilder().setMaxNumberOfAttributes(maxNumberOfAttributes).build();
  SpanImpl span =
      SpanImpl.startSpan(
          spanContext,
          recordSpanOptions,
          SPAN_NAME,
          parentSpanId,
          false,
          traceParams,
          startEndHandler,
          timestampConverter,
          testClock);
  for (int i = 0; i < 2 * maxNumberOfAttributes; i++) {
    Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
    attributes.put("MyStringAttributeKey" + i, AttributeValue.longAttributeValue(i));
    span.putAttributes(attributes);
  }
  SpanData spanData = span.toSpanData();
  assertThat(spanData.getAttributes().getDroppedAttributesCount())
      .isEqualTo(maxNumberOfAttributes);
  assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
  for (int i = 0; i < maxNumberOfAttributes; i++) {
    assertThat(
            spanData
                .getAttributes()
                .getAttributeMap()
                .get("MyStringAttributeKey" + (i + maxNumberOfAttributes)))
        .isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
  }
  span.end();
  spanData = span.toSpanData();
  assertThat(spanData.getAttributes().getDroppedAttributesCount())
      .isEqualTo(maxNumberOfAttributes);
  assertThat(spanData.getAttributes().getAttributeMap().size()).isEqualTo(maxNumberOfAttributes);
  for (int i = 0; i < maxNumberOfAttributes; i++) {
    assertThat(
            spanData
                .getAttributes()
                .getAttributeMap()
                .get("MyStringAttributeKey" + (i + maxNumberOfAttributes)))
        .isEqualTo(AttributeValue.longAttributeValue(i + maxNumberOfAttributes));
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:48,代码来源:SpanImplTest.java


示例20: emitHtmlBody

import io.opencensus.trace.AttributeValue; //导入依赖的package包/类
private void emitHtmlBody(Map<String, String> queryMap, PrintWriter out)
    throws UnsupportedEncodingException {
  if (runningSpanStore == null || sampledSpanStore == null) {
    out.write("OpenCensus implementation not available.");
    return;
  }
  Formatter formatter = new Formatter(out, Locale.US);
  emitSummaryTable(out, formatter);
  String spanName = queryMap.get(HEADER_SPAN_NAME);
  if (spanName != null) {
    tracer
        .getCurrentSpan()
        .addAnnotation(
            "Render spans.",
            ImmutableMap.<String, AttributeValue>builder()
                .put("SpanName", AttributeValue.stringAttributeValue(spanName))
                .build());
    String typeStr = queryMap.get(HEADER_SAMPLES_TYPE);
    if (typeStr != null) {
      List<SpanData> spans = null;
      RequestType type = RequestType.fromString(typeStr);
      if (type == RequestType.UNKNOWN) {
        return;
      }
      if (type == RequestType.RUNNING) {
        // Display running.
        spans =
            new ArrayList<>(
                runningSpanStore.getRunningSpans(RunningSpanStore.Filter.create(spanName, 0)));
        // Sort active spans incremental.
        Collections.sort(spans, new SpanDataComparator(true));
      } else {
        String subtypeStr = queryMap.get(HEADER_SAMPLES_SUB_TYPE);
        if (subtypeStr != null) {
          int subtype = Integer.parseInt(subtypeStr);
          if (type == RequestType.FAILED) {
            if (subtype < 0 || subtype >= CanonicalCode.values().length) {
              return;
            }
            // Display errors. subtype 0 means all.
            CanonicalCode code = subtype == 0 ? null : CanonicalCode.values()[subtype];
            spans =
                new ArrayList<>(
                    sampledSpanStore.getErrorSampledSpans(ErrorFilter.create(spanName, code, 0)));
          } else {
            if (subtype < 0 || subtype >= LatencyBucketBoundaries.values().length) {
              return;
            }
            // Display latency.
            LatencyBucketBoundaries latencyBucketBoundaries =
                LatencyBucketBoundaries.values()[subtype];
            spans =
                new ArrayList<>(
                    sampledSpanStore.getLatencySampledSpans(
                        LatencyFilter.create(
                            spanName,
                            latencyBucketBoundaries.getLatencyLowerNs(),
                            latencyBucketBoundaries.getLatencyUpperNs(),
                            0)));
            // Sort sampled spans decremental.
            Collections.sort(spans, new SpanDataComparator(false));
          }
        }
      }
      emitSpanNameAndCountPages(formatter, spanName, spans == null ? 0 : spans.size(), type);

      if (spans != null) {
        emitSpans(out, formatter, spans);
        emitLegend(out);
      }
    }
  }
}
 
开发者ID:census-instrumentation,项目名称:opencensus-java,代码行数:74,代码来源:TracezZPageHandler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TxnReadState类代码示例发布时间:2022-05-15
下一篇:
Java MultiDocumentAttachment类代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap