Back integrate with patchy

This commit is contained in:
Ian Gulliver
2023-06-12 20:18:19 -07:00
parent b44b1f4c1f
commit 5b9725f98d
2 changed files with 10 additions and 5 deletions

View File

@@ -11,6 +11,9 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
// TODO: Switch to opentelemetry protocol
// TODO: Add protocol-level tests
type Client struct { type Client struct {
targets []*Target targets []*Target
hooks []Hook hooks []Hook
@@ -43,16 +46,18 @@ func (c *Client) AddTarget(url string, headers map[string]string, writePeriodSec
return target return target
} }
func (c *Client) AddHook(hook Hook) { func (c *Client) AddHook(hook Hook) *Client {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
c.hooks = append(c.hooks, hook) c.hooks = append(c.hooks, hook)
return c
} }
func (c *Client) Log(ctx context.Context, vals ...any) { func (c *Client) Log(ctx context.Context, vals ...any) {
ev := newEvent("log", vals...) ev := NewEvent("log", vals...)
c.writeEvent(ctx, ev) c.WriteEvent(ctx, ev)
parts := []string{} parts := []string{}
@@ -72,7 +77,7 @@ func (c *Client) Close() {
} }
} }
func (c *Client) writeEvent(ctx context.Context, ev *Event) { func (c *Client) WriteEvent(ctx context.Context, ev *Event) {
ev.Set("durationMS", time.Since(ev.start).Milliseconds()) ev.Set("durationMS", time.Since(ev.start).Milliseconds())
c.mu.Lock() c.mu.Lock()

View File

@@ -10,7 +10,7 @@ type Event struct {
Data map[string]any `json:"data"` Data map[string]any `json:"data"`
} }
func newEvent(eventType string, vals ...any) *Event { func NewEvent(eventType string, vals ...any) *Event {
now := time.Now() now := time.Now()
ev := &Event{ ev := &Event{