@@ -51,7 +51,7 @@ def sentry_func(*args, **kwargs):
5151
5252 configured_time = int (configured_time )
5353
54- initial_time = datetime .now ()
54+ initial_time = datetime .utcnow ()
5555
5656 with hub .push_scope () as scope :
5757 with capture_internal_exceptions ():
@@ -119,7 +119,7 @@ def _make_request_event_processor(configured_timeout, initial_time):
119119 def event_processor (event , hint ):
120120 # type: (Event, Hint) -> Optional[Event]
121121
122- final_time = datetime .now ()
122+ final_time = datetime .utcnow ()
123123 time_diff = final_time - initial_time
124124
125125 execution_duration_in_millis = time_diff .microseconds / MILLIS_TO_SECONDS
@@ -136,7 +136,7 @@ def event_processor(event, hint):
136136 }
137137
138138 extra ["google cloud logs" ] = {
139- "url" : _get_google_cloud_logs_url (initial_time ),
139+ "url" : _get_google_cloud_logs_url (final_time ),
140140 }
141141
142142 request = event .get ("request" , {})
@@ -150,31 +150,30 @@ def event_processor(event, hint):
150150 return event_processor
151151
152152
153- def _get_google_cloud_logs_url (initial_time ):
153+ def _get_google_cloud_logs_url (final_time ):
154154 # type: (datetime) -> str
155155 """
156156 Generates a Google Cloud Logs console URL based on the environment variables
157157 Arguments:
158- initial_time {datetime} -- Initial time
158+ final_time {datetime} -- Final time
159159 Returns:
160160 str -- Google Cloud Logs Console URL to logs.
161161 """
162- hour_ago = initial_time - timedelta (hours = 1 )
162+ hour_ago = final_time - timedelta (hours = 1 )
163+ formatstring = "%Y-%m-%dT%H:%M:%SZ"
163164
164165 url = (
165166 "https://console.cloud.google.com/logs/viewer?project={project}&resource=cloud_function"
166167 "%2Ffunction_name%2F{function_name}%2Fregion%2F{region}&minLogLevel=0&expandAll=false"
167- "×tamp={initial_time }&customFacets=&limitCustomFacetWidth=true"
168+ "×tamp={timestamp_end }&customFacets=&limitCustomFacetWidth=true"
168169 "&dateRangeStart={timestamp_start}&dateRangeEnd={timestamp_end}"
169- "&interval=PT1H&scrollTimestamp={timestamp_current }"
170+ "&interval=PT1H&scrollTimestamp={timestamp_end }"
170171 ).format (
171172 project = environ .get ("GCP_PROJECT" ),
172173 function_name = environ .get ("FUNCTION_NAME" ),
173174 region = environ .get ("FUNCTION_REGION" ),
174- initial_time = initial_time ,
175- timestamp_start = hour_ago ,
176- timestamp_end = initial_time ,
177- timestamp_current = initial_time ,
175+ timestamp_end = final_time .strftime (formatstring ),
176+ timestamp_start = hour_ago .strftime (formatstring ),
178177 )
179178
180179 return url
0 commit comments