Skip to content

Commit ac2cd84

Browse files
committed
fix(internal/orchestrion/_integration/fiber.v2): avoid double instrumentation
1 parent 021a340 commit ac2cd84

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

contrib/gofiber/fiber.v2/orchestrion.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff 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

contrib/valyala/fasthttp/orchestrion.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)