File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,17 @@ aspects:
2323 app.Use(fibertrace.Middleware())
2424 return app
2525 }()
26+ # Prevent FastHTTP double-instrumentation by marking the underlying server
27+ # as already instrumented before Fiber starts listening. This ensures that
28+ # when Fiber's internal call to fasthttp.Server.Serve() happens, the
29+ # DD_Instrumented flag is already set and the FastHTTP aspect will skip.
30+ - id : Listen
31+ join-point :
32+ function-body :
33+ function :
34+ - receiver : ' *github.com/gofiber/fiber/v2.App'
35+ - name : Listen
36+ advice :
37+ - prepend-statements :
38+ template : |
39+ {{ .Function.Receiver }}.Server().DD_Instrumented = true
Original file line number Diff line number Diff line change @@ -14,9 +14,10 @@ aspects:
1414 join-point :
1515 struct-definition : github.com/valyala/fasthttp.Server
1616 advice :
17- # Add instrumentation flag to prevent double-wrapping
17+ # Add instrumentation flag to prevent double-wrapping (exported so frameworks
18+ # like Fiber that use FastHTTP internally can set it to prevent double-instrumentation)
1819 - add-struct-field :
19- name : ' __dd_instrumented '
20+ name : ' DD_Instrumented '
2021 type : ' bool'
2122 # We need to use go:linkname to refer to wrapHandlerWithDefaults in order to avoid creating
2223 # circular dependencies, as contrib/valyala/fasthttp has a dependency on valyala/fasthttp...
@@ -40,7 +41,7 @@ aspects:
4041 template : |
4142 {{ $srv := .Function.Receiver }}
4243 // Only wrap Handler once, even if Serve() is called multiple times
43- if !{{ $srv }}.__dd_instrumented && {{ $srv }}.Handler != nil {
44+ if !{{ $srv }}.DD_Instrumented && {{ $srv }}.Handler != nil {
4445 {{ $srv }}.Handler = __dd_fasthttptrace_wrapHandler({{ $srv }}.Handler)
45- {{ $srv }}.__dd_instrumented = true
46+ {{ $srv }}.DD_Instrumented = true
4647 }
You can’t perform that action at this time.
0 commit comments