prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Add database_index attribute for redis instrumentation when db is not 0
  Prior discussion [here](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/184#discussion_r528913282).
  
  The spec says for redis if db is not 0 it should have `db.redis.database_index` set to the index of the database being accessed as used in the SELECT command, provided as an integer.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py`
  Content:
  ```
  1 # Copyright The OpenTelemetry Authors
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 #
  15 """
  16 Some utils used by the redis integration
  17 """
  18 
  19 
  20 def _extract_conn_attributes(conn_kwargs):
  21     """ Transform redis conn info into dict """
  22     attributes = {
  23         "db.system": "redis",
  24         "db.name": conn_kwargs.get("db", 0),
  25     }
  26     try:
  27         attributes["net.peer.name"] = conn_kwargs["host"]
  28         attributes["net.peer.ip"] = conn_kwargs["port"]
  29         attributes["net.transport"] = "IP.TCP"
  30     except KeyError:
  31         attributes["net.peer.name"] = conn_kwargs["path"]
  32         attributes["net.transport"] = "Unix"
  33 
  34     return attributes
  35 
  36 
  37 def _format_command_args(args):
  38     """Format command arguments and trim them as needed"""
  39     value_max_len = 100
  40     value_too_long_mark = "..."
  41     cmd_max_len = 1000
  42     length = 0
  43     out = []
  44     for arg in args:
  45         cmd = str(arg)
  46 
  47         if len(cmd) > value_max_len:
  48             cmd = cmd[:value_max_len] + value_too_long_mark
  49 
  50         if length + len(cmd) > cmd_max_len:
  51             prefix = cmd[: cmd_max_len - length]
  52             out.append("%s%s" % (prefix, value_too_long_mark))
  53             break
  54 
  55         out.append(cmd)
  56         length += len(cmd)
  57 
  58     return " ".join(out)
  59
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py
  --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py
  +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py
  @@ -21,8 +21,10 @@
       """ Transform redis conn info into dict """
       attributes = {
           "db.system": "redis",
  -        "db.name": conn_kwargs.get("db", 0),
       }
  +    db = conn_kwargs.get("db", 0)
  +    attributes["db.name"] = db
  +    attributes["db.redis.database_index"] = db
       try:
           attributes["net.peer.name"] = conn_kwargs["host"]
           attributes["net.peer.ip"] = conn_kwargs["port"]
  
verification_info: {"golden_diff": "diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py\n--- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py\n+++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py\n@@ -21,8 +21,10 @@\n     \"\"\" Transform redis conn info into dict \"\"\"\n     attributes = {\n         \"db.system\": \"redis\",\n-        \"db.name\": conn_kwargs.get(\"db\", 0),\n     }\n+    db = conn_kwargs.get(\"db\", 0)\n+    attributes[\"db.name\"] = db\n+    attributes[\"db.redis.database_index\"] = db\n     try:\n         attributes[\"net.peer.name\"] = conn_kwargs[\"host\"]\n         attributes[\"net.peer.ip\"] = conn_kwargs[\"port\"]\n", "issue": "Add database_index attribute for redis instrumentation when db is not 0\nPrior discussion [here](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/184#discussion_r528913282).\r\n\r\nThe spec says for redis if db is not 0 it should have `db.redis.database_index` set to the index of the database being accessed as used in the SELECT command, provided as an integer.\n", "before_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\"\"\"\nSome utils used by the redis integration\n\"\"\"\n\n\ndef _extract_conn_attributes(conn_kwargs):\n    \"\"\" Transform redis conn info into dict \"\"\"\n    attributes = {\n        \"db.system\": \"redis\",\n        \"db.name\": conn_kwargs.get(\"db\", 0),\n    }\n    try:\n        attributes[\"net.peer.name\"] = conn_kwargs[\"host\"]\n        attributes[\"net.peer.ip\"] = conn_kwargs[\"port\"]\n        attributes[\"net.transport\"] = \"IP.TCP\"\n    except KeyError:\n        attributes[\"net.peer.name\"] = conn_kwargs[\"path\"]\n        attributes[\"net.transport\"] = \"Unix\"\n\n    return attributes\n\n\ndef _format_command_args(args):\n    \"\"\"Format command arguments and trim them as needed\"\"\"\n    value_max_len = 100\n    value_too_long_mark = \"...\"\n    cmd_max_len = 1000\n    length = 0\n    out = []\n    for arg in args:\n        cmd = str(arg)\n\n        if len(cmd) > value_max_len:\n            cmd = cmd[:value_max_len] + value_too_long_mark\n\n        if length + len(cmd) > cmd_max_len:\n            prefix = cmd[: cmd_max_len - length]\n            out.append(\"%s%s\" % (prefix, value_too_long_mark))\n            break\n\n        out.append(cmd)\n        length += len(cmd)\n\n    return \" \".join(out)\n", "path": "instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py"}], "after_files": [{"content": "# Copyright The OpenTelemetry Authors\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\"\"\"\nSome utils used by the redis integration\n\"\"\"\n\n\ndef _extract_conn_attributes(conn_kwargs):\n    \"\"\" Transform redis conn info into dict \"\"\"\n    attributes = {\n        \"db.system\": \"redis\",\n    }\n    db = conn_kwargs.get(\"db\", 0)\n    attributes[\"db.name\"] = db\n    attributes[\"db.redis.database_index\"] = db\n    try:\n        attributes[\"net.peer.name\"] = conn_kwargs[\"host\"]\n        attributes[\"net.peer.ip\"] = conn_kwargs[\"port\"]\n        attributes[\"net.transport\"] = \"IP.TCP\"\n    except KeyError:\n        attributes[\"net.peer.name\"] = conn_kwargs[\"path\"]\n        attributes[\"net.transport\"] = \"Unix\"\n\n    return attributes\n\n\ndef _format_command_args(args):\n    \"\"\"Format command arguments and trim them as needed\"\"\"\n    value_max_len = 100\n    value_too_long_mark = \"...\"\n    cmd_max_len = 1000\n    length = 0\n    out = []\n    for arg in args:\n        cmd = str(arg)\n\n        if len(cmd) > value_max_len:\n            cmd = cmd[:value_max_len] + value_too_long_mark\n\n        if length + len(cmd) > cmd_max_len:\n            prefix = cmd[: cmd_max_len - length]\n            out.append(\"%s%s\" % (prefix, value_too_long_mark))\n            break\n\n        out.append(cmd)\n        length += len(cmd)\n\n    return \" \".join(out)\n", "path": "instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py"}]}