Skip to content

Commit 8e76cd7

Browse files
ci(cloud_resource_context): Avoid not indexable mypy errors (#6223)
1 parent d34d61b commit 8e76cd7

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

sentry_sdk/integrations/cloud_resource_context.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def _get_gcp_context(cls) -> "Dict[str, str]":
176176
"cloud.platform": CLOUD_PLATFORM.GCP_COMPUTE_ENGINE,
177177
}
178178

179+
gcp_metadata = cls.gcp_metadata
179180
try:
180181
if cls.gcp_metadata is None:
181182
r = cls.http.request(
@@ -187,30 +188,29 @@ def _get_gcp_context(cls) -> "Dict[str, str]":
187188
if r.status != 200:
188189
return ctx
189190

190-
cls.gcp_metadata = json.loads(r.data.decode("utf-8"))
191+
gcp_metadata = json.loads(r.data.decode("utf-8"))
192+
cls.gcp_metadata = gcp_metadata
191193

192194
try:
193-
ctx["cloud.account.id"] = cls.gcp_metadata["project"]["projectId"]
195+
ctx["cloud.account.id"] = gcp_metadata["project"]["projectId"]
194196
except Exception:
195197
pass
196198

197199
try:
198-
ctx["cloud.availability_zone"] = cls.gcp_metadata["instance"][
199-
"zone"
200-
].split("/")[-1]
200+
ctx["cloud.availability_zone"] = gcp_metadata["instance"]["zone"].split(
201+
"/"
202+
)[-1]
201203
except Exception:
202204
pass
203205

204206
try:
205207
# only populated in google cloud run
206-
ctx["cloud.region"] = cls.gcp_metadata["instance"]["region"].split("/")[
207-
-1
208-
]
208+
ctx["cloud.region"] = gcp_metadata["instance"]["region"].split("/")[-1]
209209
except Exception:
210210
pass
211211

212212
try:
213-
ctx["host.id"] = cls.gcp_metadata["instance"]["id"]
213+
ctx["host.id"] = gcp_metadata["instance"]["id"]
214214
except Exception:
215215
pass
216216

0 commit comments

Comments
 (0)