Skip to content

Commit

Permalink
Remove header related logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IbraheemA committed Sep 24, 2024
1 parent 8f6fe76 commit be23b26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
14 changes: 4 additions & 10 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func (o *OTLPReceiver) SetOTelAttributeTranslator(attrstrans *attributes.Transla
// ReceiveResourceSpans processes the given rspans and returns the source that it identified from processing them.
func (o *OTLPReceiver) ReceiveResourceSpans(ctx context.Context, rspans ptrace.ResourceSpans, httpHeader http.Header) source.Source {
if o.conf.HasFeature("enable_receive_resource_spans_v2") {
return o.receiveResourceSpansV2(ctx, rspans, httpHeader)
return o.receiveResourceSpansV2(ctx, rspans, httpHeader.Get(header.ComputedStats) != "")
}
return o.receiveResourceSpansV1(ctx, rspans, httpHeader)
}

func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace.ResourceSpans, httpHeader http.Header) source.Source {
func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace.ResourceSpans, clientComputedStats bool) source.Source {
otelres := rspans.Resource()
resourceAttributes := otelres.Attributes()
resourceAttributesMap := make(map[string]string, resourceAttributes.Len())
Expand All @@ -219,13 +219,7 @@ func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace
// TODO(songy23): use AttributeDeploymentEnvironmentName once collector version upgrade is unblocked
env := traceutil.GetOTelAttrVal(resourceAttributes, true, "deployment.environment.name", semconv.AttributeDeploymentEnvironment)
lang := traceutil.GetOTelAttrVal(resourceAttributes, true, semconv.AttributeTelemetrySDKLanguage)
if lang == "" {
lang = fastHeaderGet(httpHeader, header.Lang)
}
containerID := traceutil.GetOTelAttrVal(resourceAttributes, true, semconv.AttributeContainerID, semconv.AttributeK8SPodUID)
if containerID == "" {
containerID = o.cidProvider.GetContainerID(ctx, httpHeader)
}

// 2. Transform OTLP spans to DD spans. If metadata was missing in resource attributes, attempt to get it from spans
topLevelByKind := o.conf.HasFeature("enable_otlp_compute_top_level_by_span_kind")
Expand Down Expand Up @@ -282,8 +276,8 @@ func (o *OTLPReceiver) receiveResourceSpansV2(ctx context.Context, rspans ptrace
_ = o.statsd.Count("datadog.trace_agent.otlp.traces", int64(len(tracesByID)), tags, 1)
p := Payload{
Source: tagstats,
ClientComputedStats: resourceAttributesMap[keyStatsComputed] != "" || httpHeader.Get(header.ComputedStats) != "",
ClientComputedTopLevel: o.conf.HasFeature("enable_otlp_compute_top_level_by_span_kind") || httpHeader.Get(header.ComputedTopLevel) != "",
ClientComputedStats: resourceAttributesMap[keyStatsComputed] != "" || clientComputedStats,
ClientComputedTopLevel: o.conf.HasFeature("enable_otlp_compute_top_level_by_span_kind"),
}
// Get the hostname or set to empty if source is empty
var hostname string
Expand Down
16 changes: 9 additions & 7 deletions pkg/trace/api/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,18 +641,18 @@ func testOTLPReceiveResourceSpans(enableReceiveResourceSpansV2 bool, t *testing.
require.False(p.ClientComputedTopLevel)
}))

t.Run("header", testAndExpect(testSpans, http.Header{
header.ComputedTopLevel: []string{"true"},
}, func(p *Payload) {
require.True(p.ClientComputedTopLevel)
}))

cfg.Features["enable_otlp_compute_top_level_by_span_kind"] = struct{}{}

t.Run("withFeatureFlag", testAndExpect(testSpans, http.Header{}, func(p *Payload) {
require.True(p.ClientComputedTopLevel)
}))

t.Run("header", testAndExpect(testSpans, http.Header{
header.ComputedTopLevel: []string{"true"},
}, func(p *Payload) {
require.True(p.ClientComputedTopLevel)
}))

t.Run("headerWithFeatureFlag", testAndExpect(testSpans, http.Header{
header.ComputedTopLevel: []string{"true"},
}, func(p *Payload) {
Expand Down Expand Up @@ -883,7 +883,9 @@ func testOTLPReceiver(enableReceiveResourceSpansV2 bool, t *testing.T) {
for i := 0; i < 2; i++ {
select {
case p := <-out:
assert.Equal(t, "go", p.Source.Lang)
if !enableReceiveResourceSpansV2 {
assert.Equal(t, "go", p.Source.Lang)
}
assert.Equal(t, "opentelemetry_grpc_v1", p.Source.EndpointVersion)
assert.Len(t, p.TracerPayload.Chunks, 1)
ps[i] = p
Expand Down

0 comments on commit be23b26

Please sign in to comment.