/** * Registers the {@code StackdriverExporter}. * * @param spanExporter the instance of the {@code SpanExporter} where this service is registered. */ @VisibleForTesting static void register(SpanExporter spanExporter, Handler handler) { StackdriverTraceExporter.register(spanExporter, handler); }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.6 */ public static void unregister() { StackdriverTraceExporter.unregister(); }
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library for an explicit * project ID and using explicit credentials. Only one Stackdriver exporter can be registered at * any point. * * @param credentials a credentials used to authenticate API calls. * @param projectId the cloud project id. * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegisterWithCredentialsAndProjectId( Credentials credentials, String projectId) throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(credentials) .setProjectId(projectId) .build()); }
@Test public void registerUnregisterStackdriverExporter() { StackdriverTraceExporter.register(spanExporter, handler); verify(spanExporter) .registerHandler( eq("io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter"), same(handler)); StackdriverTraceExporter.unregister(spanExporter); verify(spanExporter) .unregisterHandler(eq("io.opencensus.exporter.trace.stackdriver.StackdriverTraceExporter")); } }
projectId = projectId != null ? projectId : castNonNull(ServiceOptions.getDefaultProjectId()); registerInternal(handler);
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library for an explicit * project ID and using explicit credentials. Only one Stackdriver exporter can be registered at * any point. * * @param credentials a credentials used to authenticate API calls. * @param projectId the cloud project id. * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegisterWithCredentialsAndProjectId( Credentials credentials, String projectId) throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(credentials) .setProjectId(projectId) .build()); }
projectId = projectId != null ? projectId : castNonNull(ServiceOptions.getDefaultProjectId()); registerInternal(handler);
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library for an explicit * project ID. Only one Stackdriver exporter can be registered at any point. * * <p>This uses the default application credentials see {@link * GoogleCredentials#getApplicationDefault}. * * <p>This is equivalent with: * * <pre>{@code * StackdriverExporter.createAndRegisterWithCredentialsAndProjectId( * GoogleCredentials.getApplicationDefault(), projectId); * }</pre> * * @param projectId the cloud project id. * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegisterWithProjectId(String projectId) throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(GoogleCredentials.getApplicationDefault()) .setProjectId(projectId) .build()); }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.6 */ public static void unregister() { StackdriverTraceExporter.unregister(); }
/** * Registers the {@code StackdriverExporter}. * * @param spanExporter the instance of the {@code SpanExporter} where this service is registered. */ @VisibleForTesting static void register(SpanExporter spanExporter, Handler handler) { StackdriverTraceExporter.register(spanExporter, handler); }
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library for an explicit * project ID. Only one Stackdriver exporter can be registered at any point. * * <p>This uses the default application credentials see {@link * GoogleCredentials#getApplicationDefault}. * * <p>This is equivalent with: * * <pre>{@code * StackdriverExporter.createAndRegisterWithCredentialsAndProjectId( * GoogleCredentials.getApplicationDefault(), projectId); * }</pre> * * @param projectId the cloud project id. * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegisterWithProjectId(String projectId) throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(GoogleCredentials.getApplicationDefault()) .setProjectId(projectId) .build()); }
/** * Unregisters the {@code StackdriverExporter}. * * @param spanExporter the instance of the {@code SpanExporter} from where this service is * unregistered. */ @VisibleForTesting static void unregister(SpanExporter spanExporter) { StackdriverTraceExporter.unregister(spanExporter); }
private static void registerInternal(Handler newHandler) { synchronized (monitor) { handler = newHandler; register(Tracing.getExportComponent().getSpanExporter(), newHandler); } }
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library. Only one * Stackdriver exporter can be registered at any point. * * <p>This uses the default application credentials see {@link * GoogleCredentials#getApplicationDefault}. * * <p>This uses the default project ID configured see {@link ServiceOptions#getDefaultProjectId}. * * <p>This is equivalent with: * * <pre>{@code * StackdriverExporter.createAndRegisterWithProjectId(ServiceOptions.getDefaultProjectId()); * }</pre> * * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegister() throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(GoogleCredentials.getApplicationDefault()) // TODO(sebright): Handle null default project ID. .setProjectId(castNonNull(ServiceOptions.getDefaultProjectId())) .build()); }
/** * Unregisters the {@code StackdriverExporter}. * * @param spanExporter the instance of the {@code SpanExporter} from where this service is * unregistered. */ @VisibleForTesting static void unregister(SpanExporter spanExporter) { StackdriverTraceExporter.unregister(spanExporter); }
private static void registerInternal(Handler newHandler) { synchronized (monitor) { handler = newHandler; register(Tracing.getExportComponent().getSpanExporter(), newHandler); } }
/** * Creates and registers the Stackdriver Trace exporter to the OpenCensus library. Only one * Stackdriver exporter can be registered at any point. * * <p>This uses the default application credentials see {@link * GoogleCredentials#getApplicationDefault}. * * <p>This uses the default project ID configured see {@link ServiceOptions#getDefaultProjectId}. * * <p>This is equivalent with: * * <pre>{@code * StackdriverExporter.createAndRegisterWithProjectId(ServiceOptions.getDefaultProjectId()); * }</pre> * * @throws IllegalStateException if a Stackdriver exporter is already registered. * @since 0.6 */ public static void createAndRegister() throws IOException { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setCredentials(GoogleCredentials.getApplicationDefault()) // TODO(sebright): Handle null default project ID. .setProjectId(castNonNull(ServiceOptions.getDefaultProjectId())) .build()); }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Stackdriver exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }
public static void main(String[] args) throws IOException, InterruptedException { // Consult system properties to get project/instance String projectId = requiredProperty("bigtable.projectID"); String instanceId = requiredProperty("bigtable.instanceID"); // Force tracing for every request for demo purposes. Use the default settings // in most cases. Tracing.getTraceConfig().updateActiveTraceParams( TraceParams.DEFAULT.toBuilder().setSampler(Samplers.probabilitySampler(1)).build()); StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setProjectId(projectId) .build()); // Enable stats exporter to Stackdriver with a 5 second export time. // Production settings may vary. StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(projectId) .setExportInterval(Duration.create(5, 0)) .build()); RpcViews.registerAllViews(); // HBase Bigtable specific setup for zpages HBaseTracingUtilities.setupTracingConfig(); // Start a web server on port 8080 for tracing data ZPageHandlers.startHttpServerAndRegisterAll(8080); doHelloWorld(projectId, instanceId); System.out.println("Sleeping for 1 minute so that you can view http://localhost:8080/tracez"); // Sleep for 1 minute. Thread.sleep(TimeUnit.MINUTES.toMillis(1)); }
/** * Unregisters the Stackdriver Trace exporter from the OpenCensus library. * * @throws IllegalStateException if a Stackdriver exporter is not registered. * @since 0.12 */ public static void unregister() { synchronized (monitor) { checkState(handler != null, "Stackdriver exporter is not registered."); unregister(Tracing.getExportComponent().getSpanExporter()); handler = null; } }