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


Java SpanContextFactory类代码示例

本文整理汇总了Java中com.google.cloud.trace.core.SpanContextFactory的典型用法代码示例。如果您正苦于以下问题:Java SpanContextFactory类的具体用法?Java SpanContextFactory怎么用?Java SpanContextFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SpanContextFactory类属于com.google.cloud.trace.core包,在下文中一共展示了SpanContextFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doFilter

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;
  String header = httpRequest.getHeader(SpanContextFactory.headerKey());
  SpanContextHandle incomingContext = null;
  if (header != null) {
    incomingContext = contextHandler.attach(contextFactory.fromHeader(header));
  }
  TraceContext traceContext = requestInterceptor.process(new RequestAdapter(httpRequest));
  try {
    filterChain.doFilter(request, response);
  } finally {
    responseInterceptor
        .process(new ResponseAdapter((HttpServletResponse) response), traceContext);
    if (incomingContext != null) {
      incomingContext.detach();
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:20,代码来源:TraceServletFilter.java

示例2: doFilter

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Override
public void doFilter(
    ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) request;

  String contextHeader = httpRequest.getHeader(SpanContextFactory.headerKey());
  SpanContext context;
  if (contextHeader != null) {
    context = spanContextFactory.fromHeader(contextHeader);
  } else {
    context = spanContextFactory.initialContext();
  }
  SpanContextHandle handle = spanContextHandler.attach(context);
  try {
    chain.doFilter(request, response);
  } finally {
    handle.detach();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:21,代码来源:RequestTraceContextFilter.java

示例3: TraceServletFilter

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public TraceServletFilter(SpanContextHandler contextHandler, SpanContextFactory contextFactory,
    TraceHttpRequestInterceptor requestInterceptor,
    TraceHttpResponseInterceptor responseInterceptor) {
  this.contextHandler = contextHandler;
  this.contextFactory = contextFactory;
  this.requestInterceptor = requestInterceptor;
  this.responseInterceptor = responseInterceptor;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:9,代码来源:TraceServletFilter.java

示例4: LoggingTraceService

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public LoggingTraceService() {
  // Create the trace sink.
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = new LoggingTraceConsumer(logger, Level.WARNING);
  TraceSink traceSink = new TraceSinkV1("1", traceProducer, traceConsumer);

  // Create the tracer.
  spanContextFactory = new SpanContextFactory(
      new ConstantTraceOptionsFactory(true, false));
  TimestampFactory timestampFactory = new JavaTimestampFactory();

  // Create the services.
  this.spanContextHandler = new GrpcSpanContextHandler(spanContextFactory.initialContext());
  this.tracer = new SpanContextHandlerTracer(traceSink, spanContextHandler, spanContextFactory, timestampFactory);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:16,代码来源:LoggingTraceService.java

示例5: TraceGrpcApiService

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
private TraceGrpcApiService(String projectId, TraceOptionsFactory optionsFactory,
                            int bufferSize, int scheduledDelay, GoogleCredentials credentials,
                            ScheduledExecutorService executorService) throws IOException {
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = GrpcTraceConsumer.createWithCredentials(credentials);
  traceConsumer = new ScheduledBufferingTraceConsumer(traceConsumer, new RoughTraceSizer(),
      bufferSize, scheduledDelay, executorService);
  TraceSink traceSink = new TraceSinkV1(projectId, traceProducer, traceConsumer);

  factory = new SpanContextFactory(optionsFactory);
  handler = new GrpcSpanContextHandler(factory.initialContext());
  tracer = new SpanContextHandlerTracer(traceSink, handler, factory, new JavaTimestampFactory());
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:14,代码来源:TraceGrpcApiService.java

示例6: setup

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Before
public void setup() {
  TimestampFactory tsFactory = new TestTimestampFactory(1, 2);
  this.sink = new TestTraceSink();
  SpanContextFactory contextFactory = new SpanContextFactory(new ConstantTraceOptionsFactory(true, true));
  this.contextHandler = new TestSpanContextHandler(contextFactory.initialContext());
  this.tracer = new SpanContextHandlerTracer(sink, contextHandler, contextFactory, tsFactory);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:9,代码来源:SpanContextHandlerTracerTest.java

示例7: main

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  String projectId = System.getProperty("projectId");
  String clientSecretsFile = System.getProperty("clientSecretsFile");

  // Create the trace sink.
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = GrpcTraceConsumer.createWithCredentials(
      GoogleCredentials.fromStream(new FileInputStream(clientSecretsFile))
          .createScoped(Arrays.asList("https://www.googleapis.com/auth/trace.append")));
  FlushableTraceConsumer flushableSink = new SimpleBufferingTraceConsumer(traceConsumer);
  TraceSink traceSink = new TraceSinkV1(projectId, traceProducer, flushableSink);

  // Create the tracer.
  SpanContextFactory spanContextFactory = new SpanContextFactory(
      new ConstantTraceOptionsFactory(true, false));
  TimestampFactory timestampFactory = new JavaTimestampFactory();
  SpanContextHandler contextHandler = new GrpcSpanContextHandler(spanContextFactory.initialContext());
  Tracer tracer = new SpanContextHandlerTracer(traceSink, contextHandler, spanContextFactory, timestampFactory);

  // Create a span using the given timestamps.
  TraceContext context1 = tracer.startSpan("my span 1");

  TraceContext context2 = tracer.startSpan("my span 2");

  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context2, stackTraceBuilder.build());
  tracer.endSpan(context2);

  tracer.endSpan(context1);

  flushableSink.flush();
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:33,代码来源:SimpleBufferingGrpc.java

示例8: main

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  String projectId = System.getProperty("projectId");

  // Create the trace sink.
  TraceProducer traceProducer = new TraceProducer();
  TraceConsumer traceConsumer = GrpcTraceConsumer.create();
  TraceSink traceSink = new TraceSinkV1(projectId, traceProducer, traceConsumer);

  // Create the tracer.
  SpanContextFactory spanContextFactory = new SpanContextFactory(
      new ConstantTraceOptionsFactory(true, false));
  TimestampFactory timestampFactory = new JavaTimestampFactory();
  SpanContextHandler spanContextHandler = new GrpcSpanContextHandler(
      spanContextFactory.initialContext());
  Tracer tracer = new SpanContextHandlerTracer(traceSink, spanContextHandler, spanContextFactory, timestampFactory);

  // Create some trace data.
  TraceContext context1 = tracer.startSpan("my span 1");

  TraceContext context2 = tracer.startSpan("my span 2");

  StackTrace.Builder stackTraceBuilder = ThrowableStackTraceHelper.createBuilder(new Exception());
  tracer.setStackTrace(context2, stackTraceBuilder.build());
  tracer.endSpan(context2);

  tracer.endSpan(context1);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:28,代码来源:ManagedGrpc.java

示例9: testTraceHeader

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
/**
 * If x-cloud-trace-context header is present a new context must created.
 */
@Test
public void testTraceHeader() throws Exception {
  SpanContext contextFromHeader = mock(SpanContext.class);
  when(request.getHeader(SpanContextFactory.headerKey())).thenReturn("traceid/spanid");
  when(spanContextFactory.fromHeader("traceid/spanid")).thenReturn(contextFromHeader);

  valve.invoke(request, response);

  verify(spanContextHandler).attach(contextFromHeader);
}
 
开发者ID:GoogleCloudPlatform,项目名称:tomcat-runtime,代码行数:14,代码来源:TraceValveTest.java

示例10: process

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public void process(org.apache.http.HttpRequest request, HttpContext context) throws HttpException, IOException {
  TraceContext traceContext = interceptor.process(new RequestAdapter(request));
  request.addHeader(SpanContextFactory.headerKey(),
      SpanContextFactory.toHeader(traceContext.getHandle().getCurrentSpanContext()));
  context.setAttribute(TraceInterceptorUtil.TRACE_CONTEXT_KEY, traceContext);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:7,代码来源:TraceRequestInterceptor.java

示例11: filter

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
public void filter(ClientRequestContext requestContext) throws IOException {
  TraceContext traceContext = requestInterceptor.process(new RequestAdapter(requestContext));
  requestContext.getHeaders().add(SpanContextFactory.headerKey(),
      SpanContextFactory.toHeader(traceContext.getHandle().getCurrentSpanContext()));
  requestContext.setProperty(TRACE_CONTEXT_PROPERTY, traceContext);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:7,代码来源:TraceClientFilter.java

示例12: RequestTraceContextFilter

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Inject
RequestTraceContextFilter(SpanContextFactory spanContextFactory, SpanContextHandler spanContextHandler) {
  this.spanContextFactory = spanContextFactory;
  this.spanContextHandler = spanContextHandler;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:6,代码来源:RequestTraceContextFilter.java

示例13: provideTraceContextHandler

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Provides
@Singleton
SpanContextHandler provideTraceContextHandler(SpanContextFactory spanContextFactory) {
  return new GrpcSpanContextHandler(spanContextFactory.initialContext());
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:6,代码来源:GrpcSpanContextHandlerModule.java

示例14: provideTracer

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Provides
@Singleton
Tracer provideTracer(TraceSink sink, SpanContextHandler contextHandler, SpanContextFactory contextFactory, TimestampFactory timestampFactory) {
  return new SpanContextHandlerTracer(sink, contextHandler, contextFactory, timestampFactory);
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:6,代码来源:SpanContextHandlerTracerModule.java

示例15: getSpanContextFactory

import com.google.cloud.trace.core.SpanContextFactory; //导入依赖的package包/类
@Override
public SpanContextFactory getSpanContextFactory() {
  return spanContextFactory;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java,代码行数:5,代码来源:LoggingTraceService.java


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