From 2190a11a0d62e3b4aee87ad861e80f8cad237cbc Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 19 Aug 2021 20:42:15 +0100 Subject: [PATCH 1/8] apmhttp WithClientSpanType ClientOption --- module/apmhttp/client.go | 10 +++++++++- module/apmhttp/client_test.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/module/apmhttp/client.go b/module/apmhttp/client.go index f48ca4877..a097a62e2 100644 --- a/module/apmhttp/client.go +++ b/module/apmhttp/client.go @@ -59,6 +59,7 @@ func WrapRoundTripper(r http.RoundTripper, o ...ClientOption) http.RoundTripper r: r, requestName: ClientRequestName, requestIgnorer: IgnoreNone, + spanType: "external.http", } for _, o := range o { o(rt) @@ -71,6 +72,7 @@ type roundTripper struct { requestName RequestNameFunc requestIgnorer RequestIgnorerFunc traceRequests bool + spanType string } // RoundTrip delegates to r.r, emitting a span if req's context @@ -102,7 +104,7 @@ func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { } name := r.requestName(req) - span := tx.StartSpan(name, "external.http", apm.SpanFromContext(ctx)) + span := tx.StartSpan(name, r.spanType, apm.SpanFromContext(ctx)) var rt *requestTracer if !span.Dropped() { traceContext = span.TraceContext() @@ -211,3 +213,9 @@ func WithClientRequestName(r RequestNameFunc) ClientOption { rt.requestName = r }) } + +func WithClientSpanType(spanType string) ClientOption { + return ClientOption(func(rt *roundTripper) { + rt.spanType = spanType + }) +} diff --git a/module/apmhttp/client_test.go b/module/apmhttp/client_test.go index ae77d5611..2a5f6d682 100644 --- a/module/apmhttp/client_test.go +++ b/module/apmhttp/client_test.go @@ -354,6 +354,22 @@ func TestClientOutcome(t *testing.T) { assert.Equal(t, "failure", spans[2].Outcome) } +func TestWithClientSpanType(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusTeapot) + })) + defer server.Close() + + option := apmhttp.WithClientSpanType("cache") + _, spans, _ := apmtest.WithTransaction(func(ctx context.Context) { + mustGET(ctx, server.URL, option) + }) + + require.Len(t, spans, 1) + span := spans[0] + assert.Equal(t, "cache", span.Type) +} + func mustGET(ctx context.Context, url string, o ...apmhttp.ClientOption) (statusCode int, responseBody string) { client := apmhttp.WrapClient(http.DefaultClient, o...) resp, err := ctxhttp.Get(ctx, client, url) From a0c89a6b0bbcb0d5a0f5f1d3aee19d367e08bf26 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 24 Aug 2021 18:40:48 +0100 Subject: [PATCH 2/8] Update module/apmhttp/client.go Co-authored-by: Andrew Wilkins --- module/apmhttp/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/apmhttp/client.go b/module/apmhttp/client.go index a097a62e2..e629e7d4f 100644 --- a/module/apmhttp/client.go +++ b/module/apmhttp/client.go @@ -214,6 +214,9 @@ func WithClientRequestName(r RequestNameFunc) ClientOption { }) } +// WithClientSpanType sets the span type for HTTP client requests. +// +// Defaults to "external.http". func WithClientSpanType(spanType string) ClientOption { return ClientOption(func(rt *roundTripper) { rt.spanType = spanType From 8cab26151693005cab56248dedb2269fff028026 Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 24 Aug 2021 18:46:09 +0100 Subject: [PATCH 3/8] Update CHANGELOG.asciidoc --- CHANGELOG.asciidoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 10def8396..5e979a4d2 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,12 @@ https://github.com/elastic/apm-agent-go/compare/v1.13.1...master[View commits] [[release-notes-1.x]] === Go Agent version 1.x +[[release-notes-1.13.1]] +==== 1.14.0 - 2021/08/24 + +- module/apmhttp: add apmhttp.WithClientSpanType ClientOption to set the span type of http client requests {pull}1106[#(1106)] + + [[release-notes-1.13.1]] ==== 1.13.1 - 2021/08/05 From e4c028372ac95172f27344fa0be162f97069374a Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 24 Aug 2021 18:51:50 +0100 Subject: [PATCH 4/8] Update CHANGELOG.asciidoc --- CHANGELOG.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5e979a4d2..8d929be1a 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -21,7 +21,7 @@ endif::[] [[unreleased]] === Unreleased -https://github.com/elastic/apm-agent-go/compare/v1.13.1...master[View commits] +https://github.com/elastic/apm-agent-go/compare/v1.14.0...master[View commits] [[release-notes-1.x]] === Go Agent version 1.x From 2651fdf0fa32c5179adf153fbdcfa175bb5a578f Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 24 Aug 2021 18:52:15 +0100 Subject: [PATCH 5/8] Update CHANGELOG.asciidoc --- CHANGELOG.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8d929be1a..d48832676 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,7 +26,7 @@ https://github.com/elastic/apm-agent-go/compare/v1.14.0...master[View commits] [[release-notes-1.x]] === Go Agent version 1.x -[[release-notes-1.13.1]] +[[release-notes-1.14.0]] ==== 1.14.0 - 2021/08/24 - module/apmhttp: add apmhttp.WithClientSpanType ClientOption to set the span type of http client requests {pull}1106[#(1106)] From 8a6221b4112e02202e24435730af7bded6433387 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 25 Aug 2021 20:11:55 +0100 Subject: [PATCH 6/8] Update CHANGELOG.asciidoc Co-authored-by: Andrew Wilkins --- CHANGELOG.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index d48832676..c0fb4934d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -21,7 +21,7 @@ endif::[] [[unreleased]] === Unreleased -https://github.com/elastic/apm-agent-go/compare/v1.14.0...master[View commits] +- module/apmhttp: add apmhttp.WithClientSpanType ClientOption to set the span type of http client requests {pull}1106[#(1106)] [[release-notes-1.x]] === Go Agent version 1.x From 019b4c743f35c582f2e1e3137716830bb1c4f2da Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 25 Aug 2021 20:12:11 +0100 Subject: [PATCH 7/8] Update CHANGELOG.asciidoc Co-authored-by: Andrew Wilkins --- CHANGELOG.asciidoc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index c0fb4934d..1bf9f7a67 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,12 +26,6 @@ endif::[] [[release-notes-1.x]] === Go Agent version 1.x -[[release-notes-1.14.0]] -==== 1.14.0 - 2021/08/24 - -- module/apmhttp: add apmhttp.WithClientSpanType ClientOption to set the span type of http client requests {pull}1106[#(1106)] - - [[release-notes-1.13.1]] ==== 1.13.1 - 2021/08/05 From 4545713a98c375eda6a79897b2c417c926fba221 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Thu, 26 Aug 2021 08:41:37 +0800 Subject: [PATCH 8/8] Add unreleased line back --- CHANGELOG.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 1bf9f7a67..bad2f25eb 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -21,6 +21,8 @@ endif::[] [[unreleased]] === Unreleased +https://github.com/elastic/apm-agent-go/compare/v1.13.1...master[View commits] + - module/apmhttp: add apmhttp.WithClientSpanType ClientOption to set the span type of http client requests {pull}1106[#(1106)] [[release-notes-1.x]]