2024-04-26 13:09:54 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-04-30 10:41:05 +00:00
|
|
|
"context"
|
2024-04-26 13:09:54 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
|
2024-04-30 12:42:05 +00:00
|
|
|
"git.ma-al.com/gora_filip/observer/pkg/tracer"
|
2024-05-17 13:31:35 +00:00
|
|
|
"git.ma-al.com/gora_filip/pkg/attr/layer_attr"
|
2024-05-17 08:37:05 +00:00
|
|
|
"git.ma-al.com/gora_filip/pkg/exporters"
|
2024-05-16 16:19:36 +00:00
|
|
|
"git.ma-al.com/gora_filip/pkg/fiber_tracing"
|
|
|
|
"git.ma-al.com/gora_filip/pkg/level"
|
2024-04-26 13:09:54 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
type AttributesX struct {
|
|
|
|
}
|
|
|
|
|
2024-04-26 13:09:54 +00:00
|
|
|
func main() {
|
|
|
|
|
|
|
|
main := fiber.New(fiber.Config{
|
|
|
|
StreamRequestBody: true,
|
|
|
|
})
|
|
|
|
|
2024-05-17 13:31:35 +00:00
|
|
|
exps := make([]exporters.TraceExporter, 0)
|
2024-05-17 08:37:05 +00:00
|
|
|
exps = append(exps, exporters.DevConsoleExporter())
|
|
|
|
gelfExp, err := exporters.GelfExporter()
|
|
|
|
if err == nil {
|
|
|
|
exps = append(exps, gelfExp)
|
|
|
|
}
|
2024-05-17 13:31:35 +00:00
|
|
|
|
2024-05-16 16:19:36 +00:00
|
|
|
main.Use(fiber_tracing.NewMiddleware(fiber_tracing.Config{
|
|
|
|
AppName: "example",
|
|
|
|
Version: "0.0.0",
|
|
|
|
ServiceProvider: "maal",
|
2024-05-17 08:37:05 +00:00
|
|
|
Exporters: exps,
|
2024-04-26 13:09:54 +00:00
|
|
|
}))
|
2024-05-16 16:19:36 +00:00
|
|
|
defer fiber_tracing.ShutdownTracer()
|
2024-04-26 13:09:54 +00:00
|
|
|
|
|
|
|
main.Get("/", func(c *fiber.Ctx) error {
|
2024-05-17 13:31:35 +00:00
|
|
|
ctx, span := fiber_tracing.FStart(c, layer_attr.Handler{
|
|
|
|
Level: level.DEBUG,
|
|
|
|
}.AsOpts())
|
2024-04-26 13:09:54 +00:00
|
|
|
defer span.End()
|
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
span.AddEvent(
|
|
|
|
"smthing is happening",
|
2024-05-17 13:31:35 +00:00
|
|
|
layer_attr.Handler{
|
|
|
|
Level: level.INFO,
|
|
|
|
}.AsOpts(),
|
2024-04-30 10:41:05 +00:00
|
|
|
)
|
2024-04-26 13:09:54 +00:00
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
err := Serv(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return tracer.RecordError(span, err)
|
|
|
|
}
|
2024-04-26 13:09:54 +00:00
|
|
|
|
|
|
|
return c.SendString("xd")
|
|
|
|
})
|
|
|
|
|
|
|
|
// handle interrupts (shutdown)
|
|
|
|
c := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(c, os.Interrupt)
|
|
|
|
go func() {
|
|
|
|
oscall := <-c
|
|
|
|
log.Printf("system call: %+v", oscall)
|
|
|
|
main.Shutdown()
|
|
|
|
}()
|
|
|
|
if err := main.Listen(fmt.Sprintf(":%d", 3344)); err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
fmt.Println("Shutting down...")
|
|
|
|
|
|
|
|
}
|
2024-04-30 10:41:05 +00:00
|
|
|
|
|
|
|
func Serv(ctx context.Context) *fiber.Error {
|
2024-05-16 11:45:13 +00:00
|
|
|
ctx, span := tracer.Service(ctx, "service", "service span")
|
2024-04-30 10:41:05 +00:00
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
for range []int{1, 2, 3} {
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := Repo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fiber.NewError(500, "xd")
|
|
|
|
}
|
|
|
|
|
|
|
|
return fiber.NewError(500, "x")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Repo(ctx context.Context) error {
|
2024-05-16 11:45:13 +00:00
|
|
|
ctx, span := tracer.Repository(ctx, "repo", "repo span")
|
2024-04-30 10:41:05 +00:00
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
for range []int{1, 2, 3} {
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|