本文整理汇总了Java中com.google.cloud.trace.core.Labels类的典型用法代码示例。如果您正苦于以下问题:Java Labels类的具体用法?Java Labels怎么用?Java Labels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Labels类属于com.google.cloud.trace.core包,在下文中一共展示了Labels类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Starts a span for an HTTP request and record relevant labels.
* @param request The HTTP request.
* @return The new TraceContext
*/
public TraceContext process(HttpRequest request) {
Labels.Builder labels = Labels.builder();
TraceInterceptorUtil
.annotateIfNotEmpty(labels, HttpLabels.HTTP_METHOD, request.getURI().toString());
labels.add(HttpLabels.HTTP_METHOD, request.getMethod());
TraceInterceptorUtil
.annotateIfNotEmpty(labels, HttpLabels.HTTP_URL, request.getURI().toString());
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.HTTP_CLIENT_PROTOCOL,
request.getProtocol());
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.HTTP_USER_AGENT,
request.getHeader(HttpHeaders.USER_AGENT));
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.REQUEST_SIZE,
request.getHeader(HttpHeaders.CONTENT_LENGTH));
TraceContext traceContext = tracer.startSpan(request.getURI().getPath());
tracer.annotateSpan(traceContext, labels.build());
return traceContext;
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:23,代码来源:TraceHttpRequestInterceptor.java
示例2: exampleSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void exampleSpan() {
when(mockTracers.getCurrent()).thenReturn(mockTracer);
TraceService traceService = new CloudTraceSdkTraceService(mockTracers);
try (TraceService.Span span = traceService.open("JDBC.Driver#connect")) {
span.annotate(Label.DATABASE_URL, Optional.of("jdbc:mockdriver"));
span.annotate(Label.SQL_TEXT, Optional.absent());
}
ArgumentCaptor<Labels> labels = ArgumentCaptor.forClass(Labels.class);
InOrder inOrder = inOrder(mockTracer);
inOrder.verify(mockTracer).startSpan("JDBC.Driver#connect");
inOrder.verify(mockTracer).annotateSpan(eq(null), labels.capture());
inOrder.verify(mockTracer).endSpan(null);
verifyNoMoreInteractions(mockTracer); // No annotation for SQL_TEXT created.
assertThat(labels.getValue().getLabels())
.containsExactly(new com.google.cloud.trace.core.Label(
"g.co/jdbc/url", "jdbc:mockdriver"));
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:23,代码来源:CloudTraceSdkTraceServiceTest.java
示例3: commandStarted
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
public void commandStarted(CommandStartedEvent event) {
BsonDocument document = event.getCommand();
Labels.Builder labels = Labels.builder();
String commandName = event.getCommandName();
labels.add(MongoLabels.COMMAND_NAME, commandName);
String databaseName = event.getDatabaseName();
labels.add(MongoLabels.DATABASE_NAME, databaseName);
labels.add(MongoLabels.REQUEST_ID, Integer.toString(event.getRequestId()));
if (document.containsKey("batchSize")) {
int batchSize = document.getInt32("batchSize").getValue();
labels.add(MongoLabels.BATCH_SIZE, Integer.toString(batchSize));
}
String collectionKey = collectionKeyByCommand.get(commandName);
if (collectionKey != null && document.containsKey(collectionKey)) {
String collectionName = document.getString(collectionKey).getValue();
labels.add(MongoLabels.COLLECTION_NAME, collectionName);
}
TraceContext context = tracer.startSpan(commandName);
tracer.annotateSpan(context, labels.build());
contexts.set(new MongoDBCommandTraceContext(context, event.getRequestId()));
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:23,代码来源:TracingCommandListener.java
示例4: generateAnnotateSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Converts a span label annotation event into an API v1 trace message.
*
* @param projectId a string that contains the Google Cloud Platform project identifier.
* @param context a span context that represents the event span.
* @param labels a labels containing the label annotations for the event span.
* @return a trace message that represents the span label annotation event.
*/
public Trace generateAnnotateSpan(String projectId, SpanContext context, Labels labels) {
TraceSpan.Builder spanBuilder =
TraceSpan.newBuilder().setSpanId(context.getSpanId().getSpanId());
for (Label label : labels.getLabels()) {
spanBuilder.putLabels(label.getKey(), label.getValue());
}
Trace.Builder traceBuilder =
Trace.newBuilder()
.setProjectId(projectId)
.setTraceId(formatTraceId(context.getTraceId()))
.addSpans(spanBuilder.build());
return traceBuilder.build();
}
示例5: createLabels
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Create labels for Stackdriver trace with basic response and request info.
*/
private Labels createLabels(Request request, Response response) {
Labels.Builder labels = Labels.builder();
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_METHOD.getValue(), request.getMethod());
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_URL.getValue(), request.getRequestURI());
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_CLIENT_PROTOCOL.getValue(),
request.getProtocol());
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_USER_AGENT.getValue(),
request.getHeader(HttpHeaders.USER_AGENT));
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_REQUEST_SIZE.getValue(),
request.getHeader(HttpHeaders.CONTENT_LENGTH));
this.annotateIfNotEmpty(labels, HttpLabels.HTTP_RESPONSE_SIZE.getValue(),
response.getHeader(HttpHeaders.CONTENT_LENGTH));
labels.add(HttpLabels.HTTP_STATUS_CODE.getValue(), Integer.toString(response.getStatus()));
return labels.build();
}
示例6: testSpanCreation
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void testSpanCreation() throws Exception {
when(request.getRequestURI()).thenReturn("/index");
when(response.getStatus()).thenReturn(200);
ArgumentCaptor<Labels> labelsArgument = ArgumentCaptor.forClass(Labels.class);
ArgumentCaptor<TraceContext> traceArgument = ArgumentCaptor.forClass(TraceContext.class);
Label indexLabel = new Label(HttpLabels.HTTP_URL.getValue(), "/index");
Label statusCodeLabel = new Label(HttpLabels.HTTP_STATUS_CODE.getValue(), "200");
valve.invoke(request, response);
verify(tracer).startSpan(matches("/index"));
verify(tracer).annotateSpan(traceArgument.capture(), labelsArgument.capture());
verify(tracer).endSpan(traceContext);
assertEquals(labelsArgument.getValue().getLabels().size(), 2);
assertTrue(labelsArgument.getValue().getLabels().contains(indexLabel));
assertTrue(labelsArgument.getValue().getLabels().contains(statusCodeLabel));
}
示例7: annotateFromHeader
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
static void annotateFromHeader(Labels.Builder labels, String key, Header header) {
if (header != null) {
String headerValue = header.getValue();
if (headerValue != null && headerValue.length() > 0) {
labels.add(key, header.getValue());
}
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:9,代码来源:TraceInterceptorUtil.java
示例8: process
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Ends a span for an HTTP request and records relevant labels.
* @param response The HTTP response.
* @param traceContext The TraceContext for the request.
*/
public void process(HttpResponse response, TraceContext traceContext) {
if (traceContext == null) {
return;
}
Labels.Builder labels = Labels.builder();
TraceInterceptorUtil.annotateIfNotEmpty(labels, HttpLabels.RESPONSE_SIZE,
response.getHeader(HttpHeaders.CONTENT_LENGTH));
labels.add(HttpLabels.HTTP_STATUS_CODE, Integer.toString(response.getStatus()));
tracer.annotateSpan(traceContext, labels.build());
tracer.endSpan(traceContext);
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:17,代码来源:TraceHttpResponseInterceptor.java
示例9: annotate
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Override
public void annotate(Label label, Optional<String> value) {
checkNotNull(label);
checkNotNull(value);
if (value.isPresent()) {
tracer.annotateSpan(traceContext, Labels.builder().add(label.key(), value.get()).build());
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:10,代码来源:CloudTraceSdkTraceService.java
示例10: commandSucceeded
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
public void commandSucceeded(CommandSucceededEvent event) {
MongoDBCommandTraceContext commandContext = contexts.get();
if (commandContext == null || commandContext.getRequestId() != event.getRequestId()) {
contexts.remove();
return;
}
Labels.Builder labels = Labels.builder();
labels.add(MongoLabels.STATUS, "SUCCESS");
tracer.annotateSpan(commandContext.getContext(), labels.build());
tracer.endSpan(commandContext.getContext());
contexts.remove();
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:13,代码来源:TracingCommandListener.java
示例11: commandFailed
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
public void commandFailed(CommandFailedEvent event) {
MongoDBCommandTraceContext commandContext = contexts.get();
if (commandContext == null || commandContext.getRequestId() != event.getRequestId()) {
// The context doesn't match the requestId for the event so don't make any endSpan() or
// annotate() calls. Drop the context since it likely can't be used again.
contexts.remove();
return;
}
Labels.Builder labels = Labels.builder();
labels.add(MongoLabels.STATUS, "FAILURE");
labels.add(MongoLabels.ERROR, event.getThrowable().getMessage());
tracer.annotateSpan(commandContext.getContext(), labels.build());
tracer.endSpan(commandContext.getContext());
contexts.remove();
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:16,代码来源:TracingCommandListener.java
示例12: addParameterAnnotations
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
private void addParameterAnnotations(MethodInvocation invocation,
Labels.Builder labelsBuilder, boolean labelAllParams, String labelPrefix) {
Annotation[][] annotationsArray = invocation.getMethod().getParameterAnnotations();
for (int i = 0; i < annotationsArray.length; i++) {
Label label = null;
Name name = null;
for (Annotation annotation : annotationsArray[i]) {
if (annotation.annotationType() == Label.class) {
label = (Label)annotation;
} else if (annotation.annotationType() == Name.class) {
name = (Name)annotation;
}
}
boolean enabled;
String parameterName;
if (label != null) {
enabled = label.enabled();
if (label.name().equals("/")) {
parameterName = String.format("%s/arg%d", labelPrefix, i);
} else if (label.name().isEmpty()) {
parameterName = labelPrefix;
} else {
parameterName = String.format("%s/%s", labelPrefix, label.name());
}
} else {
enabled = false;
parameterName = String.format("%s/arg%d", labelPrefix, i);
}
if (labelAllParams) {
enabled = true;
}
if (name != null) {
parameterName = name.value();
}
if (enabled) {
labelsBuilder.add(parameterName, invocation.getArguments()[i].toString());
}
}
}
示例13: annotateSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Override
public void annotateSpan(SpanContext context, Labels labels) {
if (context.getTraceOptions().getTraceEnabled()) {
Trace trace = traceProducer.generateAnnotateSpan(projectId, context, labels);
traceConsumer.receive(Traces.newBuilder().addTraces(trace).build());
}
}
示例14: annotateSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Override
public void annotateSpan(TraceContext traceContext, Labels labels) {
checkNotNull(traceContext);
checkNotNull(labels);
Span span = getSpan(traceContext);
for (Label label : labels.getLabels()) {
span.setLabel(label.getKey(), label.getValue());
}
}
示例15: annotateSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void annotateSpan() {
when(mockTraceService.startSpan("test span")).thenReturn(mockSpan);
TraceContext traceContext = tracer.startSpan("test span");
tracer.annotateSpan(
traceContext, Labels.builder().add("key1", "value1").add("key2", "value2").build());
verify(mockSpan).setLabel("key1", "value1");
verify(mockSpan).setLabel("key2", "value2");
verifyNoMoreInteractions(mockSpan);
}