@@ -51,7 +51,7 @@ def sentry_func(*args, **kwargs):
51
51
52
52
configured_time = int (configured_time )
53
53
54
- initial_time = datetime .now ()
54
+ initial_time = datetime .utcnow ()
55
55
56
56
with hub .push_scope () as scope :
57
57
with capture_internal_exceptions ():
@@ -119,7 +119,7 @@ def _make_request_event_processor(configured_timeout, initial_time):
119
119
def event_processor (event , hint ):
120
120
# type: (Event, Hint) -> Optional[Event]
121
121
122
- final_time = datetime .now ()
122
+ final_time = datetime .utcnow ()
123
123
time_diff = final_time - initial_time
124
124
125
125
execution_duration_in_millis = time_diff .microseconds / MILLIS_TO_SECONDS
@@ -136,7 +136,7 @@ def event_processor(event, hint):
136
136
}
137
137
138
138
extra ["google cloud logs" ] = {
139
- "url" : _get_google_cloud_logs_url (initial_time ),
139
+ "url" : _get_google_cloud_logs_url (final_time ),
140
140
}
141
141
142
142
request = event .get ("request" , {})
@@ -150,31 +150,30 @@ def event_processor(event, hint):
150
150
return event_processor
151
151
152
152
153
- def _get_google_cloud_logs_url (initial_time ):
153
+ def _get_google_cloud_logs_url (final_time ):
154
154
# type: (datetime) -> str
155
155
"""
156
156
Generates a Google Cloud Logs console URL based on the environment variables
157
157
Arguments:
158
- initial_time {datetime} -- Initial time
158
+ final_time {datetime} -- Final time
159
159
Returns:
160
160
str -- Google Cloud Logs Console URL to logs.
161
161
"""
162
- hour_ago = initial_time - timedelta (hours = 1 )
162
+ hour_ago = final_time - timedelta (hours = 1 )
163
+ formatstring = "%Y-%m-%dT%H:%M:%SZ"
163
164
164
165
url = (
165
166
"https://console.cloud.google.com/logs/viewer?project={project}&resource=cloud_function"
166
167
"%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"
168
169
"&dateRangeStart={timestamp_start}&dateRangeEnd={timestamp_end}"
169
- "&interval=PT1H&scrollTimestamp={timestamp_current }"
170
+ "&interval=PT1H&scrollTimestamp={timestamp_end }"
170
171
).format (
171
172
project = environ .get ("GCP_PROJECT" ),
172
173
function_name = environ .get ("FUNCTION_NAME" ),
173
174
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 ),
178
177
)
179
178
180
179
return url
0 commit comments