79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
// Copyright (C) 2022 The OKit Authors
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
// copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
// OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
package okit
|
|
|
|
import (
|
|
"bufio"
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/golang/protobuf/jsonpb"
|
|
)
|
|
|
|
// DefaultClient provides a default client implementation.
|
|
var DefaultClient = NewClient()
|
|
|
|
// TODO: make this configurable
|
|
var sink = bufio.NewWriter(os.Stdout)
|
|
var marshaler = &jsonpb.Marshaler{}
|
|
|
|
// 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")
|
|
|
|
// With returns a client containing additional tags.
|
|
func With(tags ...Tag) Client {
|
|
return DefaultClient.WithCallerSkip(3).With(tags...)
|
|
}
|
|
|
|
// Emit emits an event with the provided tags.
|
|
func Emit(event string, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Emit(event, tags...)
|
|
}
|
|
|
|
// Observe reports a metric value with the provided tags.
|
|
func Observe(metric string, value float64, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Observe(metric, value, tags...)
|
|
}
|
|
|
|
// Trace traces a function call. It implements distributed tracing and bookend events.
|
|
func Trace(ctx context.Context, tags ...Tag) (context.Context, DoneFunc) {
|
|
return DefaultClient.WithCallerSkip(3).Trace(ctx, tags...)
|
|
}
|
|
|
|
func Debug(msg string, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Debug(msg, tags...)
|
|
}
|
|
|
|
func Info(msg string, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Info(msg, tags...)
|
|
}
|
|
|
|
func Warn(msg string, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Warn(msg, tags...)
|
|
}
|
|
|
|
func Error(msg string, tags ...Tag) {
|
|
DefaultClient.WithCallerSkip(3).Error(msg, tags...)
|
|
}
|