Class ZPageServer

java.lang.Object
io.opentelemetry.sdk.extension.zpages.ZPageServer

@ThreadSafe public final class ZPageServer extends Object
A collection of HTML pages to display stats and trace data and allow library configuration control. To use, add the z-pages span processor, the z-pages dynamic trace config and the z-pages dynamic sampler to a SdkTracerProviderBuilder. Currently all tracers can only be made visible to a singleton ZPageServer.

Example usage with private HttpServer


 public class Main {
   public static void main(String[] args) throws Exception {
     OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
         .setTracerProvider(SdkTracerProvider.builder()
             .addSpanProcessor(ZPageServer.getSpanProcessor())
             .setTraceConfigSupplier(ZPageServer.getTraceConfigSupplier())
             .setSampler(ZPageServer.getSampler())
             .build();
         .build();

     ZPageServer.startHttpServerAndRegisterAllPages(8000);
     ... // do work
   }
 }
 

Example usage with shared HttpServer


 public class Main {
   public static void main(String[] args) throws Exception {
     OpenTelemetry openTelemetry = OpenTelemetrySdk.builder()
         .setTracerProvider(SdkTracerProvider.builder()
             .addSpanProcessor(ZPageServer.getSpanProcessor())
             .setTraceConfigSupplier(ZPageServer.getTraceConfigSupplier())
             .setSampler(ZPageServer.getSampler())
             .build();
         .build();

     HttpServer server = HttpServer.create(new InetSocketAddress(8000), 10);
     ZPageServer.registerAllPagesToHttpServer(server);
     server.start();
     ... // do work
   }
 }
 
  • Method Details

    • getTracezTraceConfigSupplier

      public static Supplier<io.opentelemetry.sdk.trace.SpanLimits> getTracezTraceConfigSupplier()
      Returns a supplier of SpanLimits which can be reconfigured using zpages.
    • getTracezSampler

      public static io.opentelemetry.sdk.trace.samplers.Sampler getTracezSampler()
      Returns a Sampler which can be reconfigured using zpages.
    • getSpanProcessor

      public static io.opentelemetry.sdk.trace.SpanProcessor getSpanProcessor()
      Returns a SpanProcessor which will allow processing of spans by ZPageServer.
    • registerAllPagesToHttpServer

      public static void registerAllPagesToHttpServer(com.sun.net.httpserver.HttpServer server)
      Registers all zPages to the given HttpServer server.
      Parameters:
      server - the HttpServer for the page to register to.
    • startHttpServerAndRegisterAllPages

      public static void startHttpServerAndRegisterAllPages(int port) throws IOException
      Starts a private HttpServer and registers all zPages to it. When the JVM shuts down the server is stopped.

      Users can only call this function once per process.

      Parameters:
      port - the port used to bind the HttpServer server
      Throws:
      IllegalStateException - if the server is already started.
      IOException - if the server cannot bind to the specified port.