cleanup unused and add short message to GELF
This commit is contained in:
parent
d4dc790298
commit
4f4a7e09c5
@ -16,9 +16,6 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type AttributesX struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
main := fiber.New(fiber.Config{
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user