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


Java AttributeValue类代码示例

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


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


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