本文整理汇总了Java中com.google.cloud.trace.core.Labels类的典型用法代码示例。如果您正苦于以下问题:Java Labels类的具体用法?Java Labels怎么用?Java Labels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Labels类属于com.google.cloud.trace.core包,在下文中一共展示了Labels类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:25,代码来源:TraceProducer.java
示例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();
}
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:19,代码来源:TraceValve.java
示例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));
}
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:19,代码来源:TraceValveTest.java
示例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());
}
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:40,代码来源:TracerSpanInterceptor.java
示例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());
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:8,代码来源:TraceSinkV1.java
示例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());
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:11,代码来源:AppEngineTracer.java
示例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);
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:13,代码来源:AppEngineTracerTest.java
示例16: addRequestLabels
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Adds span label annotations based on the given HTTP servlet request to the given labels
* builder.
*
* @param request the http servlet request used to generate the span label annotations.
* @param labelsBuilder the labels builder to add span label annotations to.
*/
public static void addRequestLabels(HttpServletRequest request, Labels.Builder labelsBuilder) {
labelsBuilder.add("/http/method", request.getMethod());
labelsBuilder.add("/http/url", request.getRequestURL().toString());
if (request.getContentLength() != -1) {
labelsBuilder.add(
"/http/request/size", Integer.toString(request.getContentLength()));
}
labelsBuilder.add("/http/host", request.getServerName());
if (request.getHeader("user-agent") != null) {
labelsBuilder.add("/http/user_agent", request.getHeader("user-agent"));
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:20,代码来源:RequestLabelsHelper.java
示例17: addResponseLabels
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
/**
* Adds span label annotations based on the given HTTP servlet response to the given labels
* builder.
*
* @param response the http servlet response used to generate the span label annotations.
* @param labelsBuilder the labels builder to add span label annotations to.
*/
public static void addResponseLabels(HttpServletResponse response, Labels.Builder labelsBuilder) {
// Add "/http/status_code" to Integer.toString(response.getStatus()), if
// GAE supports 3.0.
if (response.getBufferSize() > 0) {
labelsBuilder.add(
"/http/response/size", Integer.toString(response.getBufferSize()));
}
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:16,代码来源:RequestLabelsHelper.java
示例18: annotateSpan
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void annotateSpan() throws Exception {
Labels labels = Labels.builder().add("key1", "value1").add("key2", "value2").build();
tracer.annotateSpan(testTraceContext, labels);
assertThat(tracer.annotateEvents).hasSize(1);
AnnotateEvent annotateEvent = tracer.annotateEvents.get(0);
assertThat(annotateEvent.getTraceContext()).isEqualTo(testTraceContext);
assertThat(annotateEvent.getLabels()).isEqualTo(labels);
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:10,代码来源:TestTracerTest.java
示例19: testReset
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void testReset() throws Exception {
TraceContext traceContext = tracer.startSpan("test");
tracer.annotateSpan(traceContext, Labels.builder().build());
tracer.setStackTrace(traceContext, StackTrace.builder().build());
tracer.endSpan(traceContext);
tracer.reset();
assertThat(tracer.stackTraceEvents).hasSize(0);
assertThat(tracer.annotateEvents).hasSize(0);
assertThat(tracer.stackTraceEvents).hasSize(0);
assertThat(tracer.endSpanEvents).hasSize(0);
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:13,代码来源:TestTracerTest.java
示例20: testGetTracer_No
import com.google.cloud.trace.core.Labels; //导入依赖的package包/类
@Test
public void testGetTracer_No() {
Tracer tracer = Trace.getTracer();
TraceContext context = tracer.startSpan("hello");
assertInvalid(context.getHandle().getCurrentSpanContext());
tracer.annotateSpan(context, Labels.builder().build());
tracer.setStackTrace(context, StackTrace.builder().build());
tracer.endSpan(context);
context = tracer.startSpan("hello", new StartSpanOptions());
assertInvalid(context.getHandle().getCurrentSpanContext());
tracer.endSpan(context, new EndSpanOptions());
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:14,代码来源:TraceTest.java
注:本文中的com.google.cloud.trace.core.Labels类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论