diff --git a/src/sentry/integrations/vercel/integration.py b/src/sentry/integrations/vercel/integration.py index 22524178255397..5a4fcaf346ecc8 100644 --- a/src/sentry/integrations/vercel/integration.py +++ b/src/sentry/integrations/vercel/integration.py @@ -232,19 +232,45 @@ def update_organization_config(self, data): ) env_var_map = { - "SENTRY_ORG": {"type": "encrypted", "value": sentry_project.organization.slug}, - "SENTRY_PROJECT": {"type": "encrypted", "value": sentry_project.slug}, - dsn_env_name: {"type": "encrypted", "value": sentry_project_dsn}, + "SENTRY_ORG": { + "type": "encrypted", + "value": sentry_project.organization.slug, + "target": ["production", "preview"], + }, + "SENTRY_PROJECT": { + "type": "encrypted", + "value": sentry_project.slug, + "target": ["production", "preview"], + }, + dsn_env_name: { + "type": "encrypted", + "value": sentry_project_dsn, + "target": [ + "production", + "preview", + "development", # The DSN is the only value that makes sense to have available locally via Vercel CLI's `vercel dev` command + ], + }, "SENTRY_AUTH_TOKEN": { "type": "encrypted", "value": sentry_auth_token, + "target": ["production", "preview"], + }, + "VERCEL_GIT_COMMIT_SHA": { + "type": "system", + "value": "VERCEL_GIT_COMMIT_SHA", + "target": ["production", "preview"], }, - "VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"}, } for env_var, details in env_var_map.items(): self.create_env_var( - vercel_client, vercel_project_id, env_var, details["value"], details["type"] + vercel_client, + vercel_project_id, + env_var, + details["value"], + details["type"], + details["target"], ) config.update(data) self.org_integration = integration_service.update_organization_integration( @@ -252,11 +278,11 @@ def update_organization_config(self, data): config=config, ) - def create_env_var(self, client, vercel_project_id, key, value, type): + def create_env_var(self, client, vercel_project_id, key, value, type, target): data = { "key": key, "value": value, - "target": ["production"], + "target": target, "type": type, } try: diff --git a/tests/sentry/integrations/vercel/test_integration.py b/tests/sentry/integrations/vercel/test_integration.py index aa9d600acb2e17..7a0f56132cfcb8 100644 --- a/tests/sentry/integrations/vercel/test_integration.py +++ b/tests/sentry/integrations/vercel/test_integration.py @@ -147,11 +147,35 @@ def test_update_organization_config(self): sentry_auth_token = SentryAppInstallationToken.objects.get_token(org.id, "vercel") env_var_map = { - "SENTRY_ORG": {"type": "encrypted", "value": org.slug}, - "SENTRY_PROJECT": {"type": "encrypted", "value": self.project.slug}, - "SENTRY_DSN": {"type": "encrypted", "value": enabled_dsn}, - "SENTRY_AUTH_TOKEN": {"type": "encrypted", "value": sentry_auth_token}, - "VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"}, + "SENTRY_ORG": { + "type": "encrypted", + "value": org.slug, + "target": ["production", "preview"], + }, + "SENTRY_PROJECT": { + "type": "encrypted", + "value": self.project.slug, + "target": ["production", "preview"], + }, + "SENTRY_DSN": { + "type": "encrypted", + "value": enabled_dsn, + "target": [ + "production", + "preview", + "development", + ], + }, + "SENTRY_AUTH_TOKEN": { + "type": "encrypted", + "value": sentry_auth_token, + "target": ["production", "preview"], + }, + "VERCEL_GIT_COMMIT_SHA": { + "type": "system", + "value": "VERCEL_GIT_COMMIT_SHA", + "target": ["production", "preview"], + }, } # mock get_project API call @@ -169,7 +193,7 @@ def test_update_organization_config(self): json={ "key": env_var, "value": details["value"], - "target": ["production"], + "target": details["target"], "type": details["type"], }, ) @@ -192,30 +216,30 @@ def test_update_organization_config(self): req_params = json.loads(responses.calls[5].request.body) assert req_params["key"] == "SENTRY_ORG" assert req_params["value"] == org.slug - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[6].request.body) assert req_params["key"] == "SENTRY_PROJECT" assert req_params["value"] == self.project.slug - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[7].request.body) assert req_params["key"] == "NEXT_PUBLIC_SENTRY_DSN" assert req_params["value"] == enabled_dsn - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview", "development"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[8].request.body) assert req_params["key"] == "SENTRY_AUTH_TOKEN" - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[9].request.body) assert req_params["key"] == "VERCEL_GIT_COMMIT_SHA" assert req_params["value"] == "VERCEL_GIT_COMMIT_SHA" - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "system" @responses.activate @@ -233,11 +257,35 @@ def test_update_org_config_vars_exist(self): sentry_auth_token = SentryAppInstallationToken.objects.get_token(org.id, "vercel") env_var_map = { - "SENTRY_ORG": {"type": "encrypted", "value": org.slug}, - "SENTRY_PROJECT": {"type": "encrypted", "value": self.project.slug}, - "SENTRY_DSN": {"type": "encrypted", "value": enabled_dsn}, - "SENTRY_AUTH_TOKEN": {"type": "secret", "value": sentry_auth_token}, - "VERCEL_GIT_COMMIT_SHA": {"type": "system", "value": "VERCEL_GIT_COMMIT_SHA"}, + "SENTRY_ORG": { + "type": "encrypted", + "value": org.slug, + "target": ["production", "preview"], + }, + "SENTRY_PROJECT": { + "type": "encrypted", + "value": self.project.slug, + "target": ["production", "preview"], + }, + "SENTRY_DSN": { + "type": "encrypted", + "value": enabled_dsn, + "target": [ + "production", + "preview", + "development", + ], + }, + "SENTRY_AUTH_TOKEN": { + "type": "encrypted", + "value": sentry_auth_token, + "target": ["production", "preview"], + }, + "VERCEL_GIT_COMMIT_SHA": { + "type": "system", + "value": "VERCEL_GIT_COMMIT_SHA", + "target": ["production", "preview"], + }, } # mock get_project API call @@ -270,7 +318,7 @@ def test_update_org_config_vars_exist(self): json={ "key": env_var, "value": details["value"], - "target": ["production"], + "target": details["target"], "type": details["type"], }, ) @@ -292,30 +340,30 @@ def test_update_org_config_vars_exist(self): req_params = json.loads(responses.calls[5].request.body) assert req_params["key"] == "SENTRY_ORG" assert req_params["value"] == org.slug - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[8].request.body) assert req_params["key"] == "SENTRY_PROJECT" assert req_params["value"] == self.project.slug - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[11].request.body) assert req_params["key"] == "SENTRY_DSN" assert req_params["value"] == enabled_dsn - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview", "development"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[14].request.body) assert req_params["key"] == "SENTRY_AUTH_TOKEN" - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "encrypted" req_params = json.loads(responses.calls[17].request.body) assert req_params["key"] == "VERCEL_GIT_COMMIT_SHA" assert req_params["value"] == "VERCEL_GIT_COMMIT_SHA" - assert req_params["target"] == ["production"] + assert req_params["target"] == ["production", "preview"] assert req_params["type"] == "system" @responses.activate