Skip to content

ref(analytics): Transform analytics events for TET-834 #95214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from sentry import analytics


@analytics.eventclass("alert_rule_ui_component_webhook.sent")
class AlertRuleUiComponentWebhookSentEvent(analytics.Event):
type = "alert_rule_ui_component_webhook.sent"

attributes = (
# organization_id refers to the organization that installed the sentryapp
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app_id"),
analytics.Attribute("event"),
)
# organization_id refers to the organization that installed the sentryapp
organization_id: str
sentry_app_id: str
event: str


analytics.register(AlertRuleUiComponentWebhookSentEvent)
11 changes: 4 additions & 7 deletions src/sentry/analytics/events/internal_integration_created.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from sentry import analytics


@analytics.eventclass("internal_integration.created")
class InternalIntegrationCreatedEvent(analytics.Event):
type = "internal_integration.created"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app: str


analytics.register(InternalIntegrationCreatedEvent)
13 changes: 5 additions & 8 deletions src/sentry/analytics/events/sentry_app_created.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from sentry import analytics


@analytics.eventclass("sentry_app.created")
class SentryAppCreatedEvent(analytics.Event):
type = "sentry_app.created"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
analytics.Attribute("created_alert_rule_ui_component", type=bool, required=False),
)
user_id: str
organization_id: str
sentry_app: str
created_alert_rule_ui_component: bool | None = None


analytics.register(SentryAppCreatedEvent)
11 changes: 4 additions & 7 deletions src/sentry/analytics/events/sentry_app_deleted.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from sentry import analytics


@analytics.eventclass("sentry_app.deleted")
class SentryAppDeletedEvent(analytics.Event):
type = "sentry_app.deleted"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app: str


analytics.register(SentryAppDeletedEvent)
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from sentry import analytics


@analytics.eventclass("sentry_app_installation_token.created")
class SentryAppInstallationTokenCreated(analytics.Event):
type = "sentry_app_installation_token.created"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app_installation_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app_installation_id: str
sentry_app: str


analytics.register(SentryAppInstallationTokenCreated)
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from sentry import analytics


@analytics.eventclass("sentry_app_installation_token.deleted")
class SentryAppInstallationTokenDeleted(analytics.Event):
type = "sentry_app_installation_token.deleted"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app_installation_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app_installation_id: str
sentry_app: str


analytics.register(SentryAppInstallationTokenDeleted)
11 changes: 4 additions & 7 deletions src/sentry/analytics/events/sentry_app_installation_updated.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from sentry import analytics


@analytics.eventclass("sentry_app_installation.updated")
class SentryAppInstallationUpdatedEvent(analytics.Event):
type = "sentry_app_installation.updated"

attributes = (
analytics.Attribute("sentry_app_installation_id"),
analytics.Attribute("sentry_app_id"),
analytics.Attribute("organization_id"),
)
sentry_app_installation_id: str
sentry_app_id: str
organization_id: str


analytics.register(SentryAppInstallationUpdatedEvent)
11 changes: 4 additions & 7 deletions src/sentry/analytics/events/sentry_app_installed.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from sentry import analytics


@analytics.eventclass("sentry_app.installed")
class SentryAppInstalledEvent(analytics.Event):
type = "sentry_app.installed"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app: str


analytics.register(SentryAppInstalledEvent)
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from sentry import analytics


@analytics.eventclass("sentry_app.schema_validation_error")
class SentryAppSchemaValidationError(analytics.Event):
type = "sentry_app.schema_validation_error"

attributes = (
analytics.Attribute("schema"),
analytics.Attribute("user_id"),
analytics.Attribute("sentry_app_id", required=False),
analytics.Attribute("sentry_app_name"),
analytics.Attribute("organization_id"),
analytics.Attribute("error_message"),
)
schema: str
user_id: str
sentry_app_id: str | None = None
sentry_app_name: str
organization_id: str
error_message: str


analytics.register(SentryAppSchemaValidationError)
9 changes: 3 additions & 6 deletions src/sentry/analytics/events/sentry_app_token_exchanged.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from sentry import analytics


@analytics.eventclass("sentry_app.token_exchanged")
class SentryAppTokenExchangedEvent(analytics.Event):
type = "sentry_app.token_exchanged"

attributes = (
analytics.Attribute("sentry_app_installation_id"),
analytics.Attribute("exchange_type"),
)
sentry_app_installation_id: str
exchange_type: str


analytics.register(SentryAppTokenExchangedEvent)
11 changes: 4 additions & 7 deletions src/sentry/analytics/events/sentry_app_uninstalled.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from sentry import analytics


@analytics.eventclass("sentry_app.uninstalled")
class SentryAppUninstalledEvent(analytics.Event):
type = "sentry_app.uninstalled"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
)
user_id: str
organization_id: str
sentry_app: str


analytics.register(SentryAppUninstalledEvent)
13 changes: 5 additions & 8 deletions src/sentry/analytics/events/sentry_app_updated.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from sentry import analytics


@analytics.eventclass("sentry_app.updated")
class SentryAppUpdatedEvent(analytics.Event):
type = "sentry_app.updated"

attributes = (
analytics.Attribute("user_id"),
analytics.Attribute("organization_id"),
analytics.Attribute("sentry_app"),
analytics.Attribute("created_alert_rule_ui_component", type=bool, required=False),
)
user_id: str
organization_id: str
sentry_app: str
created_alert_rule_ui_component: bool | None = None


analytics.register(SentryAppUpdatedEvent)
12 changes: 8 additions & 4 deletions src/sentry/integrations/services/integration/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from django.utils import timezone

from sentry import analytics
from sentry.analytics.events.alert_rule_ui_component_webhook_sent import (
AlertRuleUiComponentWebhookSentEvent,
)
from sentry.api.paginator import OffsetPaginator
from sentry.constants import SentryAppInstallationStatus
from sentry.hybridcloud.rpc.pagination import RpcPaginationArgs, RpcPaginationResult
Expand Down Expand Up @@ -422,10 +425,11 @@ def send_incident_alert_notification(

if alert_rule_action_ui_component:
analytics.record(
"alert_rule_ui_component_webhook.sent",
organization_id=organization_id,
sentry_app_id=sentry_app.id,
event=f"{app_platform_event.resource}.{app_platform_event.action}",
AlertRuleUiComponentWebhookSentEvent(
organization_id=organization_id,
sentry_app_id=sentry_app.id,
event=f"{app_platform_event.resource}.{app_platform_event.action}",
)
)
return alert_rule_action_ui_component

Expand Down
10 changes: 6 additions & 4 deletions src/sentry/sentry_apps/api/endpoints/installation_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework.response import Response

from sentry import analytics, audit_log, deletions
from sentry.analytics.events.sentry_app_uninstalled import SentryAppUninstalledEvent
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
Expand Down Expand Up @@ -64,10 +65,11 @@ def delete(self, request: Request, installation) -> Response:
data={"sentry_app": sentry_app_installation.sentry_app.name},
)
analytics.record(
"sentry_app.uninstalled",
user_id=request.user.id,
organization_id=sentry_app_installation.organization_id,
sentry_app=sentry_app_installation.sentry_app.slug,
SentryAppUninstalledEvent(
user_id=request.user.id,
organization_id=sentry_app_installation.organization_id,
sentry_app=sentry_app_installation.sentry_app.slug,
)
)
return Response(status=204)

Expand Down
10 changes: 6 additions & 4 deletions src/sentry/sentry_apps/api/endpoints/sentry_app_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rest_framework.response import Response

from sentry import analytics, audit_log, deletions, features
from sentry.analytics.events.sentry_app_deleted import SentryAppDeletedEvent
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
Expand Down Expand Up @@ -232,10 +233,11 @@ def delete(self, request: Request, sentry_app) -> Response:
data={"sentry_app": sentry_app.name},
)
analytics.record(
"sentry_app.deleted",
user_id=request.user.id,
organization_id=sentry_app.owner_id,
sentry_app=sentry_app.slug,
SentryAppDeletedEvent(
user_id=request.user.id,
organization_id=sentry_app.owner_id,
sentry_app=sentry_app.slug,
)
)
return Response(status=204)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from rest_framework.response import Response

from sentry import analytics, deletions
from sentry.analytics.events.sentry_app_installation_token_deleted import (
SentryAppInstallationTokenDeleted,
)
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import control_silo_endpoint
Expand Down Expand Up @@ -63,11 +66,12 @@ def delete(self, request: Request, sentry_app, api_token) -> Response:
deletions.exec_sync(install_token)

analytics.record(
"sentry_app_installation_token.deleted",
user_id=request.user.id,
organization_id=sentry_app_installation.organization_id,
sentry_app_installation_id=sentry_app_installation.id,
sentry_app=sentry_app.slug,
SentryAppInstallationTokenDeleted(
user_id=request.user.id,
organization_id=sentry_app_installation.organization_id,
sentry_app_installation_id=sentry_app_installation.id,
sentry_app=sentry_app.slug,
)
)

return Response(status=204)
Loading
Loading