Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track errors when recording spans #290

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func NewFromConfig(conf Config) (ret Server, err error) {
}
ret.Statsd.Namespace = "veneur."
ret.Statsd.Tags = append(ret.Tags, "veneurlocalonly")
trace.DefaultClient.SetErrorStats(ret.Statsd)

// nil is a valid sentry client that noops all methods, if there is no DSN
// we can just leave it as nil
Expand Down
16 changes: 16 additions & 0 deletions trace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
"sync"
"time"

"github.com/stripe/veneur/protocol"
Expand Down Expand Up @@ -36,6 +37,9 @@ type Client struct {
backend
cancel context.CancelFunc
ops chan op

stats IncrClient
statsMtx sync.Mutex
}

// Close tears down the entire client. It waits until the backend has
Expand All @@ -61,6 +65,18 @@ func (c *Client) run(ctx context.Context) {
}
}

type IncrClient interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should this interface get docs?

Incr(name string, tags []string, rate float64) error
}

// SetErrorStats sets an IncrClient used for reporting errors
func (c *Client) SetErrorStats(statsClient IncrClient) {
c.statsMtx.Lock()
defer c.statsMtx.Unlock()

c.stats = statsClient
}

// ClientParam is an option for NewClient. Its implementation borrows
// from Dave Cheney's functional options API
// (https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis).
Expand Down
10 changes: 9 additions & 1 deletion trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package trace

import (
"context"
"fmt"
"io"
"math/rand"
"reflect"
Expand Down Expand Up @@ -194,7 +195,14 @@ func (t *Trace) ClientRecord(cl *Client, name string, tags map[string]string) er
span := t.SSFSpan()
span.Name = name

return Record(cl, span, t.Sent)
err := Record(cl, span, t.Sent)
if err != nil {
cl.statsMtx.Lock()
defer cl.statsMtx.Unlock()
tags := []string{fmt.Sprintf("error:%s", err.Error())}
cl.stats.Incr("veneur.trace.record.errors_total", tags, 0.1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the metrics prefix that we set on our statsd client will cause the metric to be reported as veneur.veneur.trace.<...>. I wonder if SetErrorStats should have a sister method to set the metric name, too.

}
return err
}

func (t *Trace) Error(err error) {
Expand Down