Repository: open-telemetry/opentelemetry-python

Issue:
Otel Spec forbids B3 propagator from propagating `X-B3-ParentSpanId`
From the [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md#b3-inject)

> MUST NOT propagate X-B3-ParentSpanId as OpenTelemetry does not support reusing the same id for both sides of a request.

But we do it [here](https://github.com/open-telemetry/opentelemetry-python/blob/61c2d6e1508c75cce4b50ff7b28712c944b94128/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py#L152-L158)

This should be removed as the spec forbids it. 


Discussion:
please assign me this issue. Thank you.

Resolving patch:
diff --git a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py
--- a/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py
+++ b/propagator/opentelemetry-propagator-b3/src/opentelemetry/propagators/b3/__init__.py
@@ -40,7 +40,6 @@ class B3MultiFormat(TextMapPropagator):
     SINGLE_HEADER_KEY = "b3"
     TRACE_ID_KEY = "x-b3-traceid"
     SPAN_ID_KEY = "x-b3-spanid"
-    PARENT_SPAN_ID_KEY = "x-b3-parentspanid"
     SAMPLED_KEY = "x-b3-sampled"
     FLAGS_KEY = "x-b3-flags"
     _SAMPLE_PROPAGATE_VALUES = set(["1", "True", "true", "d"])
@@ -149,13 +148,6 @@ def inject(
         setter.set(
             carrier, self.SPAN_ID_KEY, format_span_id(span_context.span_id)
         )
-        span_parent = getattr(span, "parent", None)
-        if span_parent is not None:
-            setter.set(
-                carrier,
-                self.PARENT_SPAN_ID_KEY,
-                format_span_id(span_parent.span_id),
-            )
         setter.set(carrier, self.SAMPLED_KEY, "1" if sampled else "0")
 
     @property
@@ -163,7 +155,6 @@ def fields(self) -> typing.Set[str]:
         return {
             self.TRACE_ID_KEY,
             self.SPAN_ID_KEY,
-            self.PARENT_SPAN_ID_KEY,
             self.SAMPLED_KEY,
         }
 
@@ -195,10 +186,6 @@ def inject(
             "1" if sampled else "0",
         ]
 
-        span_parent = getattr(span, "parent", None)
-        if span_parent:
-            fields.append(format_span_id(span_parent.span_id))
-
         setter.set(carrier, self.SINGLE_HEADER_KEY, "-".join(fields))
 
     @property


Test patch:
diff --git a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py
--- a/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py
+++ b/propagator/opentelemetry-propagator-b3/tests/performance/benchmarks/trace/propagation/test_benchmark_b3_format.py
@@ -22,7 +22,7 @@ def test_extract_single_header(benchmark):
     benchmark(
         FORMAT.extract,
         {
-            FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-c32d953d73ad2251-1-11fd79a30b0896cd285b396ae102dd76"
+            FORMAT.SINGLE_HEADER_KEY: "bdb5b63237ed38aea578af665aa5aa60-c32d953d73ad2251-1"
         },
     )
 
@@ -36,7 +36,6 @@ def test_inject_empty_context(benchmark):
                 {
                     FORMAT.TRACE_ID_KEY: "bdb5b63237ed38aea578af665aa5aa60",
                     FORMAT.SPAN_ID_KEY: "00000000000000000c32d953d73ad225",
-                    FORMAT.PARENT_SPAN_ID_KEY: "11fd79a30b0896cd285b396ae102dd76",
                     FORMAT.SAMPLED_KEY: "1",
                 },
             )
diff --git a/propagator/opentelemetry-propagator-b3/tests/test_b3_format.py b/propagator/opentelemetry-propagator-b3/tests/test_b3_format.py
--- a/propagator/opentelemetry-propagator-b3/tests/test_b3_format.py
+++ b/propagator/opentelemetry-propagator-b3/tests/test_b3_format.py
@@ -65,9 +65,6 @@ def setUpClass(cls):
         cls.serialized_span_id = trace_api.format_span_id(
             generator.generate_span_id()
         )
-        cls.serialized_parent_id = trace_api.format_span_id(
-            generator.generate_span_id()
-        )
 
     def setUp(self) -> None:
         tracer_provider = trace.TracerProvider()
@@ -103,7 +100,6 @@ def test_extract_multi_header(self):
         context = {
             propagator.TRACE_ID_KEY: self.serialized_trace_id,
             propagator.SPAN_ID_KEY: self.serialized_span_id,
-            propagator.PARENT_SPAN_ID_KEY: self.serialized_parent_id,
             propagator.SAMPLED_KEY: "1",
         }
         child, parent, _ = self.get_child_parent_new_carrier(context)
@@ -142,7 +138,7 @@ def test_extract_single_header(self):
 
         child, parent, _ = self.get_child_parent_new_carrier(
             {
-                propagator.SINGLE_HEADER_KEY: f"{self.serialized_trace_id}-{self.serialized_span_id}-1-{self.serialized_parent_id}"
+                propagator.SINGLE_HEADER_KEY: f"{self.serialized_trace_id}-{self.serialized_span_id}-1"
             }
         )