summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/tracing/module_test.go
diff options
context:
space:
mode:
authorDavid Frickert <david.frickert@protonmail.com>2023-01-25 07:26:44 +0000
committerGitHub <noreply@github.com>2023-01-25 02:26:44 -0500
commit962310204f088a74719a48fa2dc76e76934dfa09 (patch)
treec21afae2445a95949bb81bef5335137983740965 /modules/caddyhttp/tracing/module_test.go
parent98867ac3468b33c012ae75a14c8d923117629dc2 (diff)
tracing: Support placeholders in span name (#5329)
Fixes https://github.com/caddyserver/caddy/issues/5171
Diffstat (limited to 'modules/caddyhttp/tracing/module_test.go')
-rw-r--r--modules/caddyhttp/tracing/module_test.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/caddyhttp/tracing/module_test.go b/modules/caddyhttp/tracing/module_test.go
index 0fbc05b..2a775fc 100644
--- a/modules/caddyhttp/tracing/module_test.go
+++ b/modules/caddyhttp/tracing/module_test.go
@@ -98,7 +98,7 @@ func TestTracing_ServeHTTP_Propagation_Without_Initial_Headers(t *testing.T) {
SpanName: "mySpan",
}
- req := httptest.NewRequest("GET", "https://example.com/foo", nil)
+ req := createRequestWithContext("GET", "https://example.com/foo")
w := httptest.NewRecorder()
var handler caddyhttp.HandlerFunc = func(writer http.ResponseWriter, request *http.Request) error {
@@ -128,7 +128,7 @@ func TestTracing_ServeHTTP_Propagation_With_Initial_Headers(t *testing.T) {
SpanName: "mySpan",
}
- req := httptest.NewRequest("GET", "https://example.com/foo", nil)
+ req := createRequestWithContext("GET", "https://example.com/foo")
req.Header.Set("traceparent", "00-11111111111111111111111111111111-1111111111111111-01")
w := httptest.NewRecorder()
@@ -159,7 +159,7 @@ func TestTracing_ServeHTTP_Next_Error(t *testing.T) {
SpanName: "mySpan",
}
- req := httptest.NewRequest("GET", "https://example.com/foo", nil)
+ req := createRequestWithContext("GET", "https://example.com/foo")
w := httptest.NewRecorder()
expectErr := errors.New("test error")
@@ -180,3 +180,11 @@ func TestTracing_ServeHTTP_Next_Error(t *testing.T) {
t.Errorf("expected error, got: %v", err)
}
}
+
+func createRequestWithContext(method string, url string) *http.Request {
+ r, _ := http.NewRequest(method, url, nil)
+ repl := caddy.NewReplacer()
+ ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
+ r = r.WithContext(ctx)
+ return r
+}