observer/app/main.go

55 lines
981 B
Go
Raw Normal View History

2024-04-26 13:09:54 +00:00
package main
import (
"fmt"
"log"
"maal/tracer/pkg/tracer"
"os"
"os/signal"
"time"
"github.com/gofiber/fiber/v2"
"go.opentelemetry.io/otel/trace"
)
func main() {
main := fiber.New(fiber.Config{
StreamRequestBody: true,
})
main.Use(tracer.NewTracer(tracer.Config{
AppName: "test",
JaegerUrl: "http://localhost:4318/v1/traces",
2024-04-26 13:50:00 +00:00
GelfUrl: "192.168.220.30:12201",
2024-04-26 13:09:54 +00:00
Version: "1",
}))
defer tracer.ShutdownTracer()
main.Get("/", func(c *fiber.Ctx) error {
_, span := tracer.Handler(c)
defer span.End()
span.AddEvent("xd", trace.WithTimestamp(time.Now()))
_, span = tracer.Handler(c)
defer span.End()
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...")
}