Skip to content

Commit

Permalink
Retrieves project id from environment var (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
psx95 committed May 25, 2023
1 parent ceb4457 commit b1305d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions example/metric/README.md
Expand Up @@ -16,6 +16,12 @@ foo-project-214354

In this case, the project ID is `foo-project-214354`.

Next, set this project ID to the environment variable `GOOGLE_PROJECT_ID` using the following command:

```
export GOOGLE_PROJECT_ID=$(gcloud config get-value project)
```

Once you ensure the API is enabled, then build the example application and run the executable.

```
Expand Down
3 changes: 2 additions & 1 deletion example/metric/example.go
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"log"
"math/rand"
"os"
"sync"
"time"

Expand Down Expand Up @@ -55,7 +56,7 @@ func main() {
// Initialization. In order to pass the credentials to the exporter,
// prepare credential file following the instruction described in this doc.
// https://pkg.go.dev/golang.org/x/oauth2/google?tab=doc#FindDefaultCredentials
exporter, err := mexporter.New()
exporter, err := mexporter.New(mexporter.WithProjectID(os.Getenv("GOOGLE_PROJECT_ID")))
if err != nil {
log.Fatalf("Failed to create exporter: %v", err)
}
Expand Down

0 comments on commit b1305d7

Please sign in to comment.