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

fix: refactor error reporting code sample #3291

Merged
merged 3 commits into from Sep 14, 2023
Merged

Conversation

minherz
Copy link
Contributor

@minherz minherz commented Sep 13, 2023

align code sample for error reporting with code in other languages (b/275730159). use an explicit error with the "fixed" message. populate the service context with the name of the service (module) and the version.

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Sep 13, 2023
@minherz minherz marked this pull request as ready for review September 13, 2023 19:14
@minherz minherz requested review from a team as code owners September 13, 2023 19:14
// Sets your Google Cloud Platform project ID.
projectID := "YOUR_PROJECT_ID"
// TODO: Sets your Google Cloud Platform project ID via environment or explicitly
projectID := os.Getenv("GOOGLE_PROJECT_ID")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add this? Also, if you are going to add it, GOOGLE_CLOUD_PROJECT is the standard environment variable, not GOOGLE_PROJECT_ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We try to align samples across all languages to exhibit the same behavior. The options are:

  • Environment variable
  • Explicit setup
  • Fallback to project ID implicitly configured at client initialization

Unfortunately I did not have time to dig for implementation of the last bullet in Golang. I will appreciate it if you can point me to the code that "retrieves" project ID from the client settings.

Copy link

@NimJay NimJay Sep 14, 2023

Choose a reason for hiding this comment

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

+1 to changing to GOOGLE_CLOUD_PROJECT

Suggested change
projectID := os.Getenv("GOOGLE_PROJECT_ID")
projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")

... primarily because the rest of this repository uses GOOGLE_CLOUD_PROJECT (see search results).
There's no use of GOOGLE_PROJECT_ID in this repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure autodetecting the project ID is supported in all clients for Go; see discussion on googleapis/google-cloud-go#1294 . @codyoss please correct me if I'm wrong.

In snippet samples we generally pass the project ID in via an arg (see https://googlecloudplatform.github.io/samples-style-guide/#minimal-arguments ). As this is a quickstart, I think it's fine to try to detect it from the environment. However I do think we should standardize on GOOGLE_CLOUD_PROJECT rather than GOOGLE_PROJECT_ID given that is what is supported across tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changes made to address this while allowing users to provide the project ID via argument.

errorreporting/errorreporting_quickstart/main.go Outdated Show resolved Hide resolved
errorreporting/errorreporting_quickstart/main.go Outdated Show resolved Hide resolved
@tritone tritone self-assigned this Sep 14, 2023
Copy link

@NimJay NimJay left a comment

Choose a reason for hiding this comment

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

Thanks for working on these updates related to b/275730159!

Approved (since the remaining GOOGLE_CLOUD_PROJECT issue is a nit, IMO).

Looks like the Go / Lint check is passing.
It sounds like we just need to run:

goimports -w . && find . -name go.mod -execdir go mod tidy \;

align code sample for error reporting with code in other languages.
use an explicit error with the "fixed" message
fix typo in the comment.
expand the comment about error context autopopulation.
address lint warning for errors.New() call.
align the code to the way project ID is set in other languages.
use "official" env variable name.
@minherz minherz merged commit 78dd4ac into main Sep 14, 2023
11 checks passed
@minherz minherz deleted the minherz/fix-275730159 branch September 14, 2023 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants