@Test public void updateAll() { StackdriverTraceConfiguration configuration = StackdriverTraceConfiguration.builder() .setCredentials(FAKE_CREDENTIALS) .setProjectId(PROJECT_ID) .build(); assertThat(configuration.getCredentials()).isEqualTo(FAKE_CREDENTIALS); assertThat(configuration.getProjectId()).isEqualTo(PROJECT_ID); } }
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)); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }