okit/api_impl.go

78 lines
1.9 KiB
Go
Raw Normal View History

2022-11-01 16:21:43 +00:00
// Copyright (C) 2022 Mya Pitzeruse
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package okit
import (
"context"
"crypto/rand"
"encoding/base64"
"io"
"time"
)
// contextKey is a holder structure that allows data to be attached to contexts.
type contextKey string
// spanKey identifies a span on a given context.
var spanKey = contextKey("okit.span")
// TODO: allow this to be replaced
var defaultClient Interface[Client] = Client{
now: time.Now,
uuid: func() string {
buf := make([]byte, 16)
n, err := io.ReadFull(rand.Reader, buf)
if err != nil {
panic(err)
}
return base64.RawStdEncoding.EncodeToString(buf[:n])
},
}
func With(tags ...Tag) Client {
return defaultClient.With(tags...)
}
func Emit(event string, tags ...Tag) {
defaultClient.Emit(event, tags...)
}
func Observe(metric string, value float64, tags ...Tag) {
defaultClient.Observe(metric, value, tags...)
}
func Trace(ctx context.Context, tags ...Tag) (context.Context, DoneFunc) {
return defaultClient.Trace(ctx, tags...)
}
func Debug(msg string, tags ...Tag) {
defaultClient.Debug(msg, tags...)
}
func Info(msg string, tags ...Tag) {
defaultClient.Info(msg, tags...)
}
func Warn(msg string, tags ...Tag) {
defaultClient.Warn(msg, tags...)
}
func Error(msg string, tags ...Tag) {
defaultClient.Error(msg, tags...)
}