GoogleCloudPlatform / opentelemetry-operations-java

Apache License 2.0
73 stars 39 forks source link

Trace Exporter sets invalid parent span IDs for root spans #295

Closed WadeGulbrandsen closed 9 months ago

WadeGulbrandsen commented 9 months ago

Root spans should have the parent span ID left empty but Trace Exporter is setting them to 0000000000000000 which is not a valid span ID and shows up in Cloud Trace as (Missing span ID 0000000000000000).

image

I believe the issue is in exporters/trace/src/main/java/com/google/cloud/opentelemetry/trace/TraceTranslator.java

if (spanData.getParentSpanId() != null) {
  spanBuilder.setParentSpanId(spanData.getParentSpanId());
}

Instead of checking to see if the parent span ID is not null the check should be for if the parent context is valid:

if (spanData.getParentSpanContext().isValid()) {
  spanBuilder.setParentSpanId(spanData.getParentSpanId());
}

After making that change to a local copy of the TraceTranslator.java I no longer see the (Missing span ID 0000000000000000) spans and the root span has the parent span ID empty.

image

aabmass commented 9 months ago

Thanks for the report and PR, we will take a look