We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Breaking change in sync httpx refactor from #1403
elastic/apm-agent-python#1403 refactored a lot of the httpx code. However it seems that the sync version of the instrumentation still calls `self._set_disttracing_headers` which was removed in the same PR, causing any form of sync httpx instrumentation to crash.

**Environment (please complete the following information)**
- Agent version: 6.7.1

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `elasticapm/instrumentation/packages/httpx/sync/httpcore.py`
Content:
```
1 #  BSD 3-Clause License
2 #
3 #  Copyright (c) 2021, Elasticsearch BV
4 #  All rights reserved.
5 #
6 #  Redistribution and use in source and binary forms, with or without
7 #  modification, are permitted provided that the following conditions are met:
8 #
9 #  * Redistributions of source code must retain the above copyright notice, this
10 #    list of conditions and the following disclaimer.
11 #
12 #  * Redistributions in binary form must reproduce the above copyright notice,
13 #    this list of conditions and the following disclaimer in the documentation
14 #    and/or other materials provided with the distribution.
15 #
16 #  * Neither the name of the copyright holder nor the names of its
17 #    contributors may be used to endorse or promote products derived from
18 #    this software without specific prior written permission.
19 #
20 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 #  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 #  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 #  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 #  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 #  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 #  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 #  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 #  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 from elasticapm.instrumentation.packages.base import AbstractInstrumentedModule
32 from elasticapm.instrumentation.packages.httpx import utils
33 from elasticapm.traces import DroppedSpan, capture_span, execution_context
34 from elasticapm.utils import default_ports
35 from elasticapm.utils.disttracing import TracingOptions
36 
37 
38 class HTTPCoreInstrumentation(AbstractInstrumentedModule):
39     name = "httpcore"
40 
41     instrument_list = [
42         ("httpcore._sync.connection", "SyncHTTPConnection.request"),  # < httpcore 0.13
43         ("httpcore._sync.connection", "SyncHTTPConnection.handle_request"),  # >= httpcore 0.13
44         ("httpcore._sync.connection", "HTTPConnection.handle_request"),  # httpcore >= 0.14 (hopefully...)
45     ]
46 
47     def call(self, module, method, wrapped, instance, args, kwargs):
48         url, method, headers = utils.get_request_data(args, kwargs)
49         scheme, host, port, target = url
50         if port != default_ports.get(scheme):
51             host += ":" + str(port)
52 
53         signature = "%s %s" % (method.upper(), host)
54 
55         url = "%s://%s%s" % (scheme, host, target)
56 
57         transaction = execution_context.get_transaction()
58 
59         with capture_span(
60             signature,
61             span_type="external",
62             span_subtype="http",
63             extra={"http": {"url": url}},
64             leaf=True,
65         ) as span:
66             # if httpcore has been called in a leaf span, this span might be a DroppedSpan.
67             leaf_span = span
68             while isinstance(leaf_span, DroppedSpan):
69                 leaf_span = leaf_span.parent
70 
71             if headers is not None:
72                 # It's possible that there are only dropped spans, e.g. if we started dropping spans.
73                 # In this case, the transaction.id is used
74                 parent_id = leaf_span.id if leaf_span else transaction.id
75                 trace_parent = transaction.trace_parent.copy_from(
76                     span_id=parent_id, trace_options=TracingOptions(recorded=True)
77                 )
78                 utils.set_disttracing_headers(headers, trace_parent, transaction)
79                 if leaf_span:
80                     leaf_span.dist_tracing_propagated = True
81             response = wrapped(*args, **kwargs)
82             status_code = utils.get_status(response)
83             if status_code:
84                 if span.context:
85                     span.context["http"]["status_code"] = status_code
86                 span.set_success() if status_code < 400 else span.set_failure()
87             return response
88 
89     def mutate_unsampled_call_args(self, module, method, wrapped, instance, args, kwargs, transaction):
90         # since we don't have a span, we set the span id to the transaction id
91         trace_parent = transaction.trace_parent.copy_from(
92             span_id=transaction.id, trace_options=TracingOptions(recorded=False)
93         )
94         if "headers" in kwargs:
95             headers = kwargs["headers"]
96             if headers is None:
97                 headers = []
98                 kwargs["headers"] = headers
99             self._set_disttracing_headers(headers, trace_parent, transaction)
100         return args, kwargs
101
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/elasticapm/instrumentation/packages/httpx/sync/httpcore.py b/elasticapm/instrumentation/packages/httpx/sync/httpcore.py
--- a/elasticapm/instrumentation/packages/httpx/sync/httpcore.py
+++ b/elasticapm/instrumentation/packages/httpx/sync/httpcore.py
@@ -91,10 +91,6 @@
         trace_parent = transaction.trace_parent.copy_from(
             span_id=transaction.id, trace_options=TracingOptions(recorded=False)
         )
-        if "headers" in kwargs:
-            headers = kwargs["headers"]
-            if headers is None:
-                headers = []
-                kwargs["headers"] = headers
-            self._set_disttracing_headers(headers, trace_parent, transaction)
+        headers = utils.get_request_data(args, kwargs)[2]
+        utils.set_disttracing_headers(headers, trace_parent, transaction)
         return args, kwargs

{"golden_diff": "diff --git a/elasticapm/instrumentation/packages/httpx/sync/httpcore.py b/elasticapm/instrumentation/packages/httpx/sync/httpcore.py\n--- a/elasticapm/instrumentation/packages/httpx/sync/httpcore.py\n+++ b/elasticapm/instrumentation/packages/httpx/sync/httpcore.py\n@@ -91,10 +91,6 @@\n         trace_parent = transaction.trace_parent.copy_from(\n             span_id=transaction.id, trace_options=TracingOptions(recorded=False)\n         )\n-        if \"headers\" in kwargs:\n-            headers = kwargs[\"headers\"]\n-            if headers is None:\n-                headers = []\n-                kwargs[\"headers\"] = headers\n-            self._set_disttracing_headers(headers, trace_parent, transaction)\n+        headers = utils.get_request_data(args, kwargs)[2]\n+        utils.set_disttracing_headers(headers, trace_parent, transaction)\n         return args, kwargs\n", "issue": "Breaking change in sync httpx refactor from #1403\nelastic/apm-agent-python#1403 refactored a lot of the httpx code. However it seems that the sync version of the instrumentation still calls `self._set_disttracing_headers` which was removed in the same PR, causing any form of sync httpx instrumentation to crash.\r\n\r\n**Environment (please complete the following information)**\r\n- Agent version: 6.7.1\n", "before_files": [{"content": "#  BSD 3-Clause License\n#\n#  Copyright (c) 2021, Elasticsearch BV\n#  All rights reserved.\n#\n#  Redistribution and use in source and binary forms, with or without\n#  modification, are permitted provided that the following conditions are met:\n#\n#  * Redistributions of source code must retain the above copyright notice, this\n#    list of conditions and the following disclaimer.\n#\n#  * Redistributions in binary form must reproduce the above copyright notice,\n#    this list of conditions and the following disclaimer in the documentation\n#    and/or other materials provided with the distribution.\n#\n#  * Neither the name of the copyright holder nor the names of its\n#    contributors may be used to endorse or promote products derived from\n#    this software without specific prior written permission.\n#\n#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n#  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n#  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nfrom elasticapm.instrumentation.packages.base import AbstractInstrumentedModule\nfrom elasticapm.instrumentation.packages.httpx import utils\nfrom elasticapm.traces import DroppedSpan, capture_span, execution_context\nfrom elasticapm.utils import default_ports\nfrom elasticapm.utils.disttracing import TracingOptions\n\n\nclass HTTPCoreInstrumentation(AbstractInstrumentedModule):\n    name = \"httpcore\"\n\n    instrument_list = [\n        (\"httpcore._sync.connection\", \"SyncHTTPConnection.request\"),  # < httpcore 0.13\n        (\"httpcore._sync.connection\", \"SyncHTTPConnection.handle_request\"),  # >= httpcore 0.13\n        (\"httpcore._sync.connection\", \"HTTPConnection.handle_request\"),  # httpcore >= 0.14 (hopefully...)\n    ]\n\n    def call(self, module, method, wrapped, instance, args, kwargs):\n        url, method, headers = utils.get_request_data(args, kwargs)\n        scheme, host, port, target = url\n        if port != default_ports.get(scheme):\n            host += \":\" + str(port)\n\n        signature = \"%s %s\" % (method.upper(), host)\n\n        url = \"%s://%s%s\" % (scheme, host, target)\n\n        transaction = execution_context.get_transaction()\n\n        with capture_span(\n            signature,\n            span_type=\"external\",\n            span_subtype=\"http\",\n            extra={\"http\": {\"url\": url}},\n            leaf=True,\n        ) as span:\n            # if httpcore has been called in a leaf span, this span might be a DroppedSpan.\n            leaf_span = span\n            while isinstance(leaf_span, DroppedSpan):\n                leaf_span = leaf_span.parent\n\n            if headers is not None:\n                # It's possible that there are only dropped spans, e.g. if we started dropping spans.\n                # In this case, the transaction.id is used\n                parent_id = leaf_span.id if leaf_span else transaction.id\n                trace_parent = transaction.trace_parent.copy_from(\n                    span_id=parent_id, trace_options=TracingOptions(recorded=True)\n                )\n                utils.set_disttracing_headers(headers, trace_parent, transaction)\n                if leaf_span:\n                    leaf_span.dist_tracing_propagated = True\n            response = wrapped(*args, **kwargs)\n            status_code = utils.get_status(response)\n            if status_code:\n                if span.context:\n                    span.context[\"http\"][\"status_code\"] = status_code\n                span.set_success() if status_code < 400 else span.set_failure()\n            return response\n\n    def mutate_unsampled_call_args(self, module, method, wrapped, instance, args, kwargs, transaction):\n        # since we don't have a span, we set the span id to the transaction id\n        trace_parent = transaction.trace_parent.copy_from(\n            span_id=transaction.id, trace_options=TracingOptions(recorded=False)\n        )\n        if \"headers\" in kwargs:\n            headers = kwargs[\"headers\"]\n            if headers is None:\n                headers = []\n                kwargs[\"headers\"] = headers\n            self._set_disttracing_headers(headers, trace_parent, transaction)\n        return args, kwargs\n", "path": "elasticapm/instrumentation/packages/httpx/sync/httpcore.py"}], "after_files": [{"content": "#  BSD 3-Clause License\n#\n#  Copyright (c) 2021, Elasticsearch BV\n#  All rights reserved.\n#\n#  Redistribution and use in source and binary forms, with or without\n#  modification, are permitted provided that the following conditions are met:\n#\n#  * Redistributions of source code must retain the above copyright notice, this\n#    list of conditions and the following disclaimer.\n#\n#  * Redistributions in binary form must reproduce the above copyright notice,\n#    this list of conditions and the following disclaimer in the documentation\n#    and/or other materials provided with the distribution.\n#\n#  * Neither the name of the copyright holder nor the names of its\n#    contributors may be used to endorse or promote products derived from\n#    this software without specific prior written permission.\n#\n#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n#  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n#  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\nfrom elasticapm.instrumentation.packages.base import AbstractInstrumentedModule\nfrom elasticapm.instrumentation.packages.httpx import utils\nfrom elasticapm.traces import DroppedSpan, capture_span, execution_context\nfrom elasticapm.utils import default_ports\nfrom elasticapm.utils.disttracing import TracingOptions\n\n\nclass HTTPCoreInstrumentation(AbstractInstrumentedModule):\n    name = \"httpcore\"\n\n    instrument_list = [\n        (\"httpcore._sync.connection\", \"SyncHTTPConnection.request\"),  # < httpcore 0.13\n        (\"httpcore._sync.connection\", \"SyncHTTPConnection.handle_request\"),  # >= httpcore 0.13\n        (\"httpcore._sync.connection\", \"HTTPConnection.handle_request\"),  # httpcore >= 0.14 (hopefully...)\n    ]\n\n    def call(self, module, method, wrapped, instance, args, kwargs):\n        url, method, headers = utils.get_request_data(args, kwargs)\n        scheme, host, port, target = url\n        if port != default_ports.get(scheme):\n            host += \":\" + str(port)\n\n        signature = \"%s %s\" % (method.upper(), host)\n\n        url = \"%s://%s%s\" % (scheme, host, target)\n\n        transaction = execution_context.get_transaction()\n\n        with capture_span(\n            signature,\n            span_type=\"external\",\n            span_subtype=\"http\",\n            extra={\"http\": {\"url\": url}},\n            leaf=True,\n        ) as span:\n            # if httpcore has been called in a leaf span, this span might be a DroppedSpan.\n            leaf_span = span\n            while isinstance(leaf_span, DroppedSpan):\n                leaf_span = leaf_span.parent\n\n            if headers is not None:\n                # It's possible that there are only dropped spans, e.g. if we started dropping spans.\n                # In this case, the transaction.id is used\n                parent_id = leaf_span.id if leaf_span else transaction.id\n                trace_parent = transaction.trace_parent.copy_from(\n                    span_id=parent_id, trace_options=TracingOptions(recorded=True)\n                )\n                utils.set_disttracing_headers(headers, trace_parent, transaction)\n                if leaf_span:\n                    leaf_span.dist_tracing_propagated = True\n            response = wrapped(*args, **kwargs)\n            status_code = utils.get_status(response)\n            if status_code:\n                if span.context:\n                    span.context[\"http\"][\"status_code\"] = status_code\n                span.set_success() if status_code < 400 else span.set_failure()\n            return response\n\n    def mutate_unsampled_call_args(self, module, method, wrapped, instance, args, kwargs, transaction):\n        # since we don't have a span, we set the span id to the transaction id\n        trace_parent = transaction.trace_parent.copy_from(\n            span_id=transaction.id, trace_options=TracingOptions(recorded=False)\n        )\n        headers = utils.get_request_data(args, kwargs)[2]\n        utils.set_disttracing_headers(headers, trace_parent, transaction)\n        return args, kwargs\n", "path": "elasticapm/instrumentation/packages/httpx/sync/httpcore.py"}]}