Skip to content

Commit

Permalink
Merge branch 'main' into romain.marcadier/dev-branchg
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller authored Dec 10, 2024
2 parents f9947e8 + a48a41e commit d84693e
Show file tree
Hide file tree
Showing 37 changed files with 387 additions and 128 deletions.
8 changes: 8 additions & 0 deletions contrib/IBM/sarama.v1/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
// kafka supports headers, so try to extract a span context
carrier := NewConsumerMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
next := tracer.StartSpan(cfg.consumerSpanName, opts...)
Expand Down Expand Up @@ -298,6 +302,10 @@ func startProducerSpan(cfg *config, version sarama.KafkaVersion, msg *sarama.Pro
}
// if there's a span context in the headers, use that as the parent
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span := tracer.StartSpan(cfg.producerSpanName, opts...)
Expand Down
8 changes: 8 additions & 0 deletions contrib/Shopify/sarama/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
// kafka supports headers, so try to extract a span context
carrier := NewConsumerMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
next := tracer.StartSpan(cfg.consumerSpanName, opts...)
Expand Down Expand Up @@ -301,6 +305,10 @@ func startProducerSpan(cfg *config, version sarama.KafkaVersion, msg *sarama.Pro
}
// if there's a span context in the headers, use that as the parent
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span := tracer.StartSpan(cfg.producerSpanName, opts...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func TraceReceiveFunc(s Subscription, opts ...Option) func(ctx context.Context,
if cfg.measured {
opts = append(opts, tracer.Measured())
}
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := parentSpanCtx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
span, ctx := tracer.StartSpanFromContext(ctx, cfg.receiveSpanName, opts...)
if msg.DeliveryAttempt != nil {
span.SetTag("delivery_attempt", *msg.DeliveryAttempt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (tr *KafkaTracer) StartConsumeSpan(msg Message) ddtrace.Span {
// kafka supports headers, so try to extract a span context
carrier := MessageCarrier{msg: msg}
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span, _ := tracer.StartSpanFromContext(tr.ctx, tr.consumerSpanName, opts...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (tr *KafkaTracer) StartProduceSpan(msg Message) ddtrace.Span {
// if there's a span context in the headers, use that as the parent
carrier := NewMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span, _ := tracer.StartSpanFromContext(tr.ctx, tr.producerSpanName, opts...)
Expand Down
4 changes: 4 additions & 0 deletions contrib/gofiber/fiber.v2/fiber.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func Middleware(opts ...Option) func(c *fiber.Ctx) error {
}
}
if spanctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(h)); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
opts = append(opts, cfg.spanOpts...)
Expand Down
8 changes: 4 additions & 4 deletions contrib/google.golang.org/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestBooks(t *testing.T) {
assert.Equal(t, "books.bookshelves.list", s0.Tag(ext.ResourceName))
assert.Equal(t, "400", s0.Tag(ext.HTTPCode))
assert.Equal(t, "GET", s0.Tag(ext.HTTPMethod))
assert.Equal(t, svc.BasePath+"books/v1/users/montana.banana/bookshelves?alt=json&prettyPrint=false", s0.Tag(ext.HTTPURL))
assert.Equal(t, svc.BasePath+"books/v1/users/montana.banana/bookshelves", s0.Tag(ext.HTTPURL))
assert.Equal(t, "google.golang.org/api", s0.Tag(ext.Component))
assert.Equal(t, ext.SpanKindClient, s0.Tag(ext.SpanKind))
}
Expand All @@ -88,7 +88,7 @@ func TestCivicInfo(t *testing.T) {
assert.Equal(t, "civicinfo.representatives.representativeInfoByAddress", s0.Tag(ext.ResourceName))
assert.Equal(t, "400", s0.Tag(ext.HTTPCode))
assert.Equal(t, "GET", s0.Tag(ext.HTTPMethod))
assert.Equal(t, svc.BasePath+"civicinfo/v2/representatives?alt=json&prettyPrint=false", s0.Tag(ext.HTTPURL))
assert.Equal(t, svc.BasePath+"civicinfo/v2/representatives", s0.Tag(ext.HTTPURL))
assert.Equal(t, "google.golang.org/api", s0.Tag(ext.Component))
assert.Equal(t, ext.SpanKindClient, s0.Tag(ext.SpanKind))
}
Expand All @@ -115,7 +115,7 @@ func TestURLShortener(t *testing.T) {
assert.Equal(t, "urlshortener.url.list", s0.Tag(ext.ResourceName))
assert.Equal(t, "400", s0.Tag(ext.HTTPCode))
assert.Equal(t, "GET", s0.Tag(ext.HTTPMethod))
assert.Equal(t, "https://www.googleapis.com/urlshortener/v1/url/history?alt=json&prettyPrint=false", s0.Tag(ext.HTTPURL))
assert.Equal(t, "https://www.googleapis.com/urlshortener/v1/url/history", s0.Tag(ext.HTTPURL))
assert.Equal(t, "google.golang.org/api", s0.Tag(ext.Component))
assert.Equal(t, ext.SpanKindClient, s0.Tag(ext.SpanKind))
}
Expand All @@ -140,7 +140,7 @@ func TestWithEndpointMetadataDisabled(t *testing.T) {
assert.Equal(t, "GET civicinfo.googleapis.com", s0.Tag(ext.ResourceName))
assert.Equal(t, "400", s0.Tag(ext.HTTPCode))
assert.Equal(t, "GET", s0.Tag(ext.HTTPMethod))
assert.Equal(t, svc.BasePath+"civicinfo/v2/representatives?alt=json&prettyPrint=false", s0.Tag(ext.HTTPURL))
assert.Equal(t, svc.BasePath+"civicinfo/v2/representatives", s0.Tag(ext.HTTPURL))
assert.Equal(t, "google.golang.org/api", s0.Tag(ext.Component))
assert.Equal(t, ext.SpanKindClient, s0.Tag(ext.SpanKind))
}
Expand Down
4 changes: 4 additions & 0 deletions contrib/google.golang.org/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func startSpanFromContext(
)
md, _ := metadata.FromIncomingContext(ctx) // nil is ok
if sctx, err := tracer.Extract(grpcutil.MDCarrier(md)); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := sctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(sctx))
}
return tracer.StartSpanFromContext(ctx, operation, opts...)
Expand Down
6 changes: 5 additions & 1 deletion contrib/internal/httptrace/httptrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func StartRequestSpan(r *http.Request, opts ...ddtrace.StartSpanOption) (tracer.
cfg.Tags["http.host"] = r.Host
}
if spanctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(r.Header)); err == nil {
cfg.Parent = spanctx
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
tracer.WithSpanLinks(linksCtx.SpanLinks())(cfg)
}
tracer.ChildOf(spanctx)(cfg)
}
for k, v := range ipTags {
cfg.Tags[k] = v
Expand Down
2 changes: 1 addition & 1 deletion contrib/net/http/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func newRoundTripperConfig() *roundTripperConfig {
propagation: true,
spanNamer: defaultSpanNamer,
ignoreRequest: func(_ *http.Request) bool { return false },
queryString: internal.BoolEnv(envClientQueryStringEnabled, true),
queryString: internal.BoolEnv(envClientQueryStringEnabled, false),
isStatusError: isClientError,
}
v := os.Getenv(envClientErrorStatuses)
Expand Down
18 changes: 8 additions & 10 deletions contrib/net/http/roundtripper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,19 +579,19 @@ func TestClientQueryString(t *testing.T) {
client := &http.Client{
Transport: rt,
}
resp, err := client.Get(s.URL + "/hello/world?querystring=xyz")
resp, err := client.Get(s.URL + "/hello/world?API_KEY=1234")
assert.Nil(t, err)
defer resp.Body.Close()
spans := mt.FinishedSpans()
assert.Len(t, spans, 1)

assert.Regexp(t, regexp.MustCompile(`^http://.*?/hello/world\?querystring=xyz$`), spans[0].Tag(ext.HTTPURL))
assert.Regexp(t, regexp.MustCompile(`^http://.*?/hello/world$`), spans[0].Tag(ext.HTTPURL))
})
t.Run("false", func(t *testing.T) {
t.Run("true", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()

os.Setenv("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", "false")
os.Setenv("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", "true")
defer os.Unsetenv("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING")

rt := WrapRoundTripper(http.DefaultTransport)
Expand All @@ -604,29 +604,27 @@ func TestClientQueryString(t *testing.T) {
spans := mt.FinishedSpans()
assert.Len(t, spans, 1)

assert.Regexp(t, regexp.MustCompile(`^http://.*?/hello/world$`), spans[0].Tag(ext.HTTPURL))
assert.Regexp(t, regexp.MustCompile(`^http://.*?/hello/world\?querystring=xyz$`), spans[0].Tag(ext.HTTPURL))
})
// DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED applies only to server spans, not client
t.Run("Not impacted by DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED", func(t *testing.T) {
mt := mocktracer.Start()
defer mt.Stop()

os.Setenv("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", "true")
os.Setenv("DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED", "true")
defer os.Unsetenv("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING")
os.Setenv("DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED", "false")
defer os.Unsetenv("DD_TRACE_HTTP_URL_QUERY_STRING_DISABLED")

rt := WrapRoundTripper(http.DefaultTransport)
client := &http.Client{
Transport: rt,
}
resp, err := client.Get(s.URL + "/hello/world?querystring=xyz")
resp, err := client.Get(s.URL + "/hello/world?API_KEY=1234")
assert.Nil(t, err)
defer resp.Body.Close()
spans := mt.FinishedSpans()
assert.Len(t, spans, 1)

assert.Contains(t, spans[0].Tag(ext.HTTPURL), "/hello/world?querystring=xyz")
assert.Regexp(t, regexp.MustCompile(`^http://.*?/hello/world$`), spans[0].Tag(ext.HTTPURL))
})
}

Expand Down
4 changes: 4 additions & 0 deletions contrib/segmentio/kafka.go.v0/internal/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (tr *Tracer) StartConsumeSpan(ctx context.Context, msg Message) ddtrace.Spa
// kafka supports headers, so try to extract a span context
carrier := NewMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span, _ := tracer.StartSpanFromContext(ctx, tr.consumerSpanName, opts...)
Expand Down
9 changes: 9 additions & 0 deletions contrib/twitchtv/twirp/twirp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"strconv"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
Expand Down Expand Up @@ -90,6 +91,10 @@ func (wc *wrappedClient) Do(req *http.Request) (*http.Response, error) {
opts = append(opts, tracer.Tag(ext.EventSampleRate, wc.cfg.analyticsRate))
}
if spanctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(req.Header)); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}

