Browse Source

feat(metrics) Do not provide auto-complete for high cardinality tags (#75227)

Prevents auto-complete for high cardinality tags by using deny list of
high cardinality tags.

Closes https://github.com/getsentry/sentry/issues/75126
Vjeran Grozdanić 7 months ago
parent
commit
56d55a56cd

+ 12 - 0
static/app/views/insights/types.tsx

@@ -37,13 +37,25 @@ export enum SpanMetricsField {
   HTTP_RESPONSE_TRANSFER_SIZE = 'http.response_transfer_size',
   FILE_EXTENSION = 'file_extension',
   AI_TOTAL_TOKENS_USED = 'ai.total_tokens.used',
+  AI_PROMPT_TOKENS_USED = 'ai.prompt_tokens.used',
+  AI_COMPLETION_TOKENS_USED = 'ai.completion_tokens.used',
+  AI_INPUT_MESSAGES = 'ai.input_messages',
   AI_TOTAL_COST = 'ai.total_cost',
   OS_NAME = 'os.name',
   APP_START_TYPE = 'app_start_type',
   DEVICE_CLASS = 'device.class',
   CACHE_HIT = 'cache.hit',
+  CACHE_KEY = 'cache.key',
   CACHE_ITEM_SIZE = 'cache.item_size',
   MESSAGING_MESSAGE_RECEIVE_LATENCY = 'messaging.message.receive.latency',
+  THREAD_ID = 'thread.id',
+  SENTRY_FRAMES_SLOW = 'sentry.frames.slow',
+  SENTRY_FRAMES_FROZEN = 'sentry.frames.frozen',
+  SENTRY_FRAMES_TOTAL = 'sentry.frames.total',
+  FRAMES_DELAY = 'frames.delay',
+  URL_FULL = 'url.full',
+  USER_AGENT_ORIGINAL = 'user_agent.original',
+  CLIENT_ADDRESS = 'client.address',
 }
 
 export type SpanNumberFields =

+ 42 - 12
static/app/views/settings/projectMetrics/metricsExtractionRuleForm.tsx

@@ -18,7 +18,7 @@ import type {SelectValue} from 'sentry/types/core';
 import type {MetricAggregation, MetricsExtractionCondition} from 'sentry/types/metrics';
 import {DiscoverDatasets} from 'sentry/utils/discover/types';
 import useOrganization from 'sentry/utils/useOrganization';
-import {SpanIndexedField} from 'sentry/views/insights/types';
+import {SpanIndexedField, SpanMetricsField} from 'sentry/views/insights/types';
 import {useSpanFieldSupportedTags} from 'sentry/views/performance/utils/useSpanFieldSupportedTags';
 import {useMetricsExtractionRules} from 'sentry/views/settings/projectMetrics/utils/useMetricsExtractionRules';
 
@@ -46,21 +46,52 @@ interface Props extends Omit<FormProps, 'onSubmit'> {
 }
 
 const HIGH_CARDINALITY_TAGS = new Set([
+  SpanIndexedField.HTTP_RESPONSE_CONTENT_LENGTH,
   SpanIndexedField.SPAN_DURATION,
   SpanIndexedField.SPAN_SELF_TIME,
+  SpanIndexedField.SPAN_GROUP,
+  SpanIndexedField.ID,
+  SpanIndexedField.SPAN_AI_PIPELINE_GROUP,
+  SpanIndexedField.TRANSACTION_ID,
   SpanIndexedField.PROJECT_ID,
+  SpanIndexedField.PROFILE_ID,
+  SpanIndexedField.REPLAY_ID,
+  SpanIndexedField.TIMESTAMP,
+  SpanIndexedField.USER,
+  SpanIndexedField.USER_ID,
+  SpanIndexedField.USER_EMAIL,
+  SpanIndexedField.USER_USERNAME,
   SpanIndexedField.INP,
   SpanIndexedField.INP_SCORE,
   SpanIndexedField.INP_SCORE_WEIGHT,
   SpanIndexedField.TOTAL_SCORE,
   SpanIndexedField.CACHE_ITEM_SIZE,
+  SpanIndexedField.MESSAGING_MESSAGE_ID,
   SpanIndexedField.MESSAGING_MESSAGE_BODY_SIZE,
   SpanIndexedField.MESSAGING_MESSAGE_RECEIVE_LATENCY,
   SpanIndexedField.MESSAGING_MESSAGE_RETRY_COUNT,
-  SpanIndexedField.TRANSACTION_ID,
-  SpanIndexedField.ID,
+  SpanMetricsField.AI_TOTAL_TOKENS_USED,
+  SpanMetricsField.AI_PROMPT_TOKENS_USED,
+  SpanMetricsField.AI_COMPLETION_TOKENS_USED,
+  SpanMetricsField.AI_INPUT_MESSAGES,
+  SpanMetricsField.HTTP_DECODED_RESPONSE_CONTENT_LENGTH,
+  SpanMetricsField.HTTP_RESPONSE_TRANSFER_SIZE,
+  SpanMetricsField.CACHE_ITEM_SIZE,
+  SpanMetricsField.CACHE_KEY,
+  SpanMetricsField.THREAD_ID,
+  SpanMetricsField.SENTRY_FRAMES_FROZEN,
+  SpanMetricsField.SENTRY_FRAMES_SLOW,
+  SpanMetricsField.SENTRY_FRAMES_TOTAL,
+  SpanMetricsField.FRAMES_DELAY,
+  SpanMetricsField.URL_FULL,
+  SpanMetricsField.USER_AGENT_ORIGINAL,
+  SpanMetricsField.FRAMES_DELAY,
 ]);
 
+const isHighCardinalityTag = (tag: string): boolean => {
+  return HIGH_CARDINALITY_TAGS.has(tag as SpanIndexedField);
+};
+
 const AGGREGATE_OPTIONS: {label: string; value: AggregateGroup}[] = [
   {
     label: t('count'),
@@ -254,15 +285,14 @@ export function MetricsExtractionRuleForm({
   }, [allAttributeOptions, extractionRules]);
 
   const tagOptions = useMemo(() => {
-    return allAttributeOptions
-      .filter(
-        // We don't want to suggest numeric fields as tags as they would explode cardinality
-        option => !HIGH_CARDINALITY_TAGS.has(option as SpanIndexedField)
-      )
-      .map<SelectValue<string>>(option => ({
-        label: option,
-        value: option,
-      }));
+    return allAttributeOptions.map<SelectValue<string>>(option => ({
+      label: option,
+      value: option,
+      disabled: isHighCardinalityTag(option),
+      tooltip: isHighCardinalityTag(option)
+        ? t('This tag has high cardinality.')
+        : undefined,
+    }));
   }, [allAttributeOptions]);
 
   const unitOptions = useMemo(() => {