Compare commits
2 Commits
bunroutero
...
logotel/v0
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f9d189806 | |||
| 2963386f32 |
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
const (
|
||||
tracerName = "git.blauwelle.com/go/crate/bunrouterotel"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -53,18 +53,21 @@ func Middleware(serverName string, opts ...Option) bunrouter.MiddlewareFunc {
|
||||
var spanName string
|
||||
params := req.Params()
|
||||
route := params.Route()
|
||||
if route != "" {
|
||||
spanName = req.Method + " " + route
|
||||
} else {
|
||||
spanName = "HTTP " + req.Method + " route not found"
|
||||
if route == "" {
|
||||
if req.Request != nil && req.Request.URL != nil && req.Request.URL.Path != "" {
|
||||
route = req.Request.URL.Path
|
||||
} else {
|
||||
route = "route not found"
|
||||
}
|
||||
}
|
||||
tarcerStartOpts := []trace.SpanStartOption{
|
||||
spanName = req.Method + " " + route
|
||||
tracerStartOpts := []trace.SpanStartOption{
|
||||
trace.WithAttributes(semconv.NetAttributesFromHTTPRequest("tcp", req.Request)...),
|
||||
trace.WithAttributes(semconv.EndUserAttributesFromHTTPRequest(req.Request)...),
|
||||
trace.WithAttributes(semconv.HTTPServerAttributesFromHTTPRequest(serverName, route, req.Request)...),
|
||||
trace.WithSpanKind(trace.SpanKindServer),
|
||||
}
|
||||
ctx, span := tracer.Start(ctx, spanName, tarcerStartOpts...)
|
||||
ctx, span := tracer.Start(ctx, spanName, tracerStartOpts...)
|
||||
req.Request = req.Request.WithContext(ctx)
|
||||
paramSlice := params.Slice()
|
||||
attrs := make([]attribute.KeyValue, 0, len(paramSlice))
|
||||
|
||||
@@ -7,3 +7,8 @@ require (
|
||||
go.opentelemetry.io/otel v1.13.0
|
||||
go.opentelemetry.io/otel/trace v1.13.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/go-logr/logr v1.2.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
)
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
git.blauwelle.com/go/crate/log v0.9.0 h1:H01AQIKcYybeCZGdReBzMoWhkXPQJAoY1t+K0J1asEk=
|
||||
git.blauwelle.com/go/crate/log v0.9.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
|
||||
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
|
||||
@@ -37,7 +37,11 @@ func (processor *Processor) Process(ctx context.Context, entry logsdk.ReadonlyEn
|
||||
span := trace.SpanFromContext(ctx)
|
||||
if !span.IsRecording() {
|
||||
if processor.defaultSpan {
|
||||
ctx, span = otel.Tracer("git.blauwelle.com/go/crate/logotel").Start(ctx, "default") //nolint:ineffassign,staticcheck,wastedassign
|
||||
name := entry.Message
|
||||
if name == "" {
|
||||
name = "default"
|
||||
}
|
||||
ctx, span = otel.Tracer("git.blauwelle.com/go/crate/logotel").Start(ctx, name) //nolint:ineffassign,staticcheck,wastedassign
|
||||
defer span.End()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user