Skip to content

Commit 048b7a2

Browse files
committed
fix(contrib/valyala/fasthttp): break circular dependency
1 parent 12c9fed commit 048b7a2

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

contrib/valyala/fasthttp/fasthttp.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ func init() {
2525

2626
// WrapHandler wraps a fasthttp.RequestHandler with tracing middleware
2727
func WrapHandler(h fasthttp.RequestHandler, opts ...Option) fasthttp.RequestHandler {
28+
return wrapHandler(h, opts...)
29+
}
30+
31+
// wrapHandlerWithDefaults is used by go:linkname in orchestrion aspects
32+
// to avoid circular dependencies. It has a simple signature without variadic
33+
// arguments so it can be safely referenced via linkname.
34+
func wrapHandlerWithDefaults(h fasthttp.RequestHandler) fasthttp.RequestHandler {
35+
return wrapHandler(h)
36+
}
37+
38+
func wrapHandler(h fasthttp.RequestHandler, opts ...Option) fasthttp.RequestHandler {
2839
cfg := newConfig()
2940
for _, fn := range opts {
3041
fn.apply(cfg)

contrib/valyala/fasthttp/orchestrion.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ aspects:
1818
- add-struct-field:
1919
name: '__dd_instrumented'
2020
type: 'bool'
21+
# We need to use go:linkname to refer to wrapHandlerWithDefaults in order to avoid creating
22+
# circular dependencies, as contrib/valyala/fasthttp has a dependency on valyala/fasthttp...
23+
- inject-declarations:
24+
links:
25+
- github.com/DataDog/dd-trace-go/contrib/valyala/fasthttp/v2
26+
template: |-
27+
//go:linkname __dd_fasthttptrace_wrapHandler github.com/DataDog/dd-trace-go/contrib/valyala/fasthttp/v2.wrapHandlerWithDefaults
28+
func __dd_fasthttptrace_wrapHandler(RequestHandler) RequestHandler
2129
# FastHTTP Server instrumentation
2230
# All server startup methods (ListenAndServe, ServeTLS, etc.) eventually call Serve(ln)
2331
# By targeting only Serve(), we avoid hot-path overhead and ensure complete coverage
@@ -27,14 +35,12 @@ aspects:
2735
function:
2836
- receiver: '*github.com/valyala/fasthttp.Server'
2937
- name: 'Serve' # Single entry point for all server startup methods
30-
advice:
38+
advice:
3139
- prepend-statements:
32-
imports:
33-
fasthttptrace: github.com/DataDog/dd-trace-go/contrib/valyala/fasthttp/v2
3440
template: |
3541
{{ $srv := .Function.Receiver }}
3642
// Only wrap Handler once, even if Serve() is called multiple times
3743
if !{{ $srv }}.__dd_instrumented && {{ $srv }}.Handler != nil {
38-
{{ $srv }}.Handler = fasthttptrace.WrapHandler({{ $srv }}.Handler)
44+
{{ $srv }}.Handler = __dd_fasthttptrace_wrapHandler({{ $srv }}.Handler)
3945
{{ $srv }}.__dd_instrumented = true
4046
}

internal/orchestrion/_integration/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/99designs/gqlgen v0.17.83
99
github.com/DataDog/datadog-agent/pkg/proto v0.71.2
1010
github.com/DataDog/dd-trace-go/instrumentation/testutils/containers/v2 v2.4.0-dev
11-
github.com/DataDog/dd-trace-go/orchestrion/all/v2 v2.4.0-dev
11+
github.com/DataDog/dd-trace-go/orchestrion/all/v2 v2.5.0-dev
1212
github.com/DataDog/dd-trace-go/v2 v2.5.0-dev
1313
github.com/DataDog/go-libddwaf/v4 v4.7.0
1414
github.com/DataDog/orchestrion v1.6.1
@@ -469,7 +469,7 @@ replace github.com/DataDog/dd-trace-go/contrib/valyala/fasthttp/v2 => ../../../c
469469

470470
replace github.com/DataDog/dd-trace-go/orchestrion/all/v2 => ../../../orchestrion/all
471471

472-
replace github.com/DataDog/dd-trace-go/v2 => ../../..
472+
replace github.com/DataDog/dd-trace-go/v2 => github.com/DataDog/dd-trace-go/v2 v2.5.0-dev
473473

474474
replace google.golang.org/grpc => google.golang.org/grpc v1.70.0
475475

internal/orchestrion/_integration/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ github.com/DataDog/datadog-go/v5 v5.8.1 h1:+GOES5W9zpKlhwHptZVW2C0NLVf7ilr7pHkDc
806806
github.com/DataDog/datadog-go/v5 v5.8.1/go.mod h1:K9kcYBlxkcPP8tvvjZZKs/m1edNAUFzBbdpTUKfCsuw=
807807
github.com/DataDog/dd-trace-go/instrumentation/testutils/grpc/v2 v2.4.0-dev h1:srl0FPpKiginZRfuUCioeUV8gJuTLmNY7pS6AxZl4qQ=
808808
github.com/DataDog/dd-trace-go/instrumentation/testutils/grpc/v2 v2.4.0-dev/go.mod h1:rG6TpmIBAZEpcNHjD1q/4qtbWNKWw61UH3IS+FsjReQ=
809+
github.com/DataDog/dd-trace-go/v2 v2.5.0-dev h1:BKDcb+k5FB4FEeUjA+Vb7qJL5g+RyzN/UGd2MrkkRCM=
810+
github.com/DataDog/dd-trace-go/v2 v2.5.0-dev/go.mod h1:97SyFH3WtMxNizPKpncW0yOMAtBh2j3X9zMP7hKj9lk=
809811
github.com/DataDog/go-libddwaf/v4 v4.7.0 h1:oF2YaaEtu7MYd5TrwceXUsJYdJ6b1kmLZsAj0up/0po=
810812
github.com/DataDog/go-libddwaf/v4 v4.7.0/go.mod h1:/AZqP6zw3qGJK5mLrA0PkfK3UQDk1zCI2fUNCt4xftE=
811813
github.com/DataDog/go-runtime-metrics-internal v0.0.4-0.20250806100345-ca5e7fdaf7b6 h1:rIMZ3Bqn2w8nWrAIXekOdm+sZVxUYHGX8cS7P9W06Kk=

0 commit comments

Comments
 (0)