start reworking exporters to be more composable

This commit is contained in:
2024-05-16 18:19:36 +02:00
parent ab5b70704d
commit fc92995cc8
10 changed files with 459 additions and 166 deletions

View File

@ -8,10 +8,13 @@ import (
"os/signal"
"time"
"git.ma-al.com/gora_filip/observer/pkg/level"
"git.ma-al.com/gora_filip/observer/pkg/tracer"
"git.ma-al.com/gora_filip/pkg/attr"
"git.ma-al.com/gora_filip/pkg/combined_exporter"
"git.ma-al.com/gora_filip/pkg/console_exporter"
"git.ma-al.com/gora_filip/pkg/fiber_tracing"
"git.ma-al.com/gora_filip/pkg/level"
"github.com/gofiber/fiber/v2"
"go.opentelemetry.io/otel/trace"
)
type AttributesX struct {
@ -23,13 +26,21 @@ func main() {
StreamRequestBody: true,
})
main.Use(tracer.NewTracer(tracer.Config{
AppName: "test",
JaegerUrl: "http://localhost:4318/v1/traces",
GelfUrl: "192.168.220.30:12201",
Version: "1",
lvl := level.DEBUG
exporter := combined_exporter.NewExporter(
console_exporter.NewExporter(
console_exporter.ExporterOptions{
FilterOnLevel: &lvl,
//EmitOnlyOnError: true,
},
))
main.Use(fiber_tracing.NewMiddleware(fiber_tracing.Config{
AppName: "example",
Version: "0.0.0",
ServiceProvider: "maal",
Exporter: exporter,
}))
defer tracer.ShutdownTracer()
defer fiber_tracing.ShutdownTracer()
main.Get("/", func(c *fiber.Ctx) error {
ctx, span := tracer.Handler(c)
@ -37,13 +48,7 @@ func main() {
span.AddEvent(
"smthing is happening",
trace.WithAttributes(
tracer.LongMessage("smthing is happening - long"),
tracer.JsonAttr("smth", map[string]interface{}{
"xd": 1,
}),
tracer.Level(level.ALERT),
),
attr.WithAttributes(attr.SeverityLevel(level.INFO), attr.SourceCodeLocation(1)),
)
err := Serv(ctx)