okit/examples/overview/main.go

63 lines
1.4 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 main
import (
"context"
"os/signal"
"syscall"
"time"
"go.pitz.tech/okit"
)
var tags []okit.Tag
func do(ctx context.Context) {
ctx, done := okit.With(tags...).Trace(ctx)
defer done()
// DO WORK!
select {
case <-ctx.Done():
case <-time.After(time.Second):
}
}
func main() {
ctx, shutdown := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer shutdown()
// Metric emission
okit.Observe("", 0, tags...)
// Multi-dimensional events
okit.Emit("", tags...)
// Tracing
ctx, done := okit.Trace(context.Background())
defer done()
// Logging
okit.Debug("", tags...)
okit.Info("", tags...)
okit.Warn("", tags...)
okit.Error("", tags...)
do(ctx)
}