Search code examples
telemetryopentracingdistributed-tracing

Same spanId of parent and child span in OpenTelemetry (Java)


I am studying OpenTelemetry (Java). I have created a controller. Inside the controller method, I created a span. Then called a method of service class from it. I created another span in the service method. While printing the context of both the spans on console, the traceId of both the spans is same (which should be same) but their spanId is also same. Is this is the default behaviour or I am doing something wrong.


Solution

  • By default, the parent and child spans will have same traceId and spanId. Add any exporters dependency in your "pom.xml" e.g. JaegerExporter or LoggerExporter and then it will work fine i.e. traceId of both spans will be same but spanIds will be unique. It happens because by default TraceFlags{sampled = false} of spans but adding any exporter's dependency makes TraceFlags{sampled = true}.