Skip to content
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

contrib/envoyproxy: fix resource name #3047

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions contrib/envoyproxy/go-control-plane/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"math"
"net/http"
"path"
"strings"

"gopkg.in/DataDog/dd-trace-go.v1/contrib/internal/httptrace"
Expand Down Expand Up @@ -204,6 +205,7 @@ func processRequestHeaders(ctx context.Context, req *envoyextproc.ProcessingRequ
var blocked bool
fakeResponseWriter := newFakeResponseWriter()
wrappedResponseWriter, request, afterHandle, blocked := httptrace.BeforeHandle(&httptrace.ServeConfig{
Resource: request.Method + " " + path.Clean(request.URL.Path),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we path.Clean here? shouldn't we just put the original data that was in the request?

also something we are trying to do in other http server integrations is to use the low cardinality http.route (see details here) for the resource name. Would it be possible to have this here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a path.Clean here like it's done in the mux.Handler() to get the route. And in the handler, it's calling cleanPath() which is doing a path.Clean

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we don't have the http.route information at the proxy level. Only the raw path is available.

SpanOpts: []ddtrace.StartSpanOption{
tracer.Tag(ext.SpanKind, ext.SpanKindServer),
tracer.Tag(ext.Component, componentName),
Expand Down
6 changes: 3 additions & 3 deletions contrib/envoyproxy/go-control-plane/envoy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestGeneratedSpan(t *testing.T) {
stream, err := client.Process(ctx)
require.NoError(t, err)

end2EndStreamRequest(t, stream, "/resource-span", "GET", map[string]string{"user-agent": "Mistake Not...", "test-key": "test-value"}, map[string]string{"response-test-key": "response-test-value"}, false)
end2EndStreamRequest(t, stream, "/../../../resource-span/.?id=test", "GET", map[string]string{"user-agent": "Mistake Not...", "test-key": "test-value"}, map[string]string{"response-test-key": "response-test-value"}, false)

err = stream.CloseSend()
require.NoError(t, err)
Expand All @@ -266,10 +266,10 @@ func TestGeneratedSpan(t *testing.T) {
// Check for tags
span := finished[0]
require.Equal(t, "http.request", span.OperationName())
require.Equal(t, "https://datadoghq.com/resource-span", span.Tag("http.url"))
require.Equal(t, "https://datadoghq.com/../../../resource-span/.?id=test", span.Tag("http.url"))
require.Equal(t, "GET", span.Tag("http.method"))
require.Equal(t, "datadoghq.com", span.Tag("http.host"))
// require.Equal(t, "GET /resource-span", span.Tag("resource.name"))
require.Equal(t, "GET /resource-span", span.Tag("resource.name"))
require.Equal(t, "server", span.Tag("span.kind"))
require.Equal(t, "Mistake Not...", span.Tag("http.useragent"))
})
Expand Down
Loading