Source File
errors.go
Belonging Package
cloud.google.com/go/errorreporting
type Client struct {
projectName string
apiClient client
serviceContext *pb.ServiceContext
bundler *bundler.Bundler
onErrorFn func(err error)
}
var newClient = func( context.Context, ...option.ClientOption) (client, error) {
, := vkit.NewReportErrorsClient(, ...)
if != nil {
return nil,
}
.SetGoogleClientInfo("gccl", version.Repo)
return , nil
}
func ( context.Context, string, Config, ...option.ClientOption) (*Client, error) {
if .ServiceName == "" {
.ServiceName = "goapp"
}
, := newClient(, ...)
if != nil {
return nil, fmt.Errorf("creating client: %v", )
}
:= &Client{
apiClient: ,
projectName: "projects/" + ,
serviceContext: &pb.ServiceContext{
Service: .ServiceName,
Version: .ServiceVersion,
},
onErrorFn: .OnError,
}
:= bundler.NewBundler((*pb.ReportErrorEventRequest)(nil), func( interface{}) {
:= .([]*pb.ReportErrorEventRequest)
for , := range {
_, = .apiClient.ReportErrorEvent(, )
if != nil {
.onError()
}
}
.DelayThreshold = 2 * time.Second
.BundleCountThreshold = 100
.BundleByteThreshold = 1000
.BundleByteLimit = 1000
.BufferedByteLimit = 10000
.bundler =
return , nil
}
func ( *Client) ( error) {
if .onErrorFn != nil {
.onErrorFn()
return
}
log.Println()
}
func ( *Client) ( Entry) {
.bundler.Add(.newRequest(), 1)
}
func ( *Client) ( context.Context, Entry) error {
, := .apiClient.ReportErrorEvent(, .newRequest())
return
}
var [16 * 1024]byte
= chopStack([0:runtime.Stack([:], false)])
}
:= .Error.Error() + "\n" +
var *pb.ErrorContext
if := .Req; != nil {
= &pb.ErrorContext{
HttpRequest: &pb.HttpRequestContext{
Method: .Method,
Url: .Host + .RequestURI,
UserAgent: .UserAgent(),
Referrer: .Referer(),
RemoteIp: .RemoteAddr,
},
}
}
if .User != "" {
if == nil {
= &pb.ErrorContext{}
}
.User = .User
}
return &pb.ReportErrorEventRequest{
ProjectName: .projectName,
Event: &pb.ReportedErrorEvent{
EventTime: ptypes.TimestampNow(),
ServiceContext: .serviceContext,
Message: ,
Context: ,
},
}
}
func ( []byte) string {
:= []byte("cloud.google.com/go/errorreporting.(*Client).Report")
:= bytes.IndexByte(, '\n')
if == -1 {
return string()
}
:= [:]
:= bytes.Index(, )
if == -1 {
return string()
}
= [+1:]
for := 0; < 2; ++ {
:= bytes.IndexByte(, '\n')
if == -1 {
return string()
}
= [+1:]
}
return string([:+1]) + string()
}
type client interface {
ReportErrorEvent(ctx context.Context, req *pb.ReportErrorEventRequest, opts ...gax.CallOption) (*pb.ReportErrorEventResponse, error)
Close() error
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |