本文整理了Java中io.opentracing.Tracer.buildSpan()
方法的一些代码示例,展示了Tracer.buildSpan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tracer.buildSpan()
方法的具体详情如下:
包路径:io.opentracing.Tracer
类名称:Tracer
方法名:buildSpan
[英]Return a new SpanBuilder for a Span with the given operationName
.
You can override the operationName later via Span#setOperationName(String).
A contrived example:
Tracer tracer = ...
// Note: if there is a `tracer.active()` Scope, its `span()` will be used as the target
// of an implicit CHILD_OF Reference for "workScope.span()" when `startActive()` is invoked.
try (Scope workScope = tracer.buildSpan("DoWork").startActive()) {
workScope.span().setTag("...", "...");
// etc, etc
}
// It's also possible to create Spans manually, bypassing the ScopeManager activation.
Span http = tracer.buildSpan("HandleHTTPRequest")
.asChildOf(rpcSpanContext) // an explicit parent
.withTag("user_agent", req.UserAgent)
.withTag("lucky_number", 42)
.start();
[中]为具有给定“operationName”的跨度返回新的SpanBuilder。
您可以稍后通过Span#setOperationName(字符串)覆盖operationName。
一个人为的例子:
Tracer tracer = ...
// Note: if there is a `tracer.active()` Scope, its `span()` will be used as the target
// of an implicit CHILD_OF Reference for "workScope.span()" when `startActive()` is invoked.
try (Scope workScope = tracer.buildSpan("DoWork").startActive()) {
workScope.span().setTag("...", "...");
// etc, etc
}
// It's also possible to create Spans manually, bypassing the ScopeManager activation.
Span http = tracer.buildSpan("HandleHTTPRequest")
.asChildOf(rpcSpanContext) // an explicit parent
.withTag("user_agent", req.UserAgent)
.withTag("lucky_number", 42)
.start();
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public SpanBuilder buildSpan(String operationName) {
return tracer.buildSpan(operationName);
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public SpanWrappingSpanBuilder buildSpan(String operationName) {
return new SpanWrappingSpanBuilder(delegate.buildSpan(operationName), operationName, createSpanInterceptors());
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
Span span = OpenTracingUtils
.getRequestSpan(requestContext)
.orElse(GlobalTracer.get().buildSpan("ad-hoc-span-respA").startManual());
span.log("RespFilterA.filter() invoked");
}
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Span span = OpenTracingUtils
.getRequestSpan(requestContext)
.orElse(GlobalTracer.get().buildSpan("ad-hoc-span-reqB").startManual());
span.log("ReqFilterB.filter() invoked");
}
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Span span = OpenTracingUtils
.getRequestSpan(requestContext)
.orElse(GlobalTracer.get().buildSpan("ad-hoc-span-reqA").startManual());
span.log("ReqFilterA.filter() invoked");
}
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
Span span = OpenTracingUtils
.getRequestSpan(requestContext)
.orElse(GlobalTracer.get().buildSpan("ad-hoc-span-respB").startManual());
span.log("RespFilterB.filter() invoked");
}
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public void start() {
activeSpan = ShardingTracer.get().buildSpan(OPERATION_NAME).withTag(Tags.COMPONENT.getKey(), ShardingTags.COMPONENT_NAME).startActive();
ShardingExecuteDataMap.getDataMap().put(ACTIVE_SPAN_CONTINUATION, activeSpan.capture());
}
代码示例来源:origin: oracle/helidon
protected Span startNewSpan(SpanContext parentSpan, String name) {
Tracer.SpanBuilder spanBuilder = security.tracer().buildSpan(name);
spanBuilder.asChildOf(parentSpan);
return spanBuilder.start();
}
代码示例来源:origin: oracle/helidon
private <T> Span createWriteSpan(T obj) {
Tracer.SpanBuilder spanBuilder = tracer().buildSpan("content-write");
if (spanContext() != null) {
spanBuilder.asChildOf(spanContext());
}
if (obj != null) {
spanBuilder.withTag("response.type", obj.getClass().getName());
}
return spanBuilder.start();
}
代码示例来源:origin: oracle/helidon
private Span createSpan(ClientRequestContext requestContext, Tracer tracer, Optional<SpanContext> parentSpan) {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(SPAN_OPERATION_NAME)
.withTag(Tags.HTTP_METHOD.getKey(), requestContext.getMethod())
.withTag(Tags.HTTP_URL.getKey(), requestContext.getUri().toString());
parentSpan.ifPresent(spanBuilder::asChildOf);
return spanBuilder.start();
}
代码示例来源:origin: weibocom/motan
protected Span extractTraceInfo(Request request, Tracer tracer) {
String operationName = buildOperationName(request);
SpanBuilder span = tracer.buildSpan(operationName);
try {
SpanContext spanContext = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(request.getAttachments()));
if (spanContext != null) {
span.asChildOf(spanContext);
}
} catch (Exception e) {
span.withTag("Error", "extract from request fail, error msg:" + e.getMessage());
}
return span.start();
}
代码示例来源:origin: oracle/helidon
private <T> Span createReadSpan(Class<T> type) {
Tracer.SpanBuilder spanBuilder = tracer().buildSpan("content-read");
if (span() != null) {
spanBuilder.asChildOf(span());
}
if (type != null) {
spanBuilder.withTag("requested.type", type.getName());
}
return spanBuilder.start();
}
代码示例来源:origin: qunarcorp/qmq
@Override
public boolean preOnMessage(Message message, Map<String, Object> filterContext) {
SpanContext context = TraceUtil.extract(message, tracer);
Scope scope = tracer.buildSpan(TRACE_DESC)
.withTag("subject", message.getSubject())
.withTag("messageId", message.getMessageId())
.withTag("localRetries", String.valueOf(message.localRetries()))
.withTag("times", String.valueOf(message.times()))
.asChildOf(context)
.startActive(true);
filterContext.put(TRACE_OBJECT, scope.span());
return true;
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public void start(final String sql) {
span = ShardingTracer.get().buildSpan(OPERATION_NAME)
.withTag(Tags.COMPONENT.getKey(), ShardingTags.COMPONENT_NAME)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
.withTag(Tags.DB_STATEMENT.getKey(), sql).startManual();
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public Scope createScope() {
final Tracer tracer = tracingPlugin.getTracer();
final Tracer.SpanBuilder spanBuilder = tracer.buildSpan(methodSignature)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
final Scope scope = spanBuilder
.withTag(SpanUtils.OPERATION_TYPE, OP_TYPE_METHOD_INVOCATION)
.withTag(MetricsSpanEventListener.ENABLE_TRACKING_METRICS_TAG, true)
.startActive(true);
SpanUtils.setParameters(scope.span(), safeParameters);
return scope;
}
代码示例来源:origin: weibocom/motan
/**
* process trace in client end
*
* @param caller
* @param request
* @return
*/
protected Response processRefererTrace(Tracer tracer, Caller<?> caller, Request request) {
String operationName = buildOperationName(request);
SpanBuilder spanBuilder = tracer.buildSpan(operationName);
Span activeSpan = OpenTracingContext.getActiveSpan();
if (activeSpan != null) {
spanBuilder.asChildOf(activeSpan);
}
Span span = spanBuilder.start();
span.setTag("requestId", request.getRequestId());
attachTraceInfo(tracer, span, request);
return process(caller, request, span);
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
protected void handleInboundSOAPMessage(SOAPMessageContext context) {
final Tracer.SpanBuilder spanBuilder = tracingPlugin.getTracer()
.buildSpan(getOperationName(context))
.withTag(SpanUtils.OPERATION_TYPE, "soap")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
if (soapTracingPlugin.isSoapServerRecordRequestMessages()) {
spanBuilder.withTag("soap.request", getSoapMessageAsString(context));
}
spanBuilder.startActive(true);
}
代码示例来源:origin: stagemonitor/stagemonitor
private SpanContextInformation reportSpan(long executionTimeMs, CallStackElement callTree, String operationName) {
final Tracer tracer = tracingPlugin.getTracer();
final Span span;
Tracer.SpanBuilder spanBuilder = tracer.buildSpan(operationName)
.withStartTimestamp(1);
spanBuilder = setStartTags(spanBuilder);
span = spanBuilder
.start();
final SpanContextInformation spanContextInformation = SpanContextInformation.forSpan(span);
spanContextInformation.setCallTree(callTree);
// implicitly reports
span.finish(TimeUnit.MILLISECONDS.toMicros(executionTimeMs) + 1);
return spanContextInformation;
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
protected void handleOutboundSOAPMessage(SOAPMessageContext context) {
final Tracer.SpanBuilder spanBuilder = tracingPlugin.getTracer()
.buildSpan(getOperationName(context))
.withTag(SpanUtils.OPERATION_TYPE, "soap")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
if (soapTracingPlugin.isSoapClientRecordRequestMessages()) {
spanBuilder.withTag("soap.request", getSoapMessageAsString(context));
}
final Span span = spanBuilder.startActive(true).span();
tracingPlugin.getTracer().inject(span.context(), Format.Builtin.HTTP_HEADERS, new SOAPMessageInjectAdapter(context));
}
代码示例来源:origin: apache/incubator-shardingsphere
@Override
public void start(final RouteUnit routeUnit, final DataSourceMetaData dataSourceMetaData, final boolean isTrunkThread, final Map<String, Object> shardingExecuteDataMap) {
if (!isTrunkThread) {
activeSpan = ((ActiveSpan.Continuation) shardingExecuteDataMap.get(OpenTracingRootInvokeHook.ACTIVE_SPAN_CONTINUATION)).activate();
}
span = ShardingTracer.get().buildSpan(OPERATION_NAME)
.withTag(Tags.COMPONENT.getKey(), ShardingTags.COMPONENT_NAME)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
.withTag(Tags.PEER_HOSTNAME.getKey(), dataSourceMetaData.getHostName())
.withTag(Tags.PEER_PORT.getKey(), dataSourceMetaData.getPort())
.withTag(Tags.DB_TYPE.getKey(), "sql")
.withTag(Tags.DB_INSTANCE.getKey(), routeUnit.getDataSourceName())
.withTag(Tags.DB_STATEMENT.getKey(), routeUnit.getSqlUnit().getSql())
.withTag(ShardingTags.DB_BIND_VARIABLES.getKey(), toString(routeUnit.getSqlUnit().getParameterSets())).startManual();
}
内容来源于网络,如有侵权,请联系作者删除!