Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifests/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ manifest:
tests/auto_inject/test_auto_inject_install.py::TestContainerAutoInjectInstallScriptAppsec: v2.0.0
tests/auto_inject/test_auto_inject_install.py::TestHostAutoInjectInstallScriptAppsec: v2.0.0
tests/auto_inject/test_auto_inject_install.py::TestSimpleInstallerAutoInjectManualAppsec: v2.0.0
tests/cws/test_thread_context_sharing.py::Test_ThreadContextSharing: missing_feature (missing /security/thread_context_sharing endpoint on weblog)
tests/cws/test_thread_context_sharing.py::Test_ThreadContextSharing: v2.11.0-dev
tests/debugger/test_debugger_capture_expressions.py::Test_Debugger_Line_Capture_Expressions: v2.2.3
tests/debugger/test_debugger_capture_expressions.py::Test_Debugger_Method_Capture_Expressions: v2.2.3
tests/debugger/test_debugger_capture_expressions.py::Test_Debugger_Method_Capture_Expressions::test_complex_capture_expressions: missing_feature (index expression not yet supported in Go system-probe)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package common

import (
"encoding/json"
"math/big"
"net/http"
"os"
"strconv"

"github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
)

func ThreadContextSharing(w http.ResponseWriter, r *http.Request) {
span, ok := tracer.SpanFromContext(r.Context())
if !ok {
w.WriteHeader(http.StatusInternalServerError)
return
}

path := r.URL.Query().Get("path")
if err := os.WriteFile(path, []byte("system-tests thread context sharing"), 0o644); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

// SpanContext.TraceID() returns the full 128-bit trace id as a hex string;
// convert it to decimal to match the other weblogs' response format.
traceID, ok := new(big.Int).SetString(span.Context().TraceID(), 16)
if !ok {
w.WriteHeader(http.StatusInternalServerError)
return
}

jsonResponse, err := json.Marshal(struct {
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
}{
TraceID: traceID.String(),
SpanID: strconv.FormatUint(span.Context().SpanID(), 10),
})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

w.Header().Set("Content-Type", "application/json")
if _, err := w.Write(jsonResponse); err != nil {
return
}
}
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/chi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/make_distant_call", func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/echo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func main() {
})

r.Any("/trace/manual_keep_drop", echoHandleFunc(common.ManualKeepDrop))
r.Any("/security/thread_context_sharing", echoHandleFunc(common.ThreadContextSharing))

r.Any("/make_distant_call", func(c echo.Context) error {
url := c.Request().URL.Query().Get("url")
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func main() {
})

r.Any("/trace/manual_keep_drop", ginHandleFunc(common.ManualKeepDrop))
r.Any("/security/thread_context_sharing", ginHandleFunc(common.ThreadContextSharing))

r.Any("/make_distant_call", func(ctx *gin.Context) {
url := ctx.Request.URL.Query().Get("url")
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/gqlgen/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {

Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/graph-gophers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {

Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/graphql-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/make_distant_call", func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/net-http-span-pool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func main() {
})

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/make_distant_call", func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
Expand Down
1 change: 1 addition & 0 deletions utils/build/docker/golang/app/net-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func main() {
mux.HandleFunc("/spawn_child", common.SpawnChild)

mux.HandleFunc("/trace/manual_keep_drop", common.ManualKeepDrop)
mux.HandleFunc("/security/thread_context_sharing", common.ThreadContextSharing)

mux.HandleFunc("/make_distant_call", func(w http.ResponseWriter, r *http.Request) {
url := r.URL.Query().Get("url")
Expand Down
4 changes: 4 additions & 0 deletions utils/build/docker/golang/weblog_metadata.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# docs/understand/weblogs/weblog-metadata.md

haproxy:
Expand All @@ -11,12 +12,15 @@ apim:
supported_scenarios: [APPSEC_BLOCKING, DEFAULT]
graphql-go:
categories: [dd_trace_graphql]
supported_scenarios: [THREAD_CONTEXT_SHARING]
excluded_scenarios: [GRAPHQL_ERROR_TRACKING] # why ???
gqlgen:
categories: [dd_trace_graphql]
supported_scenarios: [THREAD_CONTEXT_SHARING]
excluded_scenarios: [GRAPHQL_ERROR_TRACKING] # why ???
graph-gophers:
categories: [dd_trace_graphql]
supported_scenarios: [THREAD_CONTEXT_SHARING]
excluded_scenarios: [GRAPHQL_ERROR_TRACKING] # why ???
echo:
categories: [dd_trace]
Expand Down
Loading