Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Memorystore Redis client-side metrics sample to use standard OpenTelemetry OTLP exporters instead of Google Cloud-specific exporters, upgrading OpenTelemetry dependencies to version 1.44.1. It configures OAuth2 authentication for the OTLP endpoints and sets up GCP resource attributes. The review feedback suggests simplifying the resource configuration in RedisTelemetryApp.java by retrieving attributes directly from Resource.getDefault() rather than manually instantiating GCPResourceProvider, which is already loaded via SPI.
| final Attributes gcpAttrs = new GCPResourceProvider().getAttributes(); | ||
| final AttributesBuilder attrBuilder = gcpAttrs.toBuilder(); | ||
| String projectId = gcpAttrs.get(ATTR_CLOUD_ACCOUNT_ID); | ||
| if (projectId == null || projectId.isEmpty()) { | ||
| projectId = System.getenv("GOOGLE_CLOUD_PROJECT"); | ||
| } | ||
| if (projectId != null && !projectId.isEmpty()) { | ||
| attrBuilder.put(ATTR_GCP_PROJECT_ID, projectId); | ||
| } | ||
| final Resource resource = Resource.getDefault() | ||
| .merge(Resource.create(attrBuilder.build())); |
There was a problem hiding this comment.
Instead of manually instantiating GCPResourceProvider (which is already automatically loaded by Resource.getDefault() via SPI) and duplicating all its attributes, we can retrieve the attributes directly from Resource.getDefault(). This simplifies the code, avoids redundant attribute merging, and allows us to remove the unused imports AttributesBuilder and GCPResourceProvider.
final Resource defaultResource = Resource.getDefault();
String projectId = defaultResource.getAttributes().get(ATTR_CLOUD_ACCOUNT_ID);
if (projectId == null || projectId.isEmpty()) {
projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
}
final Resource resource = projectId != null && !projectId.isEmpty()
? defaultResource.merge(Resource.create(Attributes.of(ATTR_GCP_PROJECT_ID, projectId)))
: defaultResource;f57d8f6 to
be1721d
Compare
be1721d to
0781c78
Compare
Migrates the Memorystore for Redis client-side metrics sample from deprecated Cloud Monitoring exporters to standard OpenTelemetry OTLP exporters targeting telemetry.googleapis.com:443, per b/575558307.