Expand Down Expand Up @@ -139,6 +144,10 @@ func WrapServer(h http.Handler, opts ...Option) http.Handler {
spanOpts = append(spanOpts, tracer.Tag(ext.EventSampleRate, cfg.analyticsRate))
}
if spanctx, err := tracer.Extract(tracer.HTTPHeadersCarrier(r.Header)); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
spanOpts = append(spanOpts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
spanOpts = append(spanOpts, tracer.ChildOf(spanctx))
}
span, ctx := tracer.StartSpanFromContext(r.Context(), "twirp.handler", spanOpts...)
Expand Down
4 changes: 4 additions & 0 deletions contrib/valyala/fasthttp.v1/fasthttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func WrapHandler(h fasthttp.RequestHandler, opts ...Option) fasthttp.RequestHand
ReqHeader: &fctx.Request.Header,
}
if sctx, err := tracer.Extract(fcc); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := sctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
spanOpts = append(spanOpts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
spanOpts = append(spanOpts, tracer.ChildOf(sctx))
}
span := fasthttptrace.StartSpanFromContext(fctx, "http.request", spanOpts...)
Expand Down
28 changes: 14 additions & 14 deletions ddtrace/tracer/civisibility_tslv_msgp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ddtrace/tracer/civisibility_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (w *ciVisibilityTraceWriter) flush() {
}
log.Error("ciVisibilityTraceWriter: failure sending events (attempt %d), will retry: %v", attempt+1, err)
p.reset()
time.Sleep(time.Millisecond)
time.Sleep(w.config.retryInterval)
}
log.Error("ciVisibilityTraceWriter: lost %d events: %v", count, err)
telemetry.EndpointPayloadDropped(telemetry.TestCycleEndpointType)
Expand Down
Loading

0 comments on commit d84693e

Please sign in to comment.