Skip to content

Commit

Permalink
chore: fetch current environment when initializing sentry (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Kathurima <kathurimakimathi415@gmail.com>
  • Loading branch information
KathurimaKimathi committed Aug 3, 2022
1 parent 012b426 commit 2bcca48
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ env:
GOOGLE_PROJECT_NUMBER: ${{ secrets.GOOGLE_PROJECT_NUMBER }}
ROOT_COLLECTION_SUFFIX: ${{ secrets.ROOT_COLLECTION_SUFFIX }}
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
JAEGER_URL: ${{ secrets.JAEGER_URL }}

jobs:
lint_and_test:
Expand All @@ -28,8 +29,8 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 80
steps:
- uses: actions/checkout@v2
- uses: google-github-actions/setup-gcloud@master
- uses: actions/checkout@v3
- uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GOOGLE_CLOUD_PROJECT }}
service_account_key: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
Expand All @@ -44,15 +45,23 @@ jobs:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.1
go get -u github.com/kisielk/errcheck
go get -u golang.org/x/lint/golint
go get -u honnef.co/go/tools/cmd/staticcheck
go install honnef.co/go/tools/cmd/staticcheck@2021.1.2
go get -u github.com/axw/gocov/gocov
go get -u github.com/securego/gosec/cmd/gosec
go get -u github.com/ory/go-acc
go get golang.org/x/oauth2/internal
go get google.golang.org/grpc
go get google.golang.org/grpc/internal/transport
go get -u github.com/client9/misspell/cmd/misspell
go get -u github.com/gordonklaus/ineffassign
go get github.com/fzipp/gocyclo
go get github.com/stretchr/testify/assert@v1.7.0
go get github.com/ory/go-acc
go get contrib.go.opencensus.io/exporter/stackdriver@v0.13.6
go get cloud.google.com/go/errorreporting
go get cloud.google.com/go/profiler
- name: Run lint and test
run: |
staticcheck ./...
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV
github.com/vektah/dataloaden v0.2.1-0.20190515034641-a19b9a6e7c9e/go.mod h1:/HUdMve7rvxZma+2ZELQeNh88+003LL7Pf/CZ089j8U=
github.com/vektah/gqlparser/v2 v2.1.0 h1:uiKJ+T5HMGGQM2kRKQ8Pxw8+Zq9qhhZhz/lieYvCMns=
github.com/vektah/gqlparser/v2 v2.1.0/go.mod h1:SyUiHgLATUR8BiYURfTirrTcGpcE+4XkV2se04Px1Ms=
github.com/vektah/gqlparser/v2 v2.2.0 h1:bAc3slekAAJW6sZTi07aGq0OrfaCjj4jxARAaC7g2EM=
github.com/vektah/gqlparser/v2 v2.2.0/go.mod h1:i3mQIGIrbK2PD1RrCeMTlVbkF2FJ6WkU1KJlJlC+3F4=
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
Expand Down
9 changes: 8 additions & 1 deletion server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ func Sentry() error {
if err != nil {
return err
}
return sentry.Init(sentry.ClientOptions{Dsn: dsn})
environment, err := GetEnvVar(Environment)
if err != nil {
return err
}
return sentry.Init(sentry.ClientOptions{
Dsn: dsn,
Environment: environment,
})
}

// ListenAddress determines what port to listen on and falls back to a default
Expand Down
3 changes: 3 additions & 0 deletions server_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ func TestSentry(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
initialEnvironment := os.Getenv("ENVIRONMENT")
os.Setenv("ENVIRONMENT", "staging")
if err := serverutils.Sentry(); (err != nil) != tt.wantErr {
t.Errorf("Sentry() error = %v, wantErr %v", err, tt.wantErr)
}
os.Setenv("ENVIRONMENT", initialEnvironment)
})
}
}
Expand Down

0 comments on commit 2bcca48

Please sign in to comment.