Skip to content

Commit a209bd0

Browse files
authored
feat(projectkey): Add integration endpoint to dsn serializer (#102134)
Alright final try at #102083 and #101999. We expose the integration endpoint in the project key serializer. API consumers can build the integrations (similar to how the `build_integration_endpoint` method works) for all the integration's that we'll be exposing in Relay. We might eventually remove the `otlp_traces_endpoint` and `otlp_logs_endpoint`, but we can explore that afterwards.
1 parent f5db248 commit a209bd0

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/sentry/api/serializers/models/project_key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class DSN(TypedDict):
2828
crons: str
2929
cdn: str
3030
playstation: str
31+
integration: str
3132
otlp_traces: str
3233
otlp_logs: str
3334

@@ -98,6 +99,7 @@ def serialize(
9899
"crons": obj.crons_endpoint,
99100
"cdn": obj.js_sdk_loader_cdn_url,
100101
"playstation": obj.playstation_endpoint,
102+
"integration": obj.integration_endpoint,
101103
"otlp_traces": obj.otlp_traces_endpoint,
102104
"otlp_logs": obj.otlp_logs_endpoint,
103105
},

src/sentry/apidocs/examples/project_examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"security": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/security/?sentry_key=a785682ddda719b7a8a4011110d75598",
1919
"minidump": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/minidump/?sentry_key=a785682ddda719b7a8a4011110d75598",
2020
"playstation": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/playstation/?sentry_key=a785682ddda719b7a8a4011110d75598",
21+
"integration": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/integration/",
2122
"otlp_traces": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/integration/otlp/v1/traces",
2223
"otlp_logs": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/integration/otlp/v1/logs",
2324
"nel": "https://o4504765715316736.ingest.sentry.io/api/4505281256090153/nel/?sentry_key=a785682ddda719b7a8a4011110d75598",

src/sentry/models/projectkey.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,20 @@ def playstation_endpoint(self):
266266
return f"{endpoint}/api/{self.project_id}/playstation/?sentry_key={self.public_key}"
267267

268268
@property
269-
def otlp_traces_endpoint(self):
269+
def integration_endpoint(self):
270270
endpoint = self.get_endpoint()
271+
return f"{endpoint}/api/{self.project_id}/integration/"
271272

272-
return f"{endpoint}/api/{self.project_id}/integration/otlp/v1/traces"
273+
def build_integration_endpoint(self, integration_name: str, postfix: str = "") -> str:
274+
return f"{self.integration_endpoint}{integration_name}/{postfix}"
273275

274276
@property
275-
def otlp_logs_endpoint(self):
276-
endpoint = self.get_endpoint()
277+
def otlp_traces_endpoint(self):
278+
return self.build_integration_endpoint("otlp", "v1/traces")
277279

278-
return f"{endpoint}/api/{self.project_id}/integration/otlp/v1/logs"
280+
@property
281+
def otlp_logs_endpoint(self):
282+
return self.build_integration_endpoint("otlp", "v1/logs")
279283

280284
@property
281285
def unreal_endpoint(self) -> str:

tests/sentry/core/endpoints/test_project_keys.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def test_playstation_dsn(self) -> None:
4040
assert response.status_code == 200
4141
assert response.data[0]["dsn"]["playstation"] == key.playstation_endpoint
4242

43+
def test_integration_endpoint(self) -> None:
44+
project = self.create_project()
45+
key = ProjectKey.objects.get_or_create(project=project)[0]
46+
self.login_as(user=self.user)
47+
url = reverse(
48+
"sentry-api-0-project-keys",
49+
kwargs={
50+
"organization_id_or_slug": project.organization.slug,
51+
"project_id_or_slug": project.slug,
52+
},
53+
)
54+
response = self.client.get(url)
55+
assert response.status_code == 200
56+
assert response.data[0]["dsn"]["integration"] == key.integration_endpoint
57+
4358
def test_otlp_traces_endpoint(self) -> None:
4459
project = self.create_project()
4560
key = ProjectKey.objects.get_or_create(project=project)[0]

0 commit comments

Comments
 (0)