feat(spanner): Update OpenTelemetry OTLP trace sample to use Google C…#10251
feat(spanner): Update OpenTelemetry OTLP trace sample to use Google C…#10251surbhigarg92 wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the OpenTelemetry Spanner sample to include authentication headers for the OTLP exporter and modifies the default configuration to use the OTLP endpoint with a full sampling rate. Feedback suggests reverting specific testing values, such as project IDs and service names, to generic placeholders to ensure the code sample remains professional and reusable for a public audience.
| static String projectId = "span-cloud-testing"; | ||
| static String instanceId = "gargsurbhi-testing"; | ||
| static String databaseId = "test-db"; |
There was a problem hiding this comment.
The project, instance, and database IDs have been updated to specific testing values. For a public code sample, it is best practice to use generic placeholders (e.g., 'my-project') as originally used, especially since the TODO(developer) comment remains.
| static String projectId = "span-cloud-testing"; | |
| static String instanceId = "gargsurbhi-testing"; | |
| static String databaseId = "test-db"; | |
| static String projectId = "my-project"; | |
| static String instanceId = "my-instance"; | |
| static String databaseId = "my-database"; |
References
- Code samples may prioritize simplicity and clarity over production-ready practices.
| // [START spanner_opentelemetry_traces_otlp_usage] | ||
| Resource resource = Resource | ||
| .getDefault().merge(Resource.builder().put("service.name", "My App").build()); | ||
| .getDefault().merge(Resource.builder().put("service.name", "Surbhi App").put("gcp.project_id", projectId).build()); |
There was a problem hiding this comment.
The 'service.name' resource attribute is set to a personalized value ('Surbhi App'). Please use a generic name like 'My App' or 'spanner-otlp-sample' to ensure the sample is professional and reusable by others.
| .getDefault().merge(Resource.builder().put("service.name", "Surbhi App").put("gcp.project_id", projectId).build()); | |
| .getDefault().merge(Resource.builder().put("service.name", "My App").put("gcp.project_id", projectId).build()); |
References
- Code samples may prioritize simplicity and clarity over production-ready practices.
bdcf525 to
aa30392
Compare
…loud OTLP endpoint
aa30392 to
fe5e51c
Compare
| static boolean useCloudTraceExporter = true; // Replace to false for OTLP | ||
| static String otlpEndpoint = "http://localhost:4317"; // Replace with your OTLP endpoint | ||
| static boolean useCloudTraceExporter = false; // Replace to true for Cloud Trace exporter | ||
| static String otlpEndpoint = |
There was a problem hiding this comment.
The customer's OTLP configuration should be respected (see relevant OTel environment variables configuring the exporter). However, auth and project ID should get automatically injected/added if the endpoint is the Telemetry API or one of its regional variants.
| Resource.getDefault() | ||
| .merge( | ||
| Resource.builder() | ||
| .put("service.name", "My App") |
There was a problem hiding this comment.
Why "My App"? The service name really ought to be supplied by the program, either through an explicit parameter or through environment variables.
Note that there are standard OTel environment variables that are typically used to supply this.
| GoogleCredentials credentials = | ||
| GoogleCredentials.getApplicationDefault() | ||
| .createScoped(Collections.singleton("https://www.googleapis.com/auth/trace.append")); | ||
| OtlpGrpcSpanExporter otlpGrpcSpanExporter = | ||
| OtlpGrpcSpanExporter | ||
| .builder() | ||
| .setEndpoint(otlpEndpoint) // Replace with your OTLP endpoint | ||
| OtlpGrpcSpanExporter.builder() | ||
| .setEndpoint(otlpEndpoint) |
There was a problem hiding this comment.
The credentials and header logic should be conditioned on the endpoint matching the GCP Telemetry API. But that endpoint should not be hardcoded. It should be easy for customers to use the library with a collector of their choice.
…loud OTLP endpoint
Description