Skip to content

Commit

Permalink
contrib/internal/httptrace: add telemetry for inferred spans (#3119)
Browse files Browse the repository at this point in the history
Co-authored-by: Rodrigo Arguello <[email protected]>
  • Loading branch information
zarirhamza and rarguelloF authored Jan 28, 2025
1 parent 599da51 commit dde97eb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions contrib/internal/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
"context"
"fmt"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/telemetry"
"net/http"
"strconv"
"strings"
"sync"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
Expand All @@ -27,6 +29,8 @@ var (
cfg = newConfig()
)

var reportTelemetryConfigOnce sync.Once

type inferredSpanCreatedCtxKey struct{}

type FinishSpanFunc = func(status int, errorFn func(int) bool, opts ...tracer.FinishOption)
Expand All @@ -37,6 +41,15 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
// Append our span options before the given ones so that the caller can "overwrite" them.
// TODO(): rework span start option handling (https://github.com/DataDog/dd-trace-go/issues/1352)

// we cannot track the configuration in newConfig because it's called during init() and the the telemetry client
// is not initialized yet
reportTelemetryConfigOnce.Do(func() {
telemetry.GlobalClient.ConfigChange([]telemetry.Configuration{
{Name: "inferred_proxy_services_enabled", Value: cfg.inferredProxyServicesEnabled},
})
log.Debug("internal/httptrace: telemetry.ConfigChange called with cfg: %v:", cfg)
})

var ipTags map[string]string
if cfg.traceClientIP {
ipTags, _ = httpsec.ClientIPTags(r.Header, true, r.RemoteAddr)
Expand Down

0 comments on commit dde97eb

Please sign in to comment.