Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Commit

Permalink
feat #19: integrate sentry for event reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
debugtalk committed Nov 18, 2021
1 parent 4d4ecb1 commit 0524996
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
- docs: init documentation website with [`mkdocs`][mkdocs]
- docs: add project badges, including go report card, codecov, github actions, FOSSA, etc.
- test: add CI test with [github actions][github-actions]
- test: integrate [sentry sdk][sentry sdk] for event reporting and analysis

[jmespath]: https://jmespath.org/
[mkdocs]: https://www.mkdocs.org/
[github-actions]: https://github.com/httprunner/hrp/actions
[boomer]: github.com/myzhan/boomer
[sentry sdk]: https://github.com/getsentry/sentry-go
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/httprunner/hrp
go 1.16

require (
github.com/getsentry/sentry-go v0.11.0
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/jinzhu/copier v0.3.2
github.com/jmespath/go-jmespath v0.4.0
Expand Down
132 changes: 132 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions hrp/cmd/boom.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"time"

"github.com/getsentry/sentry-go"
"github.com/spf13/cobra"

"github.com/httprunner/hrp"
Expand All @@ -18,6 +19,7 @@ var boomCmd = &cobra.Command{
$ hrp boom examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
sentry.CaptureMessage("start to run load test")
var paths []hrp.ITestCase
for _, arg := range args {
paths = append(paths, &hrp.TestCasePath{Path: arg})
Expand Down
2 changes: 2 additions & 0 deletions hrp/cmd/har2case.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

Expand All @@ -14,6 +15,7 @@ var har2caseCmd = &cobra.Command{
Long: `Convert HAR to json/yaml testcase files`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
sentry.CaptureMessage("start to convert HAR to testcases")
var outputFiles []string
for _, arg := range args {
var outputPath string
Expand Down
2 changes: 2 additions & 0 deletions hrp/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"github.com/getsentry/sentry-go"
"github.com/spf13/cobra"

"github.com/httprunner/hrp"
Expand All @@ -16,6 +17,7 @@ var runCmd = &cobra.Command{
$ hrp run examples/ # run testcases in specified folder`,
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
sentry.CaptureMessage("start to run API tests")
var paths []hrp.ITestCase
for _, arg := range args {
paths = append(paths, &hrp.TestCasePath{Path: arg})
Expand Down
10 changes: 9 additions & 1 deletion hrp/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package main

import "github.com/httprunner/hrp/hrp/cmd"
import (
"time"

"github.com/getsentry/sentry-go"
"github.com/httprunner/hrp/hrp/cmd"
)

func main() {
// Flush buffered events before the program terminates.
defer sentry.Flush(2 * time.Second)

cmd.Execute()
}
15 changes: 15 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ import (
"os"
"strings"

"github.com/getsentry/sentry-go"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
)

func init() {
// init sentry sdk
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://[email protected]/6070292",
Release: VERSION,
})
if err != nil {
log.Fatal().Err(err).Msg("init sentry sdk failed!")
}
sentry.ConfigureScope(func(scope *sentry.Scope) {
scope.SetLevel(sentry.LevelError)
})
}

var log = zlog.Logger

func SetLogLevel(level string) {
Expand Down

0 comments on commit 0524996

Please sign in to comment.