Repository: internetarchive/openlibrary

Issue:
Sentry should include deployment SHA
Sentry has options for specifying the SHA of the current code, so you can see when an error was introduced. We currently don't take advantage of this.

### Describe the problem that you'd like solved
<!-- A clear and concise description of what you want to happen. -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

<!-- Which suggestions or requirements should be considered for how feature needs to appear or be implemented? -->

### Additional context
<!-- Add any other context or screenshots about the feature request here. -->

### Stakeholders
@cdrini 





Discussion:
This might already be happening...
![Screenshot 2020-11-01 at 19 14 56](https://user-images.githubusercontent.com/3709715/97810838-01b11300-1c77-11eb-9e29-d1d416785ee0.png)

Those 12-digit hex server names seem to link to the [12-digit hex host number on the `status` page](http://ol-web1.us.archive.org:8080/status?debug=true).

`ol-web3` events do not seem to be going into Sentry but `ol-web4` and `ol-dev0` events do.
This is the docker container SHA; it'll changer every time the docker container is rebuilt. Not sure why sentry is using that.
ol-web3 is currently not hooked up to sentry to reduce load (in theory now that we know how to set sentry quotas, we might want to try to connect it as well with a quota; but something to do when we're bored :P )

Resolving patch:
diff --git a/openlibrary/plugins/openlibrary/sentry.py b/openlibrary/plugins/openlibrary/sentry.py
--- a/openlibrary/plugins/openlibrary/sentry.py
+++ b/openlibrary/plugins/openlibrary/sentry.py
@@ -5,6 +5,8 @@
 import infogami
 from infogami.utils import delegate
 
+from openlibrary.plugins.openlibrary.status import get_software_version
+
 logger = logging.getLogger("openlibrary.sentry")
 
 
@@ -19,5 +21,6 @@ def setup():
         return
 
     sentry_sdk.init(dsn=infogami.config.sentry.dsn,
-                    environment=infogami.config.sentry.environment)
+                    environment=infogami.config.sentry.environment,
+                    release=get_software_version())
     delegate.add_exception_hook(lambda: sentry_sdk.capture_exception())
diff --git a/openlibrary/plugins/openlibrary/status.py b/openlibrary/plugins/openlibrary/status.py
--- a/openlibrary/plugins/openlibrary/status.py
+++ b/openlibrary/plugins/openlibrary/status.py
@@ -2,8 +2,8 @@
 
 import datetime
 import socket
-import subprocess
 import sys
+from subprocess import PIPE, Popen, STDOUT
 
 from infogami import config
 from infogami.utils import delegate
@@ -25,8 +25,10 @@ def get_git_revision_short_hash():
             if status_info and isinstance(status_info, dict) 
             else None)
 
-def get_software_version():
-    return subprocess.Popen("git rev-parse --short HEAD --".split(), stdout = subprocess.PIPE, stderr = subprocess.STDOUT).stdout.read().strip()
+
+def get_software_version():  # -> str:
+    cmd = "git rev-parse --short HEAD --".split()
+    return str(Popen(cmd, stdout=PIPE, stderr=STDOUT).stdout.read().decode().strip())
 
 def get_features_enabled():
     return config.features
@@ -34,12 +36,9 @@ def get_features_enabled():
 def setup():
     "Basic startup status for the server"
     global status_info, feature_flags
-    version = get_software_version()
-    if bytes != str:  # Python 3
-        version = version.decode("utf-8")
     host = socket.gethostname()
     status_info = {
-        "Software version": version,
+        "Software version": get_software_version(),
         "Python version": sys.version.split()[0],
         "Host": host,
         "Start time": datetime.datetime.utcnow(),


Test patch: