Skip to content

Commit 037153b

Browse files
authored
chore(explore): Add gen ai consent to explore analytics (#97707)
This PR adds a `gave_seer_consent` field to the `trace.explorer.metadata` analytic event.
1 parent 061a7de commit 037153b

File tree

4 files changed

+98
-44
lines changed

4 files changed

+98
-44
lines changed

static/app/utils/analytics/tracingEventMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type TracingEventParameters = {
3838
columns_count: number;
3939
confidences: string[];
4040
dataset: string;
41+
gave_seer_consent: 'given' | 'not_given' | 'gen_ai_features_disabled';
4142
has_exceeded_performance_usage_limit: boolean | null;
4243
interval: string;
4344
page_source: 'explore' | 'compare';

static/app/views/explore/hooks/useAnalytics.tsx

Lines changed: 76 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {useEffect, useRef} from 'react';
22
import * as Sentry from '@sentry/react';
33

4+
import {useOrganizationSeerSetup} from 'sentry/components/events/autofix/useOrganizationSeerSetup';
45
import {defined} from 'sentry/utils';
56
import {trackAnalytics} from 'sentry/utils/analytics';
67
import type {LogsAnalyticsPageSource} from 'sentry/utils/analytics/logsAnalyticsEvent';
@@ -86,18 +87,30 @@ function useTrackAnalytics({
8687
const chartError = timeseriesResult.error?.message ?? '';
8788
const query_status = tableError || chartError ? 'error' : 'success';
8889

90+
const {setupAcknowledgement: seerSetup, isLoading: isLoadingSeerSetup} =
91+
useOrganizationSeerSetup({
92+
enabled: !organization.hideAiFeatures,
93+
});
94+
8995
useEffect(() => {
9096
if (
9197
queryType !== 'aggregate' ||
9298
aggregatesTableResult.result.isPending ||
9399
timeseriesResult.isPending ||
94-
isLoadingSubscriptionDetails
100+
isLoadingSubscriptionDetails ||
101+
isLoadingSeerSetup
95102
) {
96103
return;
97104
}
98105

99106
const search = new MutableSearch(query);
100107
const columns = aggregatesTableResult.eventView.getColumns() as unknown as string[];
108+
const gaveSeerConsent = organization.hideAiFeatures
109+
? 'gen_ai_features_disabled'
110+
: seerSetup?.orgHasAcknowledged
111+
? 'given'
112+
: 'not_given';
113+
101114
trackAnalytics('trace.explorer.metadata', {
102115
organization,
103116
dataset,
@@ -122,6 +135,7 @@ function useTrackAnalytics({
122135
has_exceeded_performance_usage_limit: hasExceededPerformanceUsageLimit,
123136
page_source,
124137
interval,
138+
gave_seer_consent: gaveSeerConsent,
125139
});
126140

127141
/* eslint-disable @typescript-eslint/no-base-to-string */
@@ -139,43 +153,51 @@ function useTrackAnalytics({
139153
visualizes_count: ${String(String(visualizes).length)}
140154
has_exceeded_performance_usage_limit: ${String(hasExceededPerformanceUsageLimit)}
141155
page_source: ${page_source}
156+
gave_seer_consent: ${gaveSeerConsent}
142157
`,
143158
{isAnalytics: true}
144159
);
145160
/* eslint-enable @typescript-eslint/no-base-to-string */
146161
}, [
147-
organization,
148-
dataset,
149-
fields,
150-
query,
151-
visualizes,
152-
title,
153-
queryType,
154-
aggregatesTableResult.result.isPending,
155-
aggregatesTableResult.result.status,
156-
aggregatesTableResult.result.data?.length,
157162
aggregatesTableResult.eventView,
158-
timeseriesResult.isPending,
159-
timeseriesResult.data,
163+
aggregatesTableResult.result.data?.length,
164+
aggregatesTableResult.result.isPending,
165+
dataset,
160166
hasExceededPerformanceUsageLimit,
161-
isLoadingSubscriptionDetails,
162-
query_status,
163-
page_source,
164167
interval,
168+
isLoadingSeerSetup,
169+
isLoadingSubscriptionDetails,
165170
isTopN,
171+
organization,
172+
page_source,
173+
query,
174+
queryType,
175+
query_status,
176+
seerSetup?.orgHasAcknowledged,
177+
timeseriesResult.data,
178+
timeseriesResult.isPending,
179+
title,
180+
visualizes,
166181
]);
167182

168183
useEffect(() => {
169184
if (
170185
queryType !== 'samples' ||
171186
spansTableResult.result.isPending ||
172187
timeseriesResult.isPending ||
173-
isLoadingSubscriptionDetails
188+
isLoadingSubscriptionDetails ||
189+
isLoadingSeerSetup
174190
) {
175191
return;
176192
}
177193

178194
const search = new MutableSearch(query);
195+
const gaveSeerConsent = organization.hideAiFeatures
196+
? 'gen_ai_features_disabled'
197+
: seerSetup?.orgHasAcknowledged
198+
? 'given'
199+
: 'not_given';
200+
179201
trackAnalytics('trace.explorer.metadata', {
180202
organization,
181203
dataset,
@@ -200,6 +222,7 @@ function useTrackAnalytics({
200222
has_exceeded_performance_usage_limit: hasExceededPerformanceUsageLimit,
201223
page_source,
202224
interval,
225+
gave_seer_consent: gaveSeerConsent,
203226
});
204227

205228
info(fmt`trace.explorer.metadata:
@@ -215,26 +238,28 @@ function useTrackAnalytics({
215238
visualizes_count: ${String(visualizes.length)}
216239
has_exceeded_performance_usage_limit: ${String(hasExceededPerformanceUsageLimit)}
217240
page_source: ${page_source}
241+
gave_seer_consent: ${gaveSeerConsent}
218242
`);
219243
}, [
220-
organization,
221244
dataset,
222245
fields,
246+
hasExceededPerformanceUsageLimit,
247+
interval,
248+
isLoadingSeerSetup,
249+
isLoadingSubscriptionDetails,
250+
isTopN,
251+
organization,
252+
page_source,
223253
query,
224-
visualizes,
225-
title,
226254
queryType,
227-
spansTableResult.result.isPending,
228-
spansTableResult.result.status,
255+
query_status,
256+
seerSetup?.orgHasAcknowledged,
229257
spansTableResult.result.data?.length,
230-
timeseriesResult.isPending,
258+
spansTableResult.result.isPending,
231259
timeseriesResult.data,
232-
hasExceededPerformanceUsageLimit,
233-
isLoadingSubscriptionDetails,
234-
query_status,
235-
page_source,
236-
interval,
237-
isTopN,
260+
timeseriesResult.isPending,
261+
title,
262+
visualizes,
238263
]);
239264

240265
const tracesTableResultDefined = defined(tracesTableResult);
@@ -245,7 +270,8 @@ function useTrackAnalytics({
245270
queryType !== 'traces' ||
246271
tracesTableResult.result.isPending ||
247272
timeseriesResult.isPending ||
248-
isLoadingSubscriptionDetails
273+
isLoadingSubscriptionDetails ||
274+
isLoadingSeerSetup
249275
) {
250276
return;
251277
}
@@ -262,6 +288,11 @@ function useTrackAnalytics({
262288
const resultMissingRoot =
263289
tracesTableResult?.result?.data?.data?.filter(trace => !defined(trace.name))
264290
.length ?? 0;
291+
const gaveSeerConsent = organization.hideAiFeatures
292+
? 'gen_ai_features_disabled'
293+
: seerSetup?.orgHasAcknowledged
294+
? 'given'
295+
: 'not_given';
265296

266297
trackAnalytics('trace.explorer.metadata', {
267298
organization,
@@ -287,27 +318,28 @@ function useTrackAnalytics({
287318
has_exceeded_performance_usage_limit: hasExceededPerformanceUsageLimit,
288319
page_source,
289320
interval,
321+
gave_seer_consent: gaveSeerConsent,
290322
});
291323
}, [
292-
organization,
293324
dataset,
294-
fields,
295-
query,
296-
visualizes,
297-
title,
298-
queryType,
299-
tracesTableResult?.result.isPending,
300-
tracesTableResult?.result.status,
301-
tracesTableResult?.result.data?.data,
302-
timeseriesResult.isPending,
303-
timeseriesResult.data,
304325
hasExceededPerformanceUsageLimit,
326+
interval,
327+
isLoadingSeerSetup,
305328
isLoadingSubscriptionDetails,
306-
query_status,
329+
isTopN,
330+
organization,
307331
page_source,
332+
query,
333+
queryType,
334+
query_status,
335+
seerSetup?.orgHasAcknowledged,
336+
timeseriesResult.data,
337+
timeseriesResult.isPending,
338+
title,
339+
tracesTableResult?.result.data?.data,
340+
tracesTableResult?.result.isPending,
308341
tracesTableResultDefined,
309-
interval,
310-
isTopN,
342+
visualizes,
311343
]);
312344
}
313345

static/app/views/explore/multiQueryMode/content.spec.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {AutofixSetupFixture} from 'sentry-fixture/autofixSetupFixture';
12
import {RouterFixture} from 'sentry-fixture/routerFixture';
23

34
import {initializeOrg} from 'sentry-test/initializeOrg';
@@ -43,6 +44,16 @@ describe('MultiQueryModeContent', function () {
4344
new Set()
4445
);
4546

47+
MockApiClient.addMockResponse({
48+
url: `/organizations/${organization.slug}/seer/setup-check/`,
49+
body: AutofixSetupFixture({
50+
setupAcknowledgement: {
51+
orgHasAcknowledged: true,
52+
userHasAcknowledged: true,
53+
},
54+
}),
55+
});
56+
4657
MockApiClient.addMockResponse({
4758
url: `/organizations/${organization.slug}/trace-items/attributes/`,
4859
method: 'GET',

static/app/views/explore/spans/spansTab.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type {ReactNode} from 'react';
2+
import {AutofixSetupFixture} from 'sentry-fixture/autofixSetupFixture';
23

34
import {initializeOrg} from 'sentry-test/initializeOrg';
45
import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
@@ -103,6 +104,15 @@ describe('SpansTabContent', function () {
103104
method: 'GET',
104105
body: {},
105106
});
107+
MockApiClient.addMockResponse({
108+
url: `/organizations/${organization.slug}/seer/setup-check/`,
109+
body: AutofixSetupFixture({
110+
setupAcknowledgement: {
111+
orgHasAcknowledged: true,
112+
userHasAcknowledged: true,
113+
},
114+
}),
115+
});
106116
});
107117

108118
it('should fire analytics once per change', async function () {

0 commit comments

Comments
 (0)