Skip to content

feat(memorystore): migrate Redis client-side metrics sample to OTLP - #10360

Open
fosky94 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
fosky94:otlp-migration
Open

fosky94 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
fosky94:otlp-migration

Conversation

@fosky94

@fosky94 fosky94 commented Oct 26, 2026

Copy link
Copy Markdown
Member

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.

@fosky94
fosky94 requested review from a team and yoshi-approver as code owners October 26, 2026 16:44
@product-auto-label product-auto-label Bot added samples Issues that are directly related to samples. api: memorystore labels Oct 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +246 to +256
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()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: memorystore samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant