-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include service name and version in User-Agent #1196
Conversation
Change NewHTTPTransport to take HTTPTransportOptions instead, now that we can break the API. Use env vars as defaults only if values are not explicitly specified in the options, aligning with behaviour of apm.NewTracerOptions.
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! small question, but that's all.
Co-authored-by: Marc Lopez Rubio <[email protected]>
... and drop the finer-grained fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taking that back 😅 this is good to go once the tls config options get rolled into a *tls.Config
@stuartnelson3 merging as I think you concluded that all necessary changes were already made. Let me know if I misinterpreted. |
Tested with the latest package main
import (
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"go.elastic.co/apm/v2"
"go.elastic.co/apm/v2/transport"
)
func main() {
dumpHandler := func(m string) http.HandlerFunc {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
io.Copy(io.Discard, r.Body)
fmt.Println(m, "\t", "URL:", r.URL.Path, "User-Agent:", r.Header.Get("User-Agent"))
rw.WriteHeader(202)
})
}
s := http.Server{
Addr: "localhost:8200",
Handler: dumpHandler("default"),
}
defer s.Close()
go s.ListenAndServe()
srv := httptest.NewServer(dumpHandler("custom "))
defer srv.Close()
u, err := url.Parse(srv.URL)
panicOnErr(err)
t, err := transport.NewHTTPTransport(transport.HTTPTransportOptions{
ServerURLs: []*url.URL{u},
})
panicOnErr(err)
tracer, err := apm.NewTracerOptions(apm.TracerOptions{
ServiceName: "marc-test",
ServiceVersion: "5.1.3",
Transport: t,
})
genTraces(tracer)
genTraces(apm.DefaultTracer())
tracer.Flush(nil)
apm.DefaultTracer().Flush(nil)
tracer.Close()
apm.DefaultTracer().Close()
}
func panicOnErr(err error) {
if err != nil {
panic(err)
}
}
func genTraces(tracer *apm.Tracer) {
tx := tracer.StartTransaction("tx", "type")
tx.StartSpan("span", "type", nil).End()
tx.End()
} yields: $ export ELASTIC_APM_SERVICE_NAME=marc-test
$ export ELASTIC_APM_SERVICE_VERSION="5.3.1"
$ go run main.go
custom URL: /config/v1/agents User-Agent: apm-agent-go/2.0.0
default URL: /config/v1/agents User-Agent: apm-agent-go/2.0.0 (marc-test 5.3.1)
custom URL: /intake/v2/events User-Agent: apm-agent-go/2.0.0
default URL: /intake/v2/events User-Agent: apm-agent-go/2.0.0 (marc-test 5.3.1) |
UserAgent needs to be set in HTTPTransportOptions: apm-agent-go/transport/http.go Lines 129 to 133 in 640a916
Maybe not the most user-friendly. Any thoughts on how to improve that? |
ah I didn't read the UserAgent comment, it was unexpected to me since thought it should've also extended the UserAgent when not explicitly set and the tracer, err := apm.NewTracerOptions(apm.TracerOptions{
Transport: t,
}) // Yields UserAgent = `apm-agent-go/2.0.0`
tracer, err := apm.NewTracerOptions(apm.TracerOptions{
ServiceName: "marc-test",
ServiceVersion: "5.1.3",
Transport: t,
}) // Yields UserAgent = `apm-agent-go/2.0.0 (marc-test 5.3.1)`
tracer, err := apm.NewTracerOptions(apm.TracerOptions{
ServiceName: "marc-test",
ServiceVersion: "5.1.3",
Transport: t,
UserAgent: "custom-user-agent"
}) // Yields UserAgent = `custom-user-agent` It isn't a regression then since the mechanics are clearly defined in the godocs. |
Maybe we can improve this later, e.g. by adding a |
Update User-Agent to match the agent spec, including service name and service version if it is specified. User-Agent no longer includes the Go runtime version, but this is still available in
service.runtime.version
.The
transport.NewHTTPTransportOptions
function is removed, andtransport.NewHTTPTransport
is updated to take HTTPTransportOptions instead now that we can break the API. Use env vars as defaults only if values are not specified in the options struct, aligning with behaviour ofapm.NewTracerOptions
.Update to the latest shared agents Gherkin spec.
Closes #1136