33import logging
44
55from django .http import HttpResponse
6- from rest_framework .request import Request
76
8- from sentry import analytics
97from sentry .api .api_owners import ApiOwner
108from sentry .api .api_publish_status import ApiPublishStatus
119from sentry .api .base import region_silo_endpoint
1210from sentry .api .bases .project import ProjectEndpoint
1311from sentry .models .project import Project
1412from sentry .objectstore import preprod
1513from sentry .objectstore .service import ClientError
16- from sentry .preprod .analytics import PreprodArtifactApiImageEvent
1714
1815logger = logging .getLogger (__name__ )
1916
@@ -62,58 +59,29 @@ class ProjectPreprodArtifactImageEndpoint(ProjectEndpoint):
6259
6360 def get (
6461 self ,
65- request : Request ,
6662 project : Project ,
6763 image_id : str ,
6864 ) -> HttpResponse :
6965
70- analytics .record (
71- PreprodArtifactApiImageEvent (
72- organization_id = project .organization_id ,
73- project_id = project .id ,
74- user_id = request .user .id ,
75- image_id = image_id ,
76- )
77- )
78-
7966 organization_id = project .organization_id
8067 project_id = project .id
8168
8269 object_key = f"{ organization_id } /{ project_id } /{ image_id } "
83- logger .info (
84- "Retrieving image from objectstore" ,
85- extra = {
86- "organization_id" : organization_id ,
87- "project_id" : project_id ,
88- "image_id" : image_id ,
89- },
90- )
9170 client = preprod .for_project (organization_id , project_id )
9271
9372 try :
9473 result = client .get (object_key )
95- # Read the entire stream at once
74+ # Read the entire stream at once (necessary for content_type)
9675 image_data = result .payload .read ()
9776
9877 # Detect content type from the image data
9978 content_type = detect_image_content_type (image_data )
100-
101- logger .info (
102- "Retrieved image from objectstore" ,
103- extra = {
104- "organization_id" : organization_id ,
105- "project_id" : project_id ,
106- "image_id" : image_id ,
107- "size_bytes" : len (image_data ),
108- "content_type" : content_type ,
109- },
110- )
11179 return HttpResponse (image_data , content_type = content_type )
11280
11381 except ClientError as e :
11482 if e .status == 404 :
11583 logger .warning (
116- "App icon not found in objectstore" ,
84+ "Image not found in objectstore" ,
11785 extra = {
11886 "organization_id" : organization_id ,
11987 "project_id" : project_id ,
@@ -125,7 +93,7 @@ def get(
12593 return HttpResponse ({"error" : "Not found" }, status = 404 )
12694
12795 logger .warning (
128- "Failed to retrieve app icon from objectstore" ,
96+ "Failed to retrieve image from objectstore" ,
12997 extra = {
13098 "organization_id" : organization_id ,
13199 "project_id" : project_id ,
@@ -134,11 +102,11 @@ def get(
134102 "status" : e .status ,
135103 },
136104 )
137- return HttpResponse ({"error" : "Failed to retrieve app icon " }, status = 500 )
105+ return HttpResponse ({"error" : "Failed to retrieve image " }, status = 500 )
138106
139107 except Exception :
140108 logger .exception (
141- "Unexpected error retrieving app icon " ,
109+ "Unexpected error retrieving image " ,
142110 extra = {
143111 "organization_id" : organization_id ,
144112 "project_id" : project_id ,
0 commit comments