From 4f4a7e09c57bd4e0601f2e30b523ebf3ee042300 Mon Sep 17 00:00:00 2001 From: Natalia Goc Date: Fri, 17 May 2024 15:46:25 +0200 Subject: [PATCH] cleanup unused and add short message to GELF --- example/main.go | 3 -- pkg/exporters/gelf_exporter/trace.go | 4 ++ pkg/tracer/event.go | 14 ------- pkg/tracer/middleware.go | 58 ---------------------------- 4 files changed, 4 insertions(+), 75 deletions(-) delete mode 100644 pkg/tracer/event.go delete mode 100644 pkg/tracer/middleware.go diff --git a/example/main.go b/example/main.go index 460f447..cad1895 100644 --- a/example/main.go +++ b/example/main.go @@ -16,9 +16,6 @@ import ( "github.com/gofiber/fiber/v2" ) -type AttributesX struct { -} - func main() { main := fiber.New(fiber.Config{ diff --git a/pkg/exporters/gelf_exporter/trace.go b/pkg/exporters/gelf_exporter/trace.go index 1c33823..3c4888f 100644 --- a/pkg/exporters/gelf_exporter/trace.go +++ b/pkg/exporters/gelf_exporter/trace.go @@ -82,6 +82,10 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) gelf.LongMessage = attrKV.Value.AsString() continue } + if attrKV.Key == attr.LogMessageShortKey { + gelf.ShortMessage = attrKV.Value.AsString() + continue + } if attrKV.Key == attr.SeverityLevelKey { gelf.Level = level.FromString(attrKV.Value.AsString()).IntoSyslogLevel() diff --git a/pkg/tracer/event.go b/pkg/tracer/event.go deleted file mode 100644 index 7894c43..0000000 --- a/pkg/tracer/event.go +++ /dev/null @@ -1,14 +0,0 @@ -package tracer - -import ( - "git.ma-al.com/gora_filip/observer/pkg/level" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/trace" -) - -func RecordError(span trace.Span, err error) error { - span.SetStatus(codes.Error, err.Error()) - span.RecordError(err) - - return nil -} diff --git a/pkg/tracer/middleware.go b/pkg/tracer/middleware.go deleted file mode 100644 index 139a9e5..0000000 --- a/pkg/tracer/middleware.go +++ /dev/null @@ -1,58 +0,0 @@ -package tracer - -import ( - "context" - "fmt" - "github.com/gofiber/fiber/v2" - fiberOpentelemetry "github.com/psmarcin/fiber-opentelemetry/pkg/fiber-otel" - "go.opentelemetry.io/otel/attribute" - trace "go.opentelemetry.io/otel/trace" - "runtime" -) - -func Handler(fc *fiber.Ctx) (context.Context, trace.Span) { - spanName := fmt.Sprint(fc.OriginalURL()) - simpleCtx, span := fiberOpentelemetry.Tracer.Start(fc.UserContext(), spanName) - - fc.SetUserContext(simpleCtx) - - _, file, line, _ := runtime.Caller(1) - span.SetAttributes( - attribute.String("service.layer", "handler"), - attribute.String("file", file), - attribute.String("line", fmt.Sprintf("%d", line)), - ) - - return simpleCtx, span -} - -func Service(c context.Context, spanName string) (context.Context, trace.Span) { - simpleCtx, span := fiberOpentelemetry.Tracer.Start(c, spanName) - var attribs []attribute.KeyValue - - _, file, line, _ := runtime.Caller(1) - attribs = append( - attribs, - attribute.String("service.layer", "service"), - attribute.String("file", file), - attribute.String("line", fmt.Sprintf("%d", line)), - ) - - span.SetAttributes(attribs...) - - return simpleCtx, span -} - -func Repository(c context.Context, spanName string) (context.Context, trace.Span) { - ctx2, span := fiberOpentelemetry.Tracer.Start(c, spanName) - var attribs []attribute.KeyValue - - _, file, line, _ := runtime.Caller(1) - attribs = append(attribs, - attribute.String("file", file), - attribute.String("line", fmt.Sprintf("%d", line)), - ) - span.SetAttributes(attribs...) - - return ctx2, span -}