Skip to content

Commit

Permalink
contrib/internal/httpsec: remove option.go & option_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellzy committed Jun 10, 2022
1 parent 1007006 commit 93c31da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 104 deletions.
38 changes: 20 additions & 18 deletions contrib/internal/httptrace/httptrace.go
Expand Up @@ -11,6 +11,7 @@ import (
"context"
"fmt"
"net/http"
"os"
"strconv"
"strings"

Expand All @@ -21,6 +22,24 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

var (
ipv6SpecialNetworks = []*netaddr.IPPrefix{
ippref("fec0::/10"), // site local
}
defaultIPHeaders = []string{
"x-forwarded-for",
"x-real-ip",
"x-client-ip",
"x-forwarded",
"x-cluster-client-ip",
"forwarded-for",
"forwarded",
"via",
"true-client-ip",
}
clientIPHeader = os.Getenv("DD_TRACE_CLIENT_IP_HEADER")
)

// StartRequestSpan starts an HTTP request span with the standard list of HTTP request span tags (http.method, http.url,
// http.useragent). Any further span start option can be added with opts.
func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.Span, context.Context) {
Expand All @@ -37,7 +56,7 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
tracer.Tag("http.host", r.Host),
}, opts...)
}
if ip := getClientIP(r.RemoteAddr, r.Header, cfg.ipHeader); ip.IsValid() {
if ip := getClientIP(r.RemoteAddr, r.Header, clientIPHeader); ip.IsValid() {
opts = append(opts, tracer.Tag(ext.HTTPClientIP, ip.String()))
}
if spanctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(r.Header)); err == nil {
Expand Down Expand Up @@ -70,23 +89,6 @@ func ippref(s string) *netaddr.IPPrefix {
return nil
}

var (
ipv6SpecialNetworks = []*netaddr.IPPrefix{
ippref("fec0::/10"), // site local
}
defaultIPHeaders = []string{
"x-forwarded-for",
"x-real-ip",
"x-client-ip",
"x-forwarded",
"x-cluster-client-ip",
"forwarded-for",
"forwarded",
"via",
"true-client-ip",
}
)

// getClientIP uses the request headers to resolve the client IP. If a specific header to check is provided through
// DD_CLIENT_IP_HEADER, then only this header is checked.
func getClientIP(remoteAddr string, headers http.Header, clientIPHeader string) netaddr.IP {
Expand Down
23 changes: 0 additions & 23 deletions contrib/internal/httptrace/options.go

This file was deleted.

63 changes: 0 additions & 63 deletions contrib/internal/httptrace/options_test.go

This file was deleted.

0 comments on commit 93c31da

Please sign in to comment.