We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Using botocore.Stubber without ResponseMetadata fails
### Which version of dd-trace-py are you using?

0.45.0, but the code is the same on 0.47.0

### Which version of the libraries are you using?

botocore==1.16.15

### How can we reproduce your problem?

Write a test using [Stubber](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/stubber.html#botocore-stub):

```python
import datetime

import ddtrace
ddtrace.patch_all()

import botocore.session
from botocore.stub import Stubber

s3 = botocore.session.get_session().create_client('s3', aws_access_key_id="foo", aws_secret_access_key="bar")

response = {
    "Owner": {
        "ID": "foo",
        "DisplayName": "bar"
    },
    "Buckets": [{
        "CreationDate": datetime.datetime(2016, 1, 20, 22, 9),
        "Name": "baz"
    }]
}

with Stubber(s3) as stubber:
    stubber.add_response('list_buckets', response, {})
    service_response = s3.list_buckets()

assert service_response == response
```

### What is the result that you get?

```
Traceback (most recent call last):
  File "main.py", line 24, in <module>
    service_response = s3.list_buckets()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/ddtrace/contrib/botocore/patch.py", line 166, in patched_api_call
    response_meta = result['ResponseMetadata']
KeyError: 'ResponseMetadata'
```

### What is the result that you expected?

No exceptions.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ddtrace/contrib/botocore/patch.py`
Content:
```
1 """
2 Trace queries to aws api done via botocore client
3 """
4 # 3p
5 import base64
6 import json
7 
8 import botocore.client
9 
10 from ddtrace import config
11 from ddtrace.vendor import wrapt
12 
13 # project
14 from ...constants import ANALYTICS_SAMPLE_RATE_KEY
15 from ...constants import SPAN_MEASURED_KEY
16 from ...ext import SpanTypes
17 from ...ext import aws
18 from ...ext import http
19 from ...internal.logger import get_logger
20 from ...pin import Pin
21 from ...propagation.http import HTTPPropagator
22 from ...utils.formats import deep_getattr
23 from ...utils.formats import get_env
24 from ...utils.wrappers import unwrap
25 
26 
27 # Original botocore client class
28 _Botocore_client = botocore.client.BaseClient
29 
30 ARGS_NAME = ("action", "params", "path", "verb")
31 TRACED_ARGS = ["params", "path", "verb"]
32 
33 log = get_logger(__name__)
34 propagator = HTTPPropagator()
35 
36 # Botocore default settings
37 config._add(
38     "botocore",
39     {
40         "distributed_tracing": get_env("botocore", "distributed_tracing", default=True),
41     },
42 )
43 
44 
45 def inject_trace_data_to_message_attributes(trace_data, entry):
46     if "MessageAttributes" not in entry:
47         entry["MessageAttributes"] = {}
48     # An Amazon SQS message can contain up to 10 metadata attributes.
49     if len(entry["MessageAttributes"]) < 10:
50         entry["MessageAttributes"]["_datadog"] = {"DataType": "String", "StringValue": json.dumps(trace_data)}
51     else:
52         log.debug("skipping trace injection, max number (10) of MessageAttributes exceeded")
53 
54 
55 def inject_trace_to_sqs_batch_message(args, span):
56     trace_data = {}
57     propagator.inject(span.context, trace_data)
58     params = args[1]
59 
60     for entry in params["Entries"]:
61         inject_trace_data_to_message_attributes(trace_data, entry)
62 
63 
64 def inject_trace_to_sqs_message(args, span):
65     trace_data = {}
66     propagator.inject(span.context, trace_data)
67     params = args[1]
68 
69     inject_trace_data_to_message_attributes(trace_data, params)
70 
71 
72 def modify_client_context(client_context_base64, trace_headers):
73     try:
74         client_context_json = base64.b64decode(client_context_base64).decode("utf-8")
75         client_context_object = json.loads(client_context_json)
76 
77         if "custom" in client_context_object:
78             client_context_object["custom"]["_datadog"] = trace_headers
79         else:
80             client_context_object["custom"] = {"_datadog": trace_headers}
81 
82         new_context = base64.b64encode(json.dumps(client_context_object).encode("utf-8")).decode("utf-8")
83         return new_context
84     except Exception:
85         log.warning("malformed client_context=%s", client_context_base64, exc_info=True)
86         return client_context_base64
87 
88 
89 def inject_trace_to_client_context(args, span):
90     trace_headers = {}
91     propagator.inject(span.context, trace_headers)
92 
93     params = args[1]
94     if "ClientContext" in params:
95         params["ClientContext"] = modify_client_context(params["ClientContext"], trace_headers)
96     else:
97         trace_headers = {}
98         propagator.inject(span.context, trace_headers)
99         client_context_object = {"custom": {"_datadog": trace_headers}}
100         json_context = json.dumps(client_context_object).encode("utf-8")
101         params["ClientContext"] = base64.b64encode(json_context).decode("utf-8")
102 
103 
104 def patch():
105     if getattr(botocore.client, "_datadog_patch", False):
106         return
107     setattr(botocore.client, "_datadog_patch", True)
108 
109     wrapt.wrap_function_wrapper("botocore.client", "BaseClient._make_api_call", patched_api_call)
110     Pin(service="aws", app="aws").onto(botocore.client.BaseClient)
111 
112 
113 def unpatch():
114     if getattr(botocore.client, "_datadog_patch", False):
115         setattr(botocore.client, "_datadog_patch", False)
116         unwrap(botocore.client.BaseClient, "_make_api_call")
117 
118 
119 def patched_api_call(original_func, instance, args, kwargs):
120 
121     pin = Pin.get_from(instance)
122     if not pin or not pin.enabled():
123         return original_func(*args, **kwargs)
124 
125     endpoint_name = deep_getattr(instance, "_endpoint._endpoint_prefix")
126 
127     with pin.tracer.trace(
128         "{}.command".format(endpoint_name), service="{}.{}".format(pin.service, endpoint_name), span_type=SpanTypes.HTTP
129     ) as span:
130         span.set_tag(SPAN_MEASURED_KEY)
131         operation = None
132         if args:
133             operation = args[0]
134             span.resource = "%s.%s" % (endpoint_name, operation.lower())
135 
136             if config.botocore["distributed_tracing"]:
137                 if endpoint_name == "lambda" and operation == "Invoke":
138                     inject_trace_to_client_context(args, span)
139                 if endpoint_name == "sqs" and operation == "SendMessage":
140                     inject_trace_to_sqs_message(args, span)
141                 if endpoint_name == "sqs" and operation == "SendMessageBatch":
142                     inject_trace_to_sqs_batch_message(args, span)
143 
144         else:
145             span.resource = endpoint_name
146 
147         aws.add_span_arg_tags(span, endpoint_name, args, ARGS_NAME, TRACED_ARGS)
148 
149         region_name = deep_getattr(instance, "meta.region_name")
150 
151         meta = {
152             "aws.agent": "botocore",
153             "aws.operation": operation,
154             "aws.region": region_name,
155         }
156         span.set_tags(meta)
157 
158         result = original_func(*args, **kwargs)
159 
160         response_meta = result["ResponseMetadata"]
161 
162         if "HTTPStatusCode" in response_meta:
163             span.set_tag(http.STATUS_CODE, response_meta["HTTPStatusCode"])
164 
165         if "RetryAttempts" in response_meta:
166             span.set_tag("retry_attempts", response_meta["RetryAttempts"])
167 
168         if "RequestId" in response_meta:
169             span.set_tag("aws.requestid", response_meta["RequestId"])
170 
171         # set analytics sample rate
172         span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.botocore.get_analytics_sample_rate())
173 
174         return result
175
```
--- 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/ddtrace/contrib/botocore/patch.py b/ddtrace/contrib/botocore/patch.py
--- a/ddtrace/contrib/botocore/patch.py
+++ b/ddtrace/contrib/botocore/patch.py
@@ -157,16 +157,16 @@
 
         result = original_func(*args, **kwargs)
 
-        response_meta = result["ResponseMetadata"]
+        response_meta = result.get("ResponseMetadata")
+        if response_meta:
+            if "HTTPStatusCode" in response_meta:
+                span.set_tag(http.STATUS_CODE, response_meta["HTTPStatusCode"])
 
-        if "HTTPStatusCode" in response_meta:
-            span.set_tag(http.STATUS_CODE, response_meta["HTTPStatusCode"])
+            if "RetryAttempts" in response_meta:
+                span.set_tag("retry_attempts", response_meta["RetryAttempts"])
 
-        if "RetryAttempts" in response_meta:
-            span.set_tag("retry_attempts", response_meta["RetryAttempts"])
-
-        if "RequestId" in response_meta:
-            span.set_tag("aws.requestid", response_meta["RequestId"])
+            if "RequestId" in response_meta:
+                span.set_tag("aws.requestid", response_meta["RequestId"])
 
         # set analytics sample rate
         span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.botocore.get_analytics_sample_rate())

{"golden_diff": "diff --git a/ddtrace/contrib/botocore/patch.py b/ddtrace/contrib/botocore/patch.py\n--- a/ddtrace/contrib/botocore/patch.py\n+++ b/ddtrace/contrib/botocore/patch.py\n@@ -157,16 +157,16 @@\n \n         result = original_func(*args, **kwargs)\n \n-        response_meta = result[\"ResponseMetadata\"]\n+        response_meta = result.get(\"ResponseMetadata\")\n+        if response_meta:\n+            if \"HTTPStatusCode\" in response_meta:\n+                span.set_tag(http.STATUS_CODE, response_meta[\"HTTPStatusCode\"])\n \n-        if \"HTTPStatusCode\" in response_meta:\n-            span.set_tag(http.STATUS_CODE, response_meta[\"HTTPStatusCode\"])\n+            if \"RetryAttempts\" in response_meta:\n+                span.set_tag(\"retry_attempts\", response_meta[\"RetryAttempts\"])\n \n-        if \"RetryAttempts\" in response_meta:\n-            span.set_tag(\"retry_attempts\", response_meta[\"RetryAttempts\"])\n-\n-        if \"RequestId\" in response_meta:\n-            span.set_tag(\"aws.requestid\", response_meta[\"RequestId\"])\n+            if \"RequestId\" in response_meta:\n+                span.set_tag(\"aws.requestid\", response_meta[\"RequestId\"])\n \n         # set analytics sample rate\n         span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.botocore.get_analytics_sample_rate())\n", "issue": "Using botocore.Stubber without ResponseMetadata fails\n### Which version of dd-trace-py are you using?\r\n\r\n0.45.0, but the code is the same on 0.47.0\r\n\r\n### Which version of the libraries are you using?\r\n\r\nbotocore==1.16.15\r\n\r\n### How can we reproduce your problem?\r\n\r\nWrite a test using [Stubber](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/stubber.html#botocore-stub):\r\n\r\n```python\r\nimport datetime\r\n\r\nimport ddtrace\r\nddtrace.patch_all()\r\n\r\nimport botocore.session\r\nfrom botocore.stub import Stubber\r\n\r\ns3 = botocore.session.get_session().create_client('s3', aws_access_key_id=\"foo\", aws_secret_access_key=\"bar\")\r\n\r\nresponse = {\r\n    \"Owner\": {\r\n        \"ID\": \"foo\",\r\n        \"DisplayName\": \"bar\"\r\n    },\r\n    \"Buckets\": [{\r\n        \"CreationDate\": datetime.datetime(2016, 1, 20, 22, 9),\r\n        \"Name\": \"baz\"\r\n    }]\r\n}\r\n\r\nwith Stubber(s3) as stubber:\r\n    stubber.add_response('list_buckets', response, {})\r\n    service_response = s3.list_buckets()\r\n\r\nassert service_response == response\r\n```\r\n\r\n### What is the result that you get?\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"main.py\", line 24, in <module>\r\n    service_response = s3.list_buckets()\r\n  File \"/opt/virtualenvs/python3/lib/python3.8/site-packages/botocore/client.py\", line 357, in _api_call\r\n    return self._make_api_call(operation_name, kwargs)\r\n  File \"/opt/virtualenvs/python3/lib/python3.8/site-packages/ddtrace/contrib/botocore/patch.py\", line 166, in patched_api_call\r\n    response_meta = result['ResponseMetadata']\r\nKeyError: 'ResponseMetadata'\r\n```\r\n\r\n### What is the result that you expected?\r\n\r\nNo exceptions.\n", "before_files": [{"content": "\"\"\"\nTrace queries to aws api done via botocore client\n\"\"\"\n# 3p\nimport base64\nimport json\n\nimport botocore.client\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\n# project\nfrom ...constants import ANALYTICS_SAMPLE_RATE_KEY\nfrom ...constants import SPAN_MEASURED_KEY\nfrom ...ext import SpanTypes\nfrom ...ext import aws\nfrom ...ext import http\nfrom ...internal.logger import get_logger\nfrom ...pin import Pin\nfrom ...propagation.http import HTTPPropagator\nfrom ...utils.formats import deep_getattr\nfrom ...utils.formats import get_env\nfrom ...utils.wrappers import unwrap\n\n\n# Original botocore client class\n_Botocore_client = botocore.client.BaseClient\n\nARGS_NAME = (\"action\", \"params\", \"path\", \"verb\")\nTRACED_ARGS = [\"params\", \"path\", \"verb\"]\n\nlog = get_logger(__name__)\npropagator = HTTPPropagator()\n\n# Botocore default settings\nconfig._add(\n    \"botocore\",\n    {\n        \"distributed_tracing\": get_env(\"botocore\", \"distributed_tracing\", default=True),\n    },\n)\n\n\ndef inject_trace_data_to_message_attributes(trace_data, entry):\n    if \"MessageAttributes\" not in entry:\n        entry[\"MessageAttributes\"] = {}\n    # An Amazon SQS message can contain up to 10 metadata attributes.\n    if len(entry[\"MessageAttributes\"]) < 10:\n        entry[\"MessageAttributes\"][\"_datadog\"] = {\"DataType\": \"String\", \"StringValue\": json.dumps(trace_data)}\n    else:\n        log.debug(\"skipping trace injection, max number (10) of MessageAttributes exceeded\")\n\n\ndef inject_trace_to_sqs_batch_message(args, span):\n    trace_data = {}\n    propagator.inject(span.context, trace_data)\n    params = args[1]\n\n    for entry in params[\"Entries\"]:\n        inject_trace_data_to_message_attributes(trace_data, entry)\n\n\ndef inject_trace_to_sqs_message(args, span):\n    trace_data = {}\n    propagator.inject(span.context, trace_data)\n    params = args[1]\n\n    inject_trace_data_to_message_attributes(trace_data, params)\n\n\ndef modify_client_context(client_context_base64, trace_headers):\n    try:\n        client_context_json = base64.b64decode(client_context_base64).decode(\"utf-8\")\n        client_context_object = json.loads(client_context_json)\n\n        if \"custom\" in client_context_object:\n            client_context_object[\"custom\"][\"_datadog\"] = trace_headers\n        else:\n            client_context_object[\"custom\"] = {\"_datadog\": trace_headers}\n\n        new_context = base64.b64encode(json.dumps(client_context_object).encode(\"utf-8\")).decode(\"utf-8\")\n        return new_context\n    except Exception:\n        log.warning(\"malformed client_context=%s\", client_context_base64, exc_info=True)\n        return client_context_base64\n\n\ndef inject_trace_to_client_context(args, span):\n    trace_headers = {}\n    propagator.inject(span.context, trace_headers)\n\n    params = args[1]\n    if \"ClientContext\" in params:\n        params[\"ClientContext\"] = modify_client_context(params[\"ClientContext\"], trace_headers)\n    else:\n        trace_headers = {}\n        propagator.inject(span.context, trace_headers)\n        client_context_object = {\"custom\": {\"_datadog\": trace_headers}}\n        json_context = json.dumps(client_context_object).encode(\"utf-8\")\n        params[\"ClientContext\"] = base64.b64encode(json_context).decode(\"utf-8\")\n\n\ndef patch():\n    if getattr(botocore.client, \"_datadog_patch\", False):\n        return\n    setattr(botocore.client, \"_datadog_patch\", True)\n\n    wrapt.wrap_function_wrapper(\"botocore.client\", \"BaseClient._make_api_call\", patched_api_call)\n    Pin(service=\"aws\", app=\"aws\").onto(botocore.client.BaseClient)\n\n\ndef unpatch():\n    if getattr(botocore.client, \"_datadog_patch\", False):\n        setattr(botocore.client, \"_datadog_patch\", False)\n        unwrap(botocore.client.BaseClient, \"_make_api_call\")\n\n\ndef patched_api_call(original_func, instance, args, kwargs):\n\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return original_func(*args, **kwargs)\n\n    endpoint_name = deep_getattr(instance, \"_endpoint._endpoint_prefix\")\n\n    with pin.tracer.trace(\n        \"{}.command\".format(endpoint_name), service=\"{}.{}\".format(pin.service, endpoint_name), span_type=SpanTypes.HTTP\n    ) as span:\n        span.set_tag(SPAN_MEASURED_KEY)\n        operation = None\n        if args:\n            operation = args[0]\n            span.resource = \"%s.%s\" % (endpoint_name, operation.lower())\n\n            if config.botocore[\"distributed_tracing\"]:\n                if endpoint_name == \"lambda\" and operation == \"Invoke\":\n                    inject_trace_to_client_context(args, span)\n                if endpoint_name == \"sqs\" and operation == \"SendMessage\":\n                    inject_trace_to_sqs_message(args, span)\n                if endpoint_name == \"sqs\" and operation == \"SendMessageBatch\":\n                    inject_trace_to_sqs_batch_message(args, span)\n\n        else:\n            span.resource = endpoint_name\n\n        aws.add_span_arg_tags(span, endpoint_name, args, ARGS_NAME, TRACED_ARGS)\n\n        region_name = deep_getattr(instance, \"meta.region_name\")\n\n        meta = {\n            \"aws.agent\": \"botocore\",\n            \"aws.operation\": operation,\n            \"aws.region\": region_name,\n        }\n        span.set_tags(meta)\n\n        result = original_func(*args, **kwargs)\n\n        response_meta = result[\"ResponseMetadata\"]\n\n        if \"HTTPStatusCode\" in response_meta:\n            span.set_tag(http.STATUS_CODE, response_meta[\"HTTPStatusCode\"])\n\n        if \"RetryAttempts\" in response_meta:\n            span.set_tag(\"retry_attempts\", response_meta[\"RetryAttempts\"])\n\n        if \"RequestId\" in response_meta:\n            span.set_tag(\"aws.requestid\", response_meta[\"RequestId\"])\n\n        # set analytics sample rate\n        span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.botocore.get_analytics_sample_rate())\n\n        return result\n", "path": "ddtrace/contrib/botocore/patch.py"}], "after_files": [{"content": "\"\"\"\nTrace queries to aws api done via botocore client\n\"\"\"\n# 3p\nimport base64\nimport json\n\nimport botocore.client\n\nfrom ddtrace import config\nfrom ddtrace.vendor import wrapt\n\n# project\nfrom ...constants import ANALYTICS_SAMPLE_RATE_KEY\nfrom ...constants import SPAN_MEASURED_KEY\nfrom ...ext import SpanTypes\nfrom ...ext import aws\nfrom ...ext import http\nfrom ...internal.logger import get_logger\nfrom ...pin import Pin\nfrom ...propagation.http import HTTPPropagator\nfrom ...utils.formats import deep_getattr\nfrom ...utils.formats import get_env\nfrom ...utils.wrappers import unwrap\n\n\n# Original botocore client class\n_Botocore_client = botocore.client.BaseClient\n\nARGS_NAME = (\"action\", \"params\", \"path\", \"verb\")\nTRACED_ARGS = [\"params\", \"path\", \"verb\"]\n\nlog = get_logger(__name__)\npropagator = HTTPPropagator()\n\n# Botocore default settings\nconfig._add(\n    \"botocore\",\n    {\n        \"distributed_tracing\": get_env(\"botocore\", \"distributed_tracing\", default=True),\n    },\n)\n\n\ndef inject_trace_data_to_message_attributes(trace_data, entry):\n    if \"MessageAttributes\" not in entry:\n        entry[\"MessageAttributes\"] = {}\n    # An Amazon SQS message can contain up to 10 metadata attributes.\n    if len(entry[\"MessageAttributes\"]) < 10:\n        entry[\"MessageAttributes\"][\"_datadog\"] = {\"DataType\": \"String\", \"StringValue\": json.dumps(trace_data)}\n    else:\n        log.debug(\"skipping trace injection, max number (10) of MessageAttributes exceeded\")\n\n\ndef inject_trace_to_sqs_batch_message(args, span):\n    trace_data = {}\n    propagator.inject(span.context, trace_data)\n    params = args[1]\n\n    for entry in params[\"Entries\"]:\n        inject_trace_data_to_message_attributes(trace_data, entry)\n\n\ndef inject_trace_to_sqs_message(args, span):\n    trace_data = {}\n    propagator.inject(span.context, trace_data)\n    params = args[1]\n\n    inject_trace_data_to_message_attributes(trace_data, params)\n\n\ndef modify_client_context(client_context_base64, trace_headers):\n    try:\n        client_context_json = base64.b64decode(client_context_base64).decode(\"utf-8\")\n        client_context_object = json.loads(client_context_json)\n\n        if \"custom\" in client_context_object:\n            client_context_object[\"custom\"][\"_datadog\"] = trace_headers\n        else:\n            client_context_object[\"custom\"] = {\"_datadog\": trace_headers}\n\n        new_context = base64.b64encode(json.dumps(client_context_object).encode(\"utf-8\")).decode(\"utf-8\")\n        return new_context\n    except Exception:\n        log.warning(\"malformed client_context=%s\", client_context_base64, exc_info=True)\n        return client_context_base64\n\n\ndef inject_trace_to_client_context(args, span):\n    trace_headers = {}\n    propagator.inject(span.context, trace_headers)\n\n    params = args[1]\n    if \"ClientContext\" in params:\n        params[\"ClientContext\"] = modify_client_context(params[\"ClientContext\"], trace_headers)\n    else:\n        trace_headers = {}\n        propagator.inject(span.context, trace_headers)\n        client_context_object = {\"custom\": {\"_datadog\": trace_headers}}\n        json_context = json.dumps(client_context_object).encode(\"utf-8\")\n        params[\"ClientContext\"] = base64.b64encode(json_context).decode(\"utf-8\")\n\n\ndef patch():\n    if getattr(botocore.client, \"_datadog_patch\", False):\n        return\n    setattr(botocore.client, \"_datadog_patch\", True)\n\n    wrapt.wrap_function_wrapper(\"botocore.client\", \"BaseClient._make_api_call\", patched_api_call)\n    Pin(service=\"aws\", app=\"aws\").onto(botocore.client.BaseClient)\n\n\ndef unpatch():\n    if getattr(botocore.client, \"_datadog_patch\", False):\n        setattr(botocore.client, \"_datadog_patch\", False)\n        unwrap(botocore.client.BaseClient, \"_make_api_call\")\n\n\ndef patched_api_call(original_func, instance, args, kwargs):\n\n    pin = Pin.get_from(instance)\n    if not pin or not pin.enabled():\n        return original_func(*args, **kwargs)\n\n    endpoint_name = deep_getattr(instance, \"_endpoint._endpoint_prefix\")\n\n    with pin.tracer.trace(\n        \"{}.command\".format(endpoint_name), service=\"{}.{}\".format(pin.service, endpoint_name), span_type=SpanTypes.HTTP\n    ) as span:\n        span.set_tag(SPAN_MEASURED_KEY)\n        operation = None\n        if args:\n            operation = args[0]\n            span.resource = \"%s.%s\" % (endpoint_name, operation.lower())\n\n            if config.botocore[\"distributed_tracing\"]:\n                if endpoint_name == \"lambda\" and operation == \"Invoke\":\n                    inject_trace_to_client_context(args, span)\n                if endpoint_name == \"sqs\" and operation == \"SendMessage\":\n                    inject_trace_to_sqs_message(args, span)\n                if endpoint_name == \"sqs\" and operation == \"SendMessageBatch\":\n                    inject_trace_to_sqs_batch_message(args, span)\n\n        else:\n            span.resource = endpoint_name\n\n        aws.add_span_arg_tags(span, endpoint_name, args, ARGS_NAME, TRACED_ARGS)\n\n        region_name = deep_getattr(instance, \"meta.region_name\")\n\n        meta = {\n            \"aws.agent\": \"botocore\",\n            \"aws.operation\": operation,\n            \"aws.region\": region_name,\n        }\n        span.set_tags(meta)\n\n        result = original_func(*args, **kwargs)\n\n        response_meta = result.get(\"ResponseMetadata\")\n        if response_meta:\n            if \"HTTPStatusCode\" in response_meta:\n                span.set_tag(http.STATUS_CODE, response_meta[\"HTTPStatusCode\"])\n\n            if \"RetryAttempts\" in response_meta:\n                span.set_tag(\"retry_attempts\", response_meta[\"RetryAttempts\"])\n\n            if \"RequestId\" in response_meta:\n                span.set_tag(\"aws.requestid\", response_meta[\"RequestId\"])\n\n        # set analytics sample rate\n        span.set_tag(ANALYTICS_SAMPLE_RATE_KEY, config.botocore.get_analytics_sample_rate())\n\n        return result\n", "path": "ddtrace/contrib/botocore/patch.py"}]}