diff --git a/manifests/golang.yml b/manifests/golang.yml index 5ebc644513..c8862226fc 100644 --- a/manifests/golang.yml +++ b/manifests/golang.yml @@ -566,7 +566,28 @@ tests/: "*": irrelevant net-http: missing_feature (Endpoint not implemented) net-http-orchestrion: missing_feature (Endpoint not implemented) - test_inferred_proxy.py: missing_feature + test_inferred_proxy.py: + Test_AWS_API_Gateway_Inferred_Span_Creation: + "*": irrelevant + chi: v1.72.0 + echo: v1.72.0 + gin: v1.72.0 + net-http: v1.72.0 + net-http-orchestrion: v1.72.0 + Test_AWS_API_Gateway_Inferred_Span_Creation_With_Distributed_Context: + "*": irrelevant + chi: v1.72.0 + echo: v1.72.0 + gin: v1.72.0 + net-http: v1.72.0 + net-http-orchestrion: v1.72.0 + Test_AWS_API_Gateway_Inferred_Span_Creation_With_Error: + "*": irrelevant + chi: v1.72.0 + echo: v1.72.0 + gin: v1.72.0 + net-http: v1.72.0 + net-http-orchestrion: v1.72.0 test_otel_drop_in.py: Test_Otel_Drop_In: missing_feature otel/: diff --git a/manifests/nodejs.yml b/manifests/nodejs.yml index a59408e284..2963b94f6a 100644 --- a/manifests/nodejs.yml +++ b/manifests/nodejs.yml @@ -868,16 +868,16 @@ tests/: test_inferred_proxy.py: Test_AWS_API_Gateway_Inferred_Span_Creation: '*': irrelevant - express4: *ref_5_26_0 - express5: *ref_5_26_0 + express4: missing_feature # _dd.inferred_span needs to be a metric + express5: missing_feature # _dd.inferred_span needs to be a metric Test_AWS_API_Gateway_Inferred_Span_Creation_With_Distributed_Context: '*': irrelevant - express4: *ref_5_26_0 - express5: *ref_5_26_0 + express4: missing_feature # _dd.inferred_span needs to be a metric + express5: missing_feature # _dd.inferred_span needs to be a metric Test_AWS_API_Gateway_Inferred_Span_Creation_With_Error: '*': irrelevant - express4: *ref_5_26_0 - express5: *ref_5_26_0 + express4: missing_feature # _dd.inferred_span needs to be a metric + express5: missing_feature # _dd.inferred_span needs to be a metric test_otel_drop_in.py: Test_Otel_Drop_In: missing_feature otel/: diff --git a/manifests/python.yml b/manifests/python.yml index 885c5c1470..e56ae48b7a 100644 --- a/manifests/python.yml +++ b/manifests/python.yml @@ -799,13 +799,13 @@ tests/: test_inferred_proxy.py: Test_AWS_API_Gateway_Inferred_Span_Creation: '*': irrelevant - flask-poc: v3.1.0 + flask-poc: missing_feature # _dd.inferred_span needs to be a metric Test_AWS_API_Gateway_Inferred_Span_Creation_With_Distributed_Context: '*': irrelevant - flask-poc: v3.1.0 + flask-poc: missing_feature # _dd.inferred_span needs to be a metric Test_AWS_API_Gateway_Inferred_Span_Creation_With_Error: '*': irrelevant - flask-poc: v3.1.0 + flask-poc: missing_feature # _dd.inferred_span needs to be a metric test_otel_drop_in.py: Test_Otel_Drop_In: missing_feature otel/: diff --git a/tests/integrations/test_inferred_proxy.py b/tests/integrations/test_inferred_proxy.py index 17377b7954..2f05dfb707 100644 --- a/tests/integrations/test_inferred_proxy.py +++ b/tests/integrations/test_inferred_proxy.py @@ -151,13 +151,12 @@ def assert_api_gateway_span(testCase, span, path, status_code, is_distributed=Fa assert ( span["service"] == "system-tests-api-gateway.com" ), "Inferred AWS API Gateway span expected service should equal 'system-tests-api-gateway.com'" - assert "span.kind" in span["meta"], "Inferred AWS API Gateway span meta should contain 'span.kind'" - assert ( - span["meta"]["span.kind"] == "internal" - ), "Inferred AWS API Gateway span meta span.kind should equal 'internal'" assert "stage" in span["meta"], "Inferred AWS API Gateway span meta should contain 'stage'" assert span["meta"]["stage"] == "staging", "Inferred AWS API Gateway span meta expected stage to be 'staging'" assert "start" in span, "Inferred AWS API Gateway span should have 'startTime'" + assert ( + span["metrics"]["_dd.inferred_span"] == 1 + ), "Inferred AWS API Gateway span meta expected _dd.inferred_span = 1" # assert on HTTP tags assert "http.method" in span["meta"], "Inferred AWS API Gateway span meta should contain 'http.method'" diff --git a/utils/build/docker/golang/app/chi/main.go b/utils/build/docker/golang/app/chi/main.go index 6d5df0c336..ad7bf37393 100644 --- a/utils/build/docker/golang/app/chi/main.go +++ b/utils/build/docker/golang/app/chi/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "log" "math/rand" @@ -305,6 +306,30 @@ func main() { mux.HandleFunc("/requestdownstream", common.Requestdownstream) mux.HandleFunc("/returnheaders", common.Returnheaders) + mux.HandleFunc("/inferred-proxy/span-creation", func(w http.ResponseWriter, r *http.Request) { + statusCodeStr := r.URL.Query().Get("status_code") + statusCode := 200 + if statusCodeStr != "" { + var err error + statusCode, err = strconv.Atoi(statusCodeStr) + if err != nil { + statusCode = 400 // Bad request if conversion fails + } + } + + // Log the request headers + fmt.Println("Received an API Gateway request") + for key, values := range r.Header { + for _, value := range values { + fmt.Printf("%s: %s\n", key, value) + } + } + + // Send the response + w.WriteHeader(statusCode) + w.Write([]byte("ok")) + }) + srv := &http.Server{ Addr: ":7777", Handler: mux, diff --git a/utils/build/docker/golang/app/echo/main.go b/utils/build/docker/golang/app/echo/main.go index 767d66a13d..81dbb6ec2a 100644 --- a/utils/build/docker/golang/app/echo/main.go +++ b/utils/build/docker/golang/app/echo/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "log" "math/rand" @@ -264,6 +265,29 @@ func main() { return ctx.NoContent(200) }) + r.GET("/inferred-proxy/span-creation", func(ctx echo.Context) error { + statusCodeStr := ctx.Request().URL.Query().Get("status_code") + statusCode := 200 + if statusCodeStr != "" { + var err error + statusCode, err = strconv.Atoi(statusCodeStr) + if err != nil { + statusCode = 400 + return ctx.String(statusCode, "no inferred span") + } + } + + // Log the request headers + fmt.Println("Received an API Gateway request") + for key, values := range ctx.Request().Header { + for _, value := range values { + fmt.Printf("%s: %s\n", key, value) + } + } + + return ctx.String(statusCode, "ok") + }) + r.Any("/rasp/lfi", echoHandleFunc(rasp.LFI)) r.Any("/rasp/ssrf", echoHandleFunc(rasp.SSRF)) r.Any("/rasp/sqli", echoHandleFunc(rasp.SQLi)) diff --git a/utils/build/docker/golang/app/gin/main.go b/utils/build/docker/golang/app/gin/main.go index 19de3e874c..2b4de694b5 100644 --- a/utils/build/docker/golang/app/gin/main.go +++ b/utils/build/docker/golang/app/gin/main.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io" "log" "math/rand" @@ -240,6 +241,30 @@ func main() { appsec.TrackUserLoginSuccessEvent(ctx.Request.Context(), user, map[string]string{}, tracer.WithUserSessionID(cookie.Value)) }) + r.GET("/inferred-proxy/span-creation", func(ctx *gin.Context) { + statusCodeStr := ctx.Query("status_code") + statusCode := 200 + if statusCodeStr != "" { + var err error + statusCode, err = strconv.Atoi(statusCodeStr) + if err != nil { + statusCode = 400 + } + } + + // Log the request headers + fmt.Println("Received an API Gateway request") + for key, values := range ctx.Request.Header { + for _, value := range values { + fmt.Printf("%s: %s\n", key, value) + } + } + + // Send the response + ctx.Writer.WriteHeader(statusCode) + ctx.Writer.Write([]byte("ok")) + }) + r.Any("/rasp/lfi", ginHandleFunc(rasp.LFI)) r.Any("/rasp/ssrf", ginHandleFunc(rasp.SSRF)) r.Any("/rasp/sqli", ginHandleFunc(rasp.SQLi)) diff --git a/utils/build/docker/golang/app/net-http-orchestrion/main.go b/utils/build/docker/golang/app/net-http-orchestrion/main.go index 5e1147becb..f1d424d7ff 100644 --- a/utils/build/docker/golang/app/net-http-orchestrion/main.go +++ b/utils/build/docker/golang/app/net-http-orchestrion/main.go @@ -529,6 +529,30 @@ func main() { appsec.TrackUserLoginSuccessEvent(r.Context(), user, map[string]string{}, tracer.WithUserSessionID(cookie.Value)) }) + mux.HandleFunc("/inferred-proxy/span-creation", func(w http.ResponseWriter, r *http.Request) { + statusCodeStr := r.URL.Query().Get("status_code") + statusCode := 200 + if statusCodeStr != "" { + var err error + statusCode, err = strconv.Atoi(statusCodeStr) + if err != nil { + statusCode = 400 // Bad request if conversion fails + } + } + + // Log the request headers + fmt.Println("Received an API Gateway request") + for key, values := range r.Header { + for _, value := range values { + fmt.Printf("%s: %s\n", key, value) + } + } + + // Send the response + w.WriteHeader(statusCode) + w.Write([]byte("ok")) + }) + mux.HandleFunc("/requestdownstream", common.Requestdownstream) mux.HandleFunc("/returnheaders", common.Returnheaders) diff --git a/utils/build/docker/golang/app/net-http/main.go b/utils/build/docker/golang/app/net-http/main.go index 497d05f01e..f633129910 100644 --- a/utils/build/docker/golang/app/net-http/main.go +++ b/utils/build/docker/golang/app/net-http/main.go @@ -29,10 +29,10 @@ import ( "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + otelbaggage "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" oteltrace "go.opentelemetry.io/otel/trace" - otelbaggage "go.opentelemetry.io/otel/baggage" "gopkg.in/DataDog/dd-trace-go.v1/appsec" httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http" @@ -550,7 +550,7 @@ func main() { spanContext := oteltrace.SpanContextFromContext(ctx) baggage := otelbaggage.FromContext(ctx) - + base := 16 bitSize := 64 result := make(map[string]any, 4) @@ -567,7 +567,7 @@ func main() { result["tracestate"] = spanContext.TraceState().String() result["baggage"] = baggage.String() - + jsonData, err := json.Marshal(result) if err != nil { w.WriteHeader(422) @@ -626,6 +626,30 @@ func main() { appsec.TrackUserLoginSuccessEvent(r.Context(), user, map[string]string{}, tracer.WithUserSessionID(cookie.Value)) }) + mux.HandleFunc("/inferred-proxy/span-creation", func(w http.ResponseWriter, r *http.Request) { + statusCodeStr := r.URL.Query().Get("status_code") + statusCode := 200 + if statusCodeStr != "" { + var err error + statusCode, err = strconv.Atoi(statusCodeStr) + if err != nil { + statusCode = 400 // Bad request if conversion fails + } + } + + // Log the request headers + fmt.Println("Received an API Gateway request") + for key, values := range r.Header { + for _, value := range values { + fmt.Printf("%s: %s\n", key, value) + } + } + + // Send the response + w.WriteHeader(statusCode) + w.Write([]byte("ok")) + }) + mux.HandleFunc("/requestdownstream", common.Requestdownstream) mux.HandleFunc("/returnheaders", common.Returnheaders)