Commit 28cf5c88 authored by Terri Chu's avatar Terri Chu

Merge branch 'fix-error-reporting-go' into 'master'

Fix error reporting for Go

See merge request gitlab-org/gitlab!72050
parents 3585ac36 ed024893
...@@ -28,7 +28,18 @@ module ErrorTracking ...@@ -28,7 +28,18 @@ module ErrorTracking
private private
def event def event
params[:event] @event ||= format_event(params[:event])
end
def format_event(event)
# Some SDK send exception payload as Array. For exmple Go lang SDK.
# We need to convert it to hash format we expect.
if event['exception'].is_a?(Array)
exception = event['exception']
event['exception'] = { 'values' => exception }
end
event
end end
def exception def exception
......
{"contexts":{"device":{"arch":"amd64","num_cpu":20},"os":{"name":"linux"},"runtime":{"go_maxprocs":20,"go_numcgocalls":5,"go_numroutines":2,"name":"go","version":"go1.17.1"}},"environment":"Accumulate","event_id":"a6d33282b0d44ed1a5982c48b62e2a4e","level":"error","platform":"go","release":"accumulated@version unknown","sdk":{"name":"sentry.go","version":"0.11.0","integrations":["ContextifyFrames","Environment","IgnoreErrors","Modules"],"packages":[{"name":"sentry-go","version":"0.11.0"}]},"server_name":"Laurelin","user":{},"modules":{"github.com/AccumulateNetwork/accumulated":"(devel)","github.com/AccumulateNetwork/jsonrpc2/v15":"v15.0.0-20210802145948-43d2d974a106","github.com/AndreasBriese/bbloom":"v0.0.0-20190825152654-46b345b51c96","github.com/Workiva/go-datastructures":"v1.0.53","github.com/beorn7/perks":"v1.0.1","github.com/btcsuite/btcd":"v0.22.0-beta","github.com/cespare/xxhash":"v1.1.0","github.com/cespare/xxhash/v2":"v2.1.2","github.com/davecgh/go-spew":"v1.1.2-0.20180830191138-d8f796af33cc","github.com/dgraph-io/badger":"v1.6.2","github.com/dgraph-io/ristretto":"v0.0.4-0.20210122082011-bb5d392ed82d","github.com/dustin/go-humanize":"v1.0.0","github.com/fatih/color":"v1.13.0","github.com/fsnotify/fsnotify":"v1.5.1","github.com/getsentry/sentry-go":"v0.11.0","github.com/go-kit/kit":"v0.11.0","github.com/go-playground/locales":"v0.14.0","github.com/go-playground/universal-translator":"v0.18.0","github.com/go-playground/validator/v10":"v10.9.0","github.com/gogo/protobuf":"v1.3.2","github.com/golang/protobuf":"v1.5.2","github.com/golang/snappy":"v0.0.1","github.com/google/btree":"v1.0.0","github.com/google/orderedcode":"v0.0.1","github.com/google/uuid":"v1.3.0","github.com/gorilla/mux":"v1.8.0","github.com/gorilla/websocket":"v1.4.2","github.com/grpc-ecosystem/go-grpc-middleware":"v1.3.0","github.com/grpc-ecosystem/go-grpc-prometheus":"v1.2.0","github.com/hashicorp/hcl":"v1.0.0","github.com/leodido/go-urn":"v1.2.1","github.com/lib/pq":"v1.10.3","github.com/libp2p/go-buffer-pool":"v0.0.2","github.com/magiconair/properties":"v1.8.5","github.com/mattn/go-colorable":"v0.1.9","github.com/mattn/go-isatty":"v0.0.14","github.com/matttproud/golang_protobuf_extensions":"v1.0.1","github.com/minio/highwayhash":"v1.0.2","github.com/mitchellh/mapstructure":"v1.4.2","github.com/oasisprotocol/curve25519-voi":"v0.0.0-20210609091139-0a56a4bca00b","github.com/pelletier/go-toml":"v1.9.4","github.com/pkg/errors":"v0.9.1","github.com/pmezard/go-difflib":"v1.0.0","github.com/prometheus/client_golang":"v1.11.0","github.com/prometheus/client_model":"v0.2.0","github.com/prometheus/common":"v0.30.0","github.com/prometheus/procfs":"v0.7.3","github.com/rcrowley/go-metrics":"v0.0.0-20200313005456-10cdbea86bc0","github.com/rs/cors":"v1.8.0","github.com/rs/zerolog":"v1.24.0","github.com/spf13/afero":"v1.6.0","github.com/spf13/cast":"v1.4.1","github.com/spf13/cobra":"v1.2.1","github.com/spf13/jwalterweatherman":"v1.1.0","github.com/spf13/pflag":"v1.0.5","github.com/spf13/viper":"v1.8.1","github.com/stretchr/testify":"v1.7.0","github.com/subosito/gotenv":"v1.2.0","github.com/syndtr/goleveldb":"v1.0.1-0.20200815110645-5c35d600f0ca","github.com/tendermint/tendermint":"v0.35.0-rc1","github.com/tendermint/tm-db":"v0.6.4","github.com/ybbus/jsonrpc/v2":"v2.1.6","golang.org/x/crypto":"v0.0.0-20210711020723-a769d52b0f97","golang.org/x/net":"v0.0.0-20210805182204-aaa1db679c0d","golang.org/x/sys":"v0.0.0-20210917161153-d61c044b1678","golang.org/x/term":"v0.0.0-20201126162022-7de9c90e9dd1","golang.org/x/text":"v0.3.7","google.golang.org/genproto":"v0.0.0-20210602131652-f16073e35f0c","google.golang.org/grpc":"v1.40.0","google.golang.org/protobuf":"v1.27.1","gopkg.in/ini.v1":"v1.63.2","gopkg.in/yaml.v2":"v2.4.0","gopkg.in/yaml.v3":"v3.0.0-20210107192922-496545a6307b"},"exception":[{"type":"*errors.errorString","value":"Hello world","stacktrace":{"frames":[{"function":"main","module":"main","abs_path":"SRC/cmd/accumulated/main.go","lineno":37,"pre_context":["func init() {","\tcmdMain.PersistentFlags().StringVarP(&flagMain.WorkDir, \"work-dir\", \"w\", defaultWorkDir, \"Working directory for configuration and data\")","}","","func main() {"],"context_line":"\tcmdMain.Execute()","post_context":["}","","func printUsageAndExit1(cmd *cobra.Command, args []string) {","\tcmd.Usage()","\tos.Exit(1)"],"in_app":true},{"function":"(*Command).Execute","module":"github.com/spf13/cobra","abs_path":"GOPATH/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go","lineno":902,"pre_context":["","// Execute uses the args (os.Args[1:] by default)","// and run through the command tree finding appropriate matches","// for commands and then corresponding flags.","func (c *Command) Execute() error {"],"context_line":"\t_, err := c.ExecuteC()","post_context":["\treturn err","}","","// ExecuteContextC is the same as ExecuteC(), but sets the ctx on the command.","// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle or ValidArgs"],"in_app":true},{"function":"(*Command).ExecuteC","module":"github.com/spf13/cobra","abs_path":"GOPATH/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go","lineno":974,"pre_context":["\t// if context is present on the parent command.","\tif cmd.ctx == nil {","\t\tcmd.ctx = c.ctx","\t}",""],"context_line":"\terr = cmd.execute(flags)","post_context":["\tif err != nil {","\t\t// Always show help if requested, even if SilenceErrors is in","\t\t// effect","\t\tif err == flag.ErrHelp {","\t\t\tcmd.HelpFunc()(cmd, args)"],"in_app":true},{"function":"(*Command).execute","module":"github.com/spf13/cobra","abs_path":"GOPATH/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go","lineno":860,"pre_context":["\tif c.RunE != nil {","\t\tif err := c.RunE(c, argWoFlags); err != nil {","\t\t\treturn err","\t\t}","\t} else {"],"context_line":"\t\tc.Run(c, argWoFlags)","post_context":["\t}","\tif c.PostRunE != nil {","\t\tif err := c.PostRunE(c, argWoFlags); err != nil {","\t\t\treturn err","\t\t}"],"in_app":true},{"function":"runNode","module":"main","abs_path":"SRC/cmd/accumulated/cmd_run.go","lineno":76,"pre_context":["\t\tif err != nil {","\t\t\tfmt.Fprintf(os.Stderr, \"Error: configuring sentry: %v\\n\", err)","\t\t\tos.Exit(1)","\t\t}","\t\tdefer sentry.Flush(2 * time.Second)"],"context_line":"\t\tsentry.CaptureException(errors.New(\"Hello world\"))","post_context":["\t\t// sentry.CaptureMessage(\"Hello world\")","\t\tsentry.Flush(time.Second)","\t}","","\tdbPath := filepath.Join(config.RootDir, \"valacc.db\")"],"in_app":true}]}}],"timestamp":"2021-10-08T19:49:21.932425444-05:00"}
...@@ -4,7 +4,8 @@ require 'spec_helper' ...@@ -4,7 +4,8 @@ require 'spec_helper'
RSpec.describe ErrorTracking::CollectErrorService do RSpec.describe ErrorTracking::CollectErrorService do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/parsed_event.json')) } let_it_be(:parsed_event_file) { 'error_tracking/parsed_event.json' }
let_it_be(:parsed_event) { Gitlab::Json.parse(fixture_file(parsed_event_file)) }
subject { described_class.new(project, nil, event: parsed_event) } subject { described_class.new(project, nil, event: parsed_event) }
...@@ -72,5 +73,25 @@ RSpec.describe ErrorTracking::CollectErrorService do ...@@ -72,5 +73,25 @@ RSpec.describe ErrorTracking::CollectErrorService do
end end
end end
end end
context 'go payload' do
let(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/go_parsed_event.json')) }
it 'has correct values set' do
subject.execute
event = ErrorTracking::ErrorEvent.last
error = event.error
expect(error.name).to eq '*errors.errorString'
expect(error.description).to start_with 'Hello world'
expect(error.platform).to eq 'go'
expect(event.description).to start_with 'Hello world'
expect(event.level).to eq 'error'
expect(event.environment).to eq 'Accumulate'
expect(event.payload).to eq parsed_event
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment