Skip to content

Commit 9a3c3b9

Browse files
author
Shantanu Dhiman
committed
Changes:
1) Modified local time to utc time in google cloud logs url. 2) Converted log range to include log values from after the completion of execution.
1 parent 1f1a31c commit 9a3c3b9

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

sentry_sdk/integrations/gcp.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +150,7 @@ 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
@@ -159,22 +159,22 @@ def _get_google_cloud_logs_url(initial_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)
163163

164164
url = (
165165
"https://console.cloud.google.com/logs/viewer?project={project}&resource=cloud_function"
166166
"%2Ffunction_name%2F{function_name}%2Fregion%2F{region}&minLogLevel=0&expandAll=false"
167-
"&timestamp={initial_time}&customFacets=&limitCustomFacetWidth=true"
168-
"&dateRangeStart={timestamp_start}&dateRangeEnd={timestamp_end}"
169-
"&interval=PT1H&scrollTimestamp={timestamp_current}"
167+
"&timestamp={initial_time}Z&customFacets=&limitCustomFacetWidth=true"
168+
"&dateRangeStart={timestamp_start}Z&dateRangeEnd={timestamp_end}Z"
169+
"&interval=PT1H&scrollTimestamp={timestamp_current}Z"
170170
).format(
171171
project=environ.get("GCP_PROJECT"),
172172
function_name=environ.get("FUNCTION_NAME"),
173173
region=environ.get("FUNCTION_REGION"),
174-
initial_time=initial_time,
174+
initial_time=final_time,
175175
timestamp_start=hour_ago,
176-
timestamp_end=initial_time,
177-
timestamp_current=initial_time,
176+
timestamp_end=final_time,
177+
timestamp_current=final_time,
178178
)
179179

180180
return url

0 commit comments

Comments
 (0)