热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

io.opencensus.trace.SpanContext.getTraceId()方法的使用及代码示例

本文整理了Java中io.opencensus.trace.SpanContext.getTraceId()方法的一些代码示例,展示了SpanContext

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

SpanContext.getTraceId介绍

[英]Returns the trace identifier associated with this SpanContext.
[中]返回与此上下文关联的跟踪标识符。

代码示例

代码示例来源:origin: census-instrumentation/opencensus-java

/**
* Returns a new {@code Link}.
*
* @param context the context of the linked {@code Span}.
* @param type the type of the relationship with the linked {@code Span}.
* @return a new {@code Link}.
* @since 0.5
*/
public static Link fromSpanContext(SpanContext context, Type type) {
return new AutoValue_Link(context.getTraceId(), context.getSpanId(), type, EMPTY_ATTRIBUTES);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
* Returns a new {@code Link}.
*
* @param context the context of the linked {@code Span}.
* @param type the type of the relationship with the linked {@code Span}.
* @return a new {@code Link}.
*/
public static Link fromSpanContext(SpanContext context, Type type) {
return new AutoValue_Link(context.getTraceId(), context.getSpanId(), type, EMPTY_ATTRIBUTES);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
public >> extends @NonNull Object*/> void inject(
SpanContext spanContext, C carrier, Setter setter) {
checkNotNull(spanContext, "spanContext");
checkNotNull(setter, "setter");
checkNotNull(carrier, "carrier");
StringBuilder builder =
new StringBuilder()
.append(spanContext.getTraceId().toLowerBase16())
.append(SPAN_ID_DELIMITER)
.append(UnsignedLongs.toString(spanIdToLong(spanContext.getSpanId())))
.append(TRACE_OPTION_DELIMITER)
.append(spanContext.getTraceOptions().isSampled() ? SAMPLED : NOT_SAMPLED);
setter.put(carrier, HEADER_NAME, builder.toString());
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
public >> extends @NonNull Object*/> void inject(
SpanContext spanContext, C carrier, Setter setter) {
checkNotNull(spanContext, "spanContext");
checkNotNull(setter, "setter");
checkNotNull(carrier, "carrier");
setter.put(carrier, X_B3_TRACE_ID, spanContext.getTraceId().toLowerBase16());
setter.put(carrier, X_B3_SPAN_ID, spanContext.getSpanId().toLowerBase16());
if (spanContext.getTraceOptions().isSampled()) {
setter.put(carrier, X_B3_SAMPLED, SAMPLED_VALUE);
}
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
public byte[] toByteArray(SpanContext spanContext) {
checkNotNull(spanContext, "spanContext");
byte[] bytes = new byte[ALL_FORMAT_LENGTH];
bytes[VERSION_ID_OFFSET] = VERSION_ID;
bytes[TRACE_ID_FIELD_ID_OFFSET] = TRACE_ID_FIELD_ID;
spanContext.getTraceId().copyBytesTo(bytes, TRACE_ID_OFFSET);
bytes[SPAN_ID_FIELD_ID_OFFSET] = SPAN_ID_FIELD_ID;
spanContext.getSpanId().copyBytesTo(bytes, SPAN_ID_OFFSET);
bytes[TRACE_OPTION_FIELD_ID_OFFSET] = TRACE_OPTION_FIELD_ID;
spanContext.getTraceOptions().copyBytesTo(bytes, TRACE_OPTIONS_OFFSET);
return bytes;
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

@Override
public >> extends @NonNull Object*/> void inject(
SpanContext spanContext, C carrier, Setter setter) {
checkNotNull(spanContext, "spanContext");
checkNotNull(setter, "setter");
checkNotNull(carrier, "carrier");
setter.put(carrier, X_B3_TRACE_ID, spanContext.getTraceId().toLowerBase16());
setter.put(carrier, X_B3_SPAN_ID, spanContext.getSpanId().toLowerBase16());
if (spanContext.getTraceOptions().isSampled()) {
setter.put(carrier, X_B3_SAMPLED, SAMPLED_VALUE);
}
}

代码示例来源:origin: io.opencensus/opencensus-impl-core

@Override
public byte[] toByteArray(SpanContext spanContext) {
checkNotNull(spanContext, "spanContext");
byte[] bytes = new byte[ALL_FORMAT_LENGTH];
bytes[VERSION_ID_OFFSET] = VERSION_ID;
bytes[TRACE_ID_FIELD_ID_OFFSET] = TRACE_ID_FIELD_ID;
spanContext.getTraceId().copyBytesTo(bytes, TRACE_ID_OFFSET);
bytes[SPAN_ID_FIELD_ID_OFFSET] = SPAN_ID_FIELD_ID;
spanContext.getSpanId().copyBytesTo(bytes, SPAN_ID_OFFSET);
bytes[TRACE_OPTION_FIELD_ID_OFFSET] = TRACE_OPTION_FIELD_ID;
spanContext.getTraceOptions().copyBytesTo(bytes, TRACE_OPTIONS_OFFSET);
return bytes;
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void getTraceId() {
assertThat(first.getTraceId()).isEqualTo(TraceId.fromBytes(firstTraceIdBytes));
assertThat(second.getTraceId()).isEqualTo(TraceId.fromBytes(secondTraceIdBytes));
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void link_ToString() {
Link link = Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN, attributesMap);
assertThat(link.toString()).contains(spanContext.getTraceId().toString());
assertThat(link.toString()).contains(spanContext.getSpanId().toString());
assertThat(link.toString()).contains("CHILD_LINKED_SPAN");
assertThat(link.toString()).contains(attributesMap.toString());
link = Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN, attributesMap);
assertThat(link.toString()).contains(spanContext.getTraceId().toString());
assertThat(link.toString()).contains(spanContext.getSpanId().toString());
assertThat(link.toString()).contains("PARENT_LINKED_SPAN");
assertThat(link.toString()).contains(attributesMap.toString());
}
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void handleStartWithPublicEndpointShouldAddLink() throws Exception {
handlerForPublicEndpoint.handleStart(carrier, request);
verify(tracer).spanBuilderWithExplicitParent(any(String.class), any(Span.class));
verify(spanWithLocalParent).addLink(captor.capture());
Link link = captor.getValue();
assertThat(link.getSpanId()).isEqualTo(spanContextRemote.getSpanId());
assertThat(link.getTraceId()).isEqualTo(spanContextRemote.getTraceId());
assertThat(link.getType()).isEqualTo(Type.PARENT_LINKED_SPAN);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void invalidSpanContext() {
assertThat(SpanContext.INVALID.getTraceId()).isEqualTo(TraceId.INVALID);
assertThat(SpanContext.INVALID.getSpanId()).isEqualTo(SpanId.INVALID);
assertThat(SpanContext.INVALID.getTraceOptions()).isEqualTo(TraceOptions.DEFAULT);
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static void assertSpanEquals(
Span span, org.springframework.cloud.sleuth.Span sleuthSpan) {
assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16))
.isEqualTo(sleuthSpan.getTraceIdHigh());
assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16))
.isEqualTo(sleuthSpan.getTraceId());
assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16))
.isEqualTo(sleuthSpan.getSpanId());
assertThat(span.getContext().getTraceOptions().isSampled())
.isEqualTo(sleuthSpan.isExportable());
}
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static void addTracingData(
String tracePrefix, SpanContext span, LogEntry.Builder builder) {
builder.setTrace(formatTraceId(tracePrefix, span.getTraceId()));
builder.setSpanId(span.getSpanId().toLowerBase16());
builder.setTraceSampled(span.getTraceOptions().isSampled());
}

代码示例来源:origin: census-instrumentation/opencensus-java

/**
* Puts a {@link SpanContext} into the attachments of the given {@link MeasureMap}.
*
*

{@link TraceId} and {@link SpanId} of the {@link SpanContext} will be encoded in base 16
* lower case encoding.
*
* @param measureMap the {@code MeasureMap}
* @param spanContext the {@code SpanContext} to be put as attachments.
* @since 0.16
*/
public static void putSpanContextAttachments(MeasureMap measureMap, SpanContext spanContext) {
checkNotNull(measureMap, "measureMap");
checkNotNull(spanContext, "spanContext");
measureMap.putAttachment(ATTACHMENT_KEY_TRACE_ID, spanContext.getTraceId().toLowerBase16());
measureMap.putAttachment(ATTACHMENT_KEY_SPAN_ID, spanContext.getSpanId().toLowerBase16());
}

代码示例来源:origin: census-instrumentation/opencensus-java

private static final void assertSpanEquals(io.opencensus.trace.Span span, Span sleuthSpan) {
assertThat(span.getContext().isValid()).isTrue();
assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(0, 16), 16))
.isEqualTo(sleuthSpan.getTraceIdHigh());
assertThat(Long.parseLong(span.getContext().getTraceId().toLowerBase16().substring(16, 32), 16))
.isEqualTo(sleuthSpan.getTraceId());
assertThat(Long.parseLong(span.getContext().getSpanId().toLowerBase16(), 16))
.isEqualTo(sleuthSpan.getSpanId());
assertThat(span.getContext().getTraceOptions().isSampled())
.isEqualTo(sleuthSpan.isExportable());
}
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromSpanContext_ChildLink() {
Link link = Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN);
assertThat(link.getTraceId()).isEqualTo(spanContext.getTraceId());
assertThat(link.getSpanId()).isEqualTo(spanContext.getSpanId());
assertThat(link.getType()).isEqualTo(Type.CHILD_LINKED_SPAN);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromSpanContext_ParentLink() {
Link link = Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN);
assertThat(link.getTraceId()).isEqualTo(spanContext.getTraceId());
assertThat(link.getSpanId()).isEqualTo(spanContext.getSpanId());
assertThat(link.getType()).isEqualTo(Type.PARENT_LINKED_SPAN);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromSpanContext_ParentLink_WithAttributes() {
Link link = Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN, attributesMap);
assertThat(link.getTraceId()).isEqualTo(spanContext.getTraceId());
assertThat(link.getSpanId()).isEqualTo(spanContext.getSpanId());
assertThat(link.getType()).isEqualTo(Type.PARENT_LINKED_SPAN);
assertThat(link.getAttributes()).isEqualTo(attributesMap);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void fromSpanContext_ChildLink_WithAttributes() {
Link link = Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN, attributesMap);
assertThat(link.getTraceId()).isEqualTo(spanContext.getTraceId());
assertThat(link.getSpanId()).isEqualTo(spanContext.getSpanId());
assertThat(link.getType()).isEqualTo(Type.CHILD_LINKED_SPAN);
assertThat(link.getAttributes()).isEqualTo(attributesMap);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void startChildSpan_WithoutSpecifiedSampler() {
Span rootSpan =
SpanBuilderImpl.createWithParent(SPAN_NAME, null, spanBuilderOptions)
.setSampler(Samplers.neverSample())
.startSpan();
assertThat(rootSpan.getContext().isValid()).isTrue();
assertThat(rootSpan.getContext().getTraceOptions().isSampled()).isFalse();
// Don't apply the default sampler (always true) for child spans.
Span childSpan =
SpanBuilderImpl.createWithParent(SPAN_NAME, rootSpan, spanBuilderOptions).startSpan();
assertThat(childSpan.getContext().isValid()).isTrue();
assertThat(childSpan.getContext().getTraceId()).isEqualTo(rootSpan.getContext().getTraceId());
assertThat(childSpan.getContext().getTraceOptions().isSampled()).isFalse();
}

推荐阅读
author-avatar
縌风而行2010
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有