本文整理了Java中io.opentracing.Span.setBaggageItem()
方法的一些代码示例,展示了Span.setBaggageItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.setBaggageItem()
方法的具体详情如下:
包路径:io.opentracing.Span
类名称:Span
方法名:setBaggageItem
[英]Sets a baggage item in the Span (and its SpanContext) as a key/value pair. Baggage enables powerful distributed context propagation functionality where arbitrary application data can be carried along the full path of request execution throughout the system. Note 1: Baggage is only propagated to the future (recursive) children of this SpanContext. Note 2: Baggage is sent in-band with every subsequent local and remote calls, so this feature must be used with care.
[中]将Span(及其Span上下文)中的行李项设置为键/值对。Baggage支持强大的分布式上下文传播功能,其中任意应用程序数据可以在整个系统中沿着请求执行的完整路径进行传输。注1:Baggage仅传播给该上下文的未来(递归)子级。注2:每次后续的本地和远程呼叫都会在带内发送行李,因此必须小心使用此功能。
代码示例来源:origin: oracle/helidon
@Override
public Span setBaggageItem(String key, String value) {
span.setBaggageItem(key, value);
return this;
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public Span setBaggageItem(String key, String value) {
delegate = delegate.setBaggageItem(key, value);
return this;
}
代码示例来源:origin: jersey/jersey
/**
* Similar as {@link #appLevelLogging(ContainerRequestContext)}, just with {@code POST} method.
*
* @param entity posted entity
* @param context injected context
* @return dummy response
*/
@POST
@Path("appLevelPost")
public Response tracePost(String entity, @Context ContainerRequestContext context) {
final Span resourceSpan = OpenTracingUtils
.getRequestSpan(context)
.orElseThrow(() -> new RuntimeException("Tracing has failed"));
resourceSpan.setTag("result", "42");
resourceSpan.setBaggageItem("entity", entity);
return Response.ok("Done!").build();
}
代码示例来源:origin: io.helidon.webserver/helidon-webserver-zipkin
@Override
public Span setBaggageItem(String key, String value) {
span.setBaggageItem(key, value);
return this;
}
代码示例来源:origin: redhat-developer-demos/istio-tutorial
public void addTracer(Exchange exchange){
String userAgent = (String) exchange.getIn().getHeader("user-agent");
Span span = ActiveSpanManager.getSpan(exchange);
span.setBaggageItem("user-agent",userAgent);
}
}
代码示例来源:origin: io.opentracing.contrib/opentracing-spanmanager
@Override
public Span setBaggageItem(String key, String value) {
getSpan().setBaggageItem(key, value);
return this;
}
代码示例来源:origin: io.opentracing.contrib/opentracing-api-extensions-tracer
@Override
public Span setBaggageItem(String name, String value) {
if (wrappedSpan != null) {
wrappedSpan.setBaggageItem(name, value);
}
for (SpanObserver observer : observers) {
observer.onSetBaggageItem(this, name, value);
}
return this;
}
代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.tracing
/**
* Set the baggage item to the span which can be passed to the distributed systems
*
* @param span
* @param key
* @param value
* */
public static void baggageSet(TracingSpan span, String key, String value) {
Object sp = span.getSpan();
if (sp instanceof Span) {
((Span) sp).setBaggageItem(key, value);
}
}
代码示例来源:origin: objectiser/opentracing-prometheus-example
@RequestMapping("/sell")
public String sell() throws InterruptedException {
Thread.sleep(1 + (long)(Math.random()*500));
Optional.ofNullable(tracer.activeSpan()).ifPresent(as -> as.setBaggageItem("transaction", "sell"));
ResponseEntity<String> response = restTemplate.getForEntity(accountMgrUrl + "/account", String.class);
return "SELL + " + response.getBody();
}
代码示例来源:origin: objectiser/opentracing-prometheus-example
@RequestMapping("/buy")
public String buy() throws InterruptedException {
Thread.sleep(1 + (long)(Math.random()*500));
Optional.ofNullable(tracer.activeSpan()).ifPresent(as -> as.setBaggageItem("transaction", "buy"));
try (Scope scope = tracer.buildSpan("SomeWork").startActive(true)) {
scope.span().setTag("work", "buying");
ResponseEntity<String> response = restTemplate.getForEntity(accountMgrUrl + "/account", String.class);
return "BUY + " + response.getBody();
}
}
代码示例来源:origin: redhat-developer-demos/istio-tutorial
@RequestMapping(value = "/", method = RequestMethod.GET)
public ResponseEntity<String> getCustomer(@RequestHeader("User-Agent") String userAgent, @RequestHeader(value = "user-preference", required = false) String userPreference) {
try {
/**
* Set baggage
*/
tracer.activeSpan().setBaggageItem("user-agent", userAgent);
if (userPreference != null && !userPreference.isEmpty()) {
tracer.activeSpan().setBaggageItem("user-preference", userPreference);
}
ResponseEntity<String> responseEntity = restTemplate.getForEntity(remoteURL, String.class);
String response = responseEntity.getBody();
return ResponseEntity.ok(String.format(RESPONSE_STRING_FORMAT, response.trim()));
} catch (HttpStatusCodeException ex) {
logger.warn("Exception trying to get the response from preference service.", ex);
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(String.format(RESPONSE_STRING_FORMAT,
String.format("%d %s", ex.getRawStatusCode(), createHttpErrorResponseString(ex))));
} catch (RestClientException ex) {
logger.warn("Exception trying to get the response from preference service.", ex);
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE)
.body(String.format(RESPONSE_STRING_FORMAT, ex.getMessage()));
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
@SuppressWarnings({"unchecked"})
public D call(final GetResponse response) {
Transcoder<?, Object> transcoder = (Transcoder<?, Object>) transcoders.get(target);
Scope decodeScope = null;
if (environment.operationTracingEnabled()) {
decodeScope = environment.tracer()
.buildSpan("response_decoding")
.asChildOf(response.request().span())
.startActive(true);
}
D decoded = (D) transcoder.decode(id, response.content(), response.cas(), 0,
response.flags(), response.status());
if (environment.operationTracingEnabled() && decodeScope != null) {
decodeScope.close();
if (decodeScope.span() instanceof ThresholdLogSpan) {
decodeScope.span().setBaggageItem(ThresholdLogReporter.KEY_DECODE_MICROS,
Long.toString(((ThresholdLogSpan) decodeScope.span()).durationMicros())
);
}
}
if (environment.operationTracingEnabled()) {
environment.tracer().scopeManager()
.activate(response.request().span(), true)
.close();
}
return decoded;
}
代码示例来源:origin: com.couchbase.client/java-client
encodeScope.close();
if (encodeScope.span() instanceof ThresholdLogSpan) {
encodeScope.span().setBaggageItem(ThresholdLogReporter.KEY_ENCODE_MICROS,
Long.toString(((ThresholdLogSpan) encodeScope.span()).durationMicros())
);
代码示例来源:origin: com.couchbase.client/java-client
encodeScope.close();
if (encodeScope.span() instanceof ThresholdLogSpan) {
encodeScope.span().setBaggageItem(ThresholdLogReporter.KEY_ENCODE_MICROS,
Long.toString(((ThresholdLogSpan) encodeScope.span()).durationMicros())
);
代码示例来源:origin: com.couchbase.client/java-client
encodeScope.close();
if (encodeScope.span() instanceof ThresholdLogSpan) {
encodeScope.span().setBaggageItem(ThresholdLogReporter.KEY_ENCODE_MICROS,
Long.toString(((ThresholdLogSpan) encodeScope.span()).durationMicros())
);
代码示例来源:origin: com.couchbase.client/java-client
encodeScope.close();
if (encodeScope.span() instanceof ThresholdLogSpan) {
encodeScope.span().setBaggageItem(ThresholdLogReporter.KEY_ENCODE_MICROS,
Long.toString(((ThresholdLogSpan) encodeScope.span()).durationMicros())
);
代码示例来源:origin: com.couchbase.client/core-io
/**
* Fulfill and complete the response observable.
*
* When called directly, this method completes on the event loop, but it can also be used in a callback (see
* {@link #scheduleDirect(CoreScheduler, CouchbaseResponse, Subject)} for example.
*/
private void completeResponse(final CouchbaseResponse response,
final Subject<CouchbaseResponse, CouchbaseResponse> observable) {
// Noone is listening anymore, handle tracing and/or orphan reporting
// depending on if enabled or not.
CouchbaseRequest request = response.request();
if (request != null && !request.isActive()) {
if (env().operationTracingEnabled() && request.span() != null) {
Scope scope = env().tracer().scopeManager()
.activate(request.span(), true);
scope.span().setBaggageItem("couchbase.orphan", "true");
scope.close();
}
if (env().orphanResponseReportingEnabled()) {
env().orphanResponseReporter().report(response);
}
}
try {
observable.onNext(response);
observable.onCompleted();
} catch (Exception ex) {
LOGGER.warn("Caught exception while onNext on observable", ex);
observable.onError(ex);
}
}
代码示例来源:origin: couchbase/couchbase-jvm-core
/**
* Fulfill and complete the response observable.
*
* When called directly, this method completes on the event loop, but it can also be used in a callback (see
* {@link #scheduleDirect(CoreScheduler, CouchbaseResponse, Subject)} for example.
*/
private void completeResponse(final CouchbaseResponse response,
final Subject<CouchbaseResponse, CouchbaseResponse> observable) {
// Noone is listening anymore, handle tracing and/or orphan reporting
// depending on if enabled or not.
CouchbaseRequest request = response.request();
if (request != null && !request.isActive()) {
if (env().operationTracingEnabled() && request.span() != null) {
Scope scope = env().tracer().scopeManager()
.activate(request.span(), true);
scope.span().setBaggageItem("couchbase.orphan", "true");
scope.close();
}
if (env().orphanResponseReportingEnabled()) {
env().orphanResponseReporter().report(response);
}
}
try {
observable.onNext(response);
observable.onCompleted();
} catch (Exception ex) {
LOGGER.warn("Caught exception while onNext on observable", ex);
observable.onError(ex);
}
}
代码示例来源:origin: com.couchbase.client/core-io
.close();
if (currentDispatchSpan instanceof ThresholdLogSpan) {
currentDispatchSpan.setBaggageItem(
ThresholdLogReporter.KEY_DISPATCH_MICROS,
Long.toString(((ThresholdLogSpan) currentDispatchSpan).durationMicros())
代码示例来源:origin: couchbase/couchbase-jvm-core
.close();
if (currentDispatchSpan instanceof ThresholdLogSpan) {
currentDispatchSpan.setBaggageItem(
ThresholdLogReporter.KEY_DISPATCH_MICROS,
Long.toString(((ThresholdLogSpan) currentDispatchSpan).durationMicros())
内容来源于网络,如有侵权,请联系作者删除!