Skip to content

test(o11y): add tests for tracing, metrics and logging in java-compute#12730

Open
diegomarquezp wants to merge 10 commits intomainfrom
observability/test/compute-integration-test
Open

test(o11y): add tests for tracing, metrics and logging in java-compute#12730
diegomarquezp wants to merge 10 commits intomainfrom
observability/test/compute-integration-test

Conversation

@diegomarquezp
Copy link
Copy Markdown
Contributor

This PR adds tests for java-compute to confirm behavior of recently added o11y features.

Key changes:

  • sdk-platform-java/gax-java: Overrode requestUrlResolved in CompositeTracer to ensure url.full is recorded in HTTP/REST transport. This was a fix found during testing.
  • java-compute: Introduced ITComputeGoldenSignals.java to validate tracing, metrics, and logging.
  • java-compute: Added GOOGLE_SDK_JAVA_LOGGING=true environment variable to maven-surefire-plugin in pom.xml to enable logging for verification in tests.

Copy link
Copy Markdown
Contributor

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

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 introduces integration tests for observability "golden signals" (traces, metrics, and logs) in the Compute service. It adds necessary OpenTelemetry and logging dependencies to the POM, implements the ITComputeGoldenSignals test class, and updates CompositeTracer to delegate requestUrlResolved calls. Review feedback identifies an opportunity to prevent test flakiness by clearing the TestAppender state between tests and suggests removing a redundant call to getMDCPropertyMap in the appender's logic.

@diegomarquezp diegomarquezp marked this pull request as ready for review April 9, 2026 19:01
@diegomarquezp diegomarquezp requested a review from a team as a code owner April 9, 2026 19:01
Arrays.asList(
new OpenTelemetryTracingFactory(openTelemetrySdk),
new OpenTelemetryMetricsFactory(openTelemetrySdk),
new LoggingTracerFactory());
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.

Can we try to enable logging using environment variables?

rootSpanName = "ComputeRootSpan-" + generateRandomHexString(8);

GoogleCredentials credentials = GoogleCredentials.getApplicationDefault();
credentials.refreshIfExpired();
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.

Is refreshing the credentials needed?

.isEqualTo("compute/v1/projects/{project=*}/zones/{zone=*}/instances");
String expectedDestinationResource;
if (expectError) {
expectedDestinationResource = "//compute.googleapis.com/projects/invalid-project-";
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.

It actually took me some time to figure out why expectedDestinationResource is different even if it errors out. Which is because we are testing that the actual resource startsWith the expected resource. Can we try to use a fixed invalid project id instead of randomUUID? So that we can make sure that the resource name is in the same format for both success and error scenarios.

assertThat(span.getLabelsMap().get(ObservabilityAttributes.DESTINATION_RESOURCE_ID_ATTRIBUTE))
.startsWith(expectedDestinationResource);

// These might fail if not supported in HTTP/REST yet
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.

This comment is not needed since compute only supports HTTP/REST

.startsWith(expectedDestinationResource);

// These might fail if not supported in HTTP/REST yet
assertThat(span.getLabelsMap()).containsKey(ObservabilityAttributes.HTTP_URL_FULL_ATTRIBUTE);
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.

Can we verify the value as well? Same comments for the error attributes below as well. Status message might be hard but I think we should be able to verify all other attributes

Resource.create(
Attributes.of(AttributeKey.stringKey("gcp.project_id"), DEFAULT_PROJECT)));

metricReader = InMemoryMetricReader.create();
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.

Can we use Otel exporter to export it and use Cloud Monitoring client to verify it? To be consistent with how we verify traces.

}
}

@Override
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.

Let's break this up to a separate PR. This needs to be released but the integration tests does not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do.


io.opentelemetry.api.common.Attributes attributes =
durationMetric.getHistogramData().getPoints().iterator().next().getAttributes();
assertThat(
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.

Can we verify as much attributes as possible?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants