cleanup unused and add short message to GELF

This commit is contained in:
Natalia Goc 2024-05-17 15:46:25 +02:00
parent d4dc790298
commit 4f4a7e09c5
4 changed files with 4 additions and 75 deletions

View File

@ -16,9 +16,6 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
type AttributesX struct {
}
func main() { func main() {
main := fiber.New(fiber.Config{ main := fiber.New(fiber.Config{

View File

@ -82,6 +82,10 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
gelf.LongMessage = attrKV.Value.AsString() gelf.LongMessage = attrKV.Value.AsString()
continue continue
} }
if attrKV.Key == attr.LogMessageShortKey {
gelf.ShortMessage = attrKV.Value.AsString()
continue
}
if attrKV.Key == attr.SeverityLevelKey { if attrKV.Key == attr.SeverityLevelKey {
gelf.Level = level.FromString(attrKV.Value.AsString()).IntoSyslogLevel() gelf.Level = level.FromString(attrKV.Value.AsString()).IntoSyslogLevel()

View File

@ -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
}

View File

@ -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
}