当前位置: 首页>>代码示例>>Java>>正文


Java Labels.Builder方法代码示例

本文整理汇总了Java中com.google.cloud.trace.core.Labels.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java Labels.Builder方法的具体用法?Java Labels.Builder怎么用?Java Labels.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.cloud.trace.core.Labels的用法示例。


在下文中一共展示了Labels.Builder方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: annotateIfNotEmpty

import com.google.cloud.trace.core.Labels; //导入方法依赖的package包/类
static void annotateIfNotEmpty(Labels.Builder labels, String key, String value) {
  if (value != null && value.length() > 0) {
    labels.add(key, value);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:6,代码来源:TraceInterceptorUtil.java

示例12: addLabelsBeforeCall

import com.google.cloud.trace.core.Labels; //导入方法依赖的package包/类
@Override
public void addLabelsBeforeCall(Labels.Builder labelsBuilder) {
  RequestLabelsHelper.addRequestLabels(requestProvider.get(), labelsBuilder);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:5,代码来源:RequestLabeler.java

示例13: addLabelsAfterCall

import com.google.cloud.trace.core.Labels; //导入方法依赖的package包/类
@Override
public void addLabelsAfterCall(Labels.Builder labelsBuilder) {
  RequestLabelsHelper.addResponseLabels(responseProvider.get(), labelsBuilder);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:5,代码来源:RequestLabeler.java

示例14: annotateIfNotEmpty

import com.google.cloud.trace.core.Labels; //导入方法依赖的package包/类
/**
 * Make sure that only labels with actual values are added.
 */
private void annotateIfNotEmpty(Labels.Builder labels, String key, String value) {
  if (value != null && value.length() > 0) {
    labels.add(key, value);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:9,代码来源:TraceValve.java

示例15: addLabelsBeforeCall

import com.google.cloud.trace.core.Labels; //导入方法依赖的package包/类
void addLabelsBeforeCall(Labels.Builder labelsBuilder); 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:2,代码来源:Labeler.java


注:本文中的com.google.cloud.trace.core.Labels.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。