Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix tracing sample to exit when completed, and use custom monitored resource for export #3287

Merged
merged 4 commits into from
Oct 25, 2024

Conversation

rahul2393
Copy link
Contributor

@rahul2393 rahul2393 commented Aug 21, 2024

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

@rahul2393 rahul2393 requested a review from a team as a code owner August 21, 2024 10:06
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: spanner Issues related to the googleapis/java-spanner API. samples Issues that are directly related to samples. labels Aug 21, 2024
@rahul2393 rahul2393 changed the title docs: fix tracing sample to exit when completed, and use custom monit… docs: fix tracing sample to exit when completed, and use custom monitored resource for export Aug 21, 2024
@@ -87,6 +97,9 @@ public static void main(String[] args) throws Exception {
} finally {
// Closes the client which will free up the resources used
spanner.close();
StackdriverExporter.unregister();
StackdriverStatsExporter.unregister();
System.exit(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems overly harsh. What is the reason that we need to call System.exit(0) to stop the application here? Is the Stackdriver exporter using non-daemon threads that are not stopped? If so, does the StackdriverExporter have a close/shutdown method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

StackdriverExporter does not export any close/shutdown method they only have unregister, without system.exit I see exceptions and sample getting stuck https://pastebin.com/drh6qubH

Copy link
Collaborator

Choose a reason for hiding this comment

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

The 'getting stuck' problem is actually caused by ZPageHandlers.startHttpServerAndRegisterAll(8080);. That starts an HTTP server that can be accessed on http://localhost:8080/tracez to view the traces that were collected. That component does not have a public stop() method, and keeps the JVM alive, as it uses non-daemon threads. Can we update the comment here to reflect this?

The errors regarding closed channels could in theory still happen. I think that there is a race condition in the OpenCensus stats exporter that tries to flush any remaining stats, while at the same time also closing the underlying exporter client. Those can be ignored.

@cloud-java-bot cloud-java-bot requested a review from a team as a code owner October 25, 2024 05:19
@@ -58,7 +64,13 @@ public static void main(String[] args) throws Exception {
.registerSpanNamesForCollection(Arrays.asList(SAMPLE_SPAN));

// Installs an exporter for stack driver stats.
StackdriverStatsExporter.createAndRegister();
MonitoredResource.Builder builder = MonitoredResource.newBuilder();
Copy link
Contributor Author

@rahul2393 rahul2393 Oct 25, 2024

Choose a reason for hiding this comment

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

This is being added because without this an exception is thrown because StackdriverStatsExporter tries to use different project from metadata API

Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Field timeSeries[0].resource.labels.project_id had an invalid value of "google.com:xxxxx: if present, must be the project number or ID in the request name.                                                      
        at io.grpc.Status.asRuntimeException(Status.java:533) 
        ```

@rahul2393 rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 25, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 25, 2024
@rahul2393 rahul2393 merged commit ddb65b1 into main Oct 25, 2024
33 checks passed
@rahul2393 rahul2393 deleted the fix-tracing-sample branch October 25, 2024 07:17
gcf-merge-on-green bot pushed a commit that referenced this pull request Oct 25, 2024
🤖 I have created a release *beep* *boop*
---


## [6.80.0](https://togithub.com/googleapis/java-spanner/compare/v6.79.0...v6.80.0) (2024-10-25)


### Features

* Enabling endToEndTracing support in Connection API ([#3412](https://togithub.com/googleapis/java-spanner/issues/3412)) ([16cc6ee](https://togithub.com/googleapis/java-spanner/commit/16cc6eed58cf735026d7757a28f61f29821a14bf))


### Dependencies

* Update dependency com.google.cloud:sdk-platform-java-config to v3.38.0 ([#3424](https://togithub.com/googleapis/java-spanner/issues/3424)) ([b727453](https://togithub.com/googleapis/java-spanner/commit/b727453b93d1089f76e1b908255610cc2796da43))
* Update dependency io.opentelemetry:opentelemetry-bom to v1.43.0 ([#3399](https://togithub.com/googleapis/java-spanner/issues/3399)) ([a755c6c](https://togithub.com/googleapis/java-spanner/commit/a755c6c2f44cc3eb0f5a54cd58244cebc62b7a4f))
* Update dependency io.opentelemetry:opentelemetry-sdk-testing to v1.43.0 ([#3398](https://togithub.com/googleapis/java-spanner/issues/3398)) ([693243a](https://togithub.com/googleapis/java-spanner/commit/693243afae34610441345645f627bf199e8ddb8b))
* Update googleapis/sdk-platform-java action to v2.48.0 ([#3422](https://togithub.com/googleapis/java-spanner/issues/3422)) ([d5d1f55](https://togithub.com/googleapis/java-spanner/commit/d5d1f55d7e8e8f9aa89b7ab9e5f5bd0464bf0e1a))


### Documentation

* Fix tracing sample to exit when completed, and use custom monitored resource for export ([#3287](https://togithub.com/googleapis/java-spanner/issues/3287)) ([ddb65b1](https://togithub.com/googleapis/java-spanner/commit/ddb65b197a6f311c2bb8ec9856ea968f3a31d62a))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. samples Issues that are directly related to samples. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants