Skip to content

Commit

Permalink
Merge branch 'main' into romain.marcadier/APPSEC-55160/orchestrion
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller authored Jan 20, 2025
2 parents 6e09796 + d8c71d4 commit 0dd7466
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contrib/gofiber/fiber.v2/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Middleware(opts ...Option) func(c *fiber.Ctx) error {
tracer.Tag(ext.Component, componentName),
tracer.Tag(ext.SpanKind, ext.SpanKindServer),
)
span, ctx := tracer.StartSpanFromContext(c.Context(), cfg.spanName, opts...)
span, ctx := tracer.StartSpanFromContext(c.UserContext(), cfg.spanName, opts...)

defer span.Finish()

Expand Down
20 changes: 20 additions & 0 deletions contrib/gofiber/fiber.v2/fiber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package fiber

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -178,11 +179,30 @@ func TestUserContext(t *testing.T) {

// setup
router := fiber.New()

// define a custom context key
type contextKey string
const fooKey contextKey = "foo"

// add a middleware that adds a value to the context
router.Use(func(c *fiber.Ctx) error {
ctx := context.WithValue(c.UserContext(), fooKey, "bar")
c.SetUserContext(ctx)
return c.Next()
})

// add the middleware
router.Use(Middleware(WithServiceName("foobar")))

router.Get("/", func(c *fiber.Ctx) error {
// check if not default empty context
assert.NotEmpty(c.UserContext())

// checks that the user context still has the information provided before using the middleware
foo, ok := c.UserContext().Value(fooKey).(string)
assert.True(ok)
assert.Equal(foo, "bar")

span, _ := tracer.StartSpanFromContext(c.UserContext(), "http.request")
defer span.Finish()
return c.SendString("test")
Expand Down

0 comments on commit 0dd7466

Please sign in to comment.