-
Notifications
You must be signed in to change notification settings - Fork 117
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
Conversation
1dd2bd4
to
7be099f
Compare
TracingSample was not using project_id set via GOOGLE_CLOUD_PROJECT and will use metadata API request to set project on default MetricResource, which causes exception in exporting stats. |
@@ -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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
…ored resource for export
3c969e3
to
37f88d0
Compare
@@ -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(); |
There was a problem hiding this comment.
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)
```
🤖 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).
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:
Fixes #<issue_number_goes_here> ☕️
If you write sample code, please follow the samples format.