-
Notifications
You must be signed in to change notification settings - Fork 9
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
parametric: remove http_headers from otel start span creation #3478
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,20 +43,3 @@ def test_otel_start_span_with_w3c(self, test_agent, test_library): | |
assert root_span["resource"] == "operation" | ||
assert root_span["meta"]["start_attr_key"] == "start_attr_val" | ||
assert root_span["duration"] == duration_ns | ||
|
||
@irrelevant(context.library == "cpp", reason="library does not implement OpenTelemetry") | ||
def test_otel_span_with_w3c_headers(self, test_agent, test_library): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you review the manifest files? For example there is an entry for "Test_Otel_Span_With_W3c" in python.yml |
||
with test_library: | ||
with test_library.otel_start_span( | ||
name="name", http_headers=[["traceparent", "00-00000000000000001111111111111111-2222222222222222-01"]], | ||
) as span: | ||
context = span.span_context() | ||
assert context.get("trace_flags") == "01" | ||
assert context.get("trace_id") == "00000000000000001111111111111111" | ||
span.end_span() | ||
|
||
span = find_only_span(test_agent.wait_for_num_traces(1)) | ||
assert span.get("trace_id") == 1229782938247303441 | ||
assert span.get("parent_id") == 2459565876494606882 | ||
assert span["metrics"].get(SAMPLING_PRIORITY_KEY) == 1 | ||
assert span["meta"].get(ORIGIN) is None |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ import ( | |
|
||
"go.opentelemetry.io/otel/codes" | ||
otel_trace "go.opentelemetry.io/otel/trace" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace" | ||
ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry" | ||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" | ||
) | ||
|
@@ -59,61 +58,10 @@ func (s *apmClientServer) OtelStartSpan(args OtelStartSpanArgs) (OtelStartSpanRe | |
if a := args.Attributes; len(a) > 0 { | ||
otelOpts = append(otelOpts, otel_trace.WithAttributes(a.ConvertToAttributes()...)) | ||
} | ||
if h := args.HttpHeaders; len(h) > 0 { | ||
headers := map[string]string{} | ||
for _, headerTuple := range h { | ||
k := headerTuple.Key() | ||
v := headerTuple.Value() | ||
if k != "" && v != "" { | ||
headers[k] = v | ||
} | ||
} | ||
sctx, err := tracer.NewPropagator(nil).Extract(tracer.TextMapCarrier(headers)) | ||
if err != nil { | ||
fmt.Println("failed to extract span context from headers:", err, args.HttpHeaders) | ||
} else { | ||
ddOpts = append(ddOpts, tracer.ChildOf(sctx)) | ||
} | ||
} | ||
|
||
if links := args.SpanLinks; links != nil { | ||
for _, link := range links { | ||
if p := link.ParentId; p != 0 { | ||
if _, ok := s.otelSpans[p]; ok { | ||
otelOpts = append(otelOpts, otel_trace.WithLinks(otel_trace.Link{SpanContext: s.otelSpans[p].span.SpanContext(), Attributes: link.Attributes.ConvertToAttributesStringified()})) | ||
} | ||
} else if h := link.HttpHeaders; h != nil { | ||
headers := map[string]string{} | ||
for _, headerTuple := range h { | ||
k := headerTuple.Key() | ||
v := headerTuple.Value() | ||
if k != "" && v != "" { | ||
headers[k] = v | ||
} | ||
} | ||
extractedContext, _ := tracer.NewPropagator(nil).Extract(tracer.TextMapCarrier(headers)) | ||
state, _ := otel_trace.ParseTraceState(headers["tracestate"]) | ||
|
||
var traceID otel_trace.TraceID | ||
var spanID otel_trace.SpanID | ||
if w3cCtx, ok := extractedContext.(ddtrace.SpanContextW3C); ok { | ||
traceID = w3cCtx.TraceID128Bytes() | ||
} else { | ||
fmt.Printf("Non-W3C context found in span, unable to get full 128 bit trace id") | ||
uint64ToByte(extractedContext.TraceID(), traceID[:]) | ||
} | ||
uint64ToByte(extractedContext.SpanID(), spanID[:]) | ||
config := otel_trace.SpanContextConfig{ | ||
TraceID: traceID, | ||
SpanID: spanID, | ||
TraceState: state, | ||
} | ||
var newCtx = otel_trace.NewSpanContext(config) | ||
otelOpts = append(otelOpts, otel_trace.WithLinks(otel_trace.Link{ | ||
SpanContext: newCtx, | ||
Attributes: link.Attributes.ConvertToAttributesStringified(), | ||
})) | ||
} | ||
otelOpts = append(otelOpts, otel_trace.WithLinks(otel_trace.Link{SpanContext: s.otelSpans[link.ParentId].span.SpanContext(), Attributes: link.Attributes.ConvertToAttributesStringified()})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not care about these conditions anymore when adding span links? |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this code useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this span ("dd_root") is linked to the otel span below. In this test I removed the
http_headers
argument from the Links object. Instead I use on the parent_id to generate a span link. This better aligns with the Otel Start Span API.