From 9750daf90bf9d935475b7f3d5f6a56560c439134 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 18 May 2026 15:03:26 +0200 Subject: [PATCH 1/2] rename types-hoist to types --- packages/core/src/types/attachment.ts | 35 + packages/core/src/types/breadcrumb.ts | 108 +++ packages/core/src/types/browseroptions.ts | 49 ++ packages/core/src/types/checkin.ts | 113 +++ packages/core/src/types/clientreport.ts | 26 + packages/core/src/types/context.ts | 141 ++++ packages/core/src/types/csp.ts | 15 + packages/core/src/types/datacategory.ts | 38 + packages/core/src/types/datacollection.ts | 72 ++ packages/core/src/types/debugMeta.ts | 30 + packages/core/src/types/dsn.ts | 23 + packages/core/src/types/envelope.ts | 182 +++++ packages/core/src/types/error.ts | 8 + packages/core/src/types/event.ts | 89 +++ packages/core/src/types/eventprocessor.ts | 12 + packages/core/src/types/exception.ts | 12 + packages/core/src/types/extra.ts | 2 + packages/core/src/types/feedback/config.ts | 251 ++++++ packages/core/src/types/feedback/form.ts | 8 + packages/core/src/types/feedback/index.ts | 92 +++ .../core/src/types/feedback/sendFeedback.ts | 62 ++ packages/core/src/types/feedback/theme.ts | 42 + packages/core/src/types/instrument.ts | 98 +++ packages/core/src/types/integration.ts | 75 ++ packages/core/src/types/link.ts | 30 + packages/core/src/types/log.ts | 73 ++ packages/core/src/types/measurement.ts | 45 ++ packages/core/src/types/mechanism.ts | 57 ++ packages/core/src/types/metric.ts | 86 +++ packages/core/src/types/misc.ts | 69 ++ packages/core/src/types/opentelemetry.ts | 31 + packages/core/src/types/options.ts | 725 ++++++++++++++++++ packages/core/src/types/package.ts | 7 + packages/core/src/types/parameterize.ts | 4 + packages/core/src/types/polymorphics.ts | 76 ++ packages/core/src/types/profiling.ts | 157 ++++ packages/core/src/types/replay.ts | 61 ++ packages/core/src/types/request.ts | 44 ++ packages/core/src/types/runtime.ts | 5 + packages/core/src/types/samplingcontext.ts | 54 ++ packages/core/src/types/sdkinfo.ts | 14 + packages/core/src/types/sdkmetadata.ts | 5 + packages/core/src/types/session.ts | 72 ++ packages/core/src/types/severity.ts | 1 + packages/core/src/types/span.ts | 323 ++++++++ packages/core/src/types/spanStatus.ts | 60 ++ packages/core/src/types/stackframe.ts | 23 + packages/core/src/types/stacktrace.ts | 11 + packages/core/src/types/startSpanOptions.ts | 85 ++ packages/core/src/types/thread.ts | 11 + packages/core/src/types/timedEvent.ts | 7 + packages/core/src/types/tracing.ts | 63 ++ packages/core/src/types/transaction.ts | 37 + packages/core/src/types/transport.ts | 45 ++ packages/core/src/types/user.ts | 19 + packages/core/src/types/view-hierarchy.ts | 19 + packages/core/src/types/vue.ts | 18 + packages/core/src/types/webfetchapi.ts | 19 + packages/core/src/types/wrappedfunction.ts | 8 + 59 files changed, 3947 insertions(+) create mode 100644 packages/core/src/types/attachment.ts create mode 100644 packages/core/src/types/breadcrumb.ts create mode 100644 packages/core/src/types/browseroptions.ts create mode 100644 packages/core/src/types/checkin.ts create mode 100644 packages/core/src/types/clientreport.ts create mode 100644 packages/core/src/types/context.ts create mode 100644 packages/core/src/types/csp.ts create mode 100644 packages/core/src/types/datacategory.ts create mode 100644 packages/core/src/types/datacollection.ts create mode 100644 packages/core/src/types/debugMeta.ts create mode 100644 packages/core/src/types/dsn.ts create mode 100644 packages/core/src/types/envelope.ts create mode 100644 packages/core/src/types/error.ts create mode 100644 packages/core/src/types/event.ts create mode 100644 packages/core/src/types/eventprocessor.ts create mode 100644 packages/core/src/types/exception.ts create mode 100644 packages/core/src/types/extra.ts create mode 100644 packages/core/src/types/feedback/config.ts create mode 100644 packages/core/src/types/feedback/form.ts create mode 100644 packages/core/src/types/feedback/index.ts create mode 100644 packages/core/src/types/feedback/sendFeedback.ts create mode 100644 packages/core/src/types/feedback/theme.ts create mode 100644 packages/core/src/types/instrument.ts create mode 100644 packages/core/src/types/integration.ts create mode 100644 packages/core/src/types/link.ts create mode 100644 packages/core/src/types/log.ts create mode 100644 packages/core/src/types/measurement.ts create mode 100644 packages/core/src/types/mechanism.ts create mode 100644 packages/core/src/types/metric.ts create mode 100644 packages/core/src/types/misc.ts create mode 100644 packages/core/src/types/opentelemetry.ts create mode 100644 packages/core/src/types/options.ts create mode 100644 packages/core/src/types/package.ts create mode 100644 packages/core/src/types/parameterize.ts create mode 100644 packages/core/src/types/polymorphics.ts create mode 100644 packages/core/src/types/profiling.ts create mode 100644 packages/core/src/types/replay.ts create mode 100644 packages/core/src/types/request.ts create mode 100644 packages/core/src/types/runtime.ts create mode 100644 packages/core/src/types/samplingcontext.ts create mode 100644 packages/core/src/types/sdkinfo.ts create mode 100644 packages/core/src/types/sdkmetadata.ts create mode 100644 packages/core/src/types/session.ts create mode 100644 packages/core/src/types/severity.ts create mode 100644 packages/core/src/types/span.ts create mode 100644 packages/core/src/types/spanStatus.ts create mode 100644 packages/core/src/types/stackframe.ts create mode 100644 packages/core/src/types/stacktrace.ts create mode 100644 packages/core/src/types/startSpanOptions.ts create mode 100644 packages/core/src/types/thread.ts create mode 100644 packages/core/src/types/timedEvent.ts create mode 100644 packages/core/src/types/tracing.ts create mode 100644 packages/core/src/types/transaction.ts create mode 100644 packages/core/src/types/transport.ts create mode 100644 packages/core/src/types/user.ts create mode 100644 packages/core/src/types/view-hierarchy.ts create mode 100644 packages/core/src/types/vue.ts create mode 100644 packages/core/src/types/webfetchapi.ts create mode 100644 packages/core/src/types/wrappedfunction.ts diff --git a/packages/core/src/types/attachment.ts b/packages/core/src/types/attachment.ts new file mode 100644 index 000000000000..11bbca772e02 --- /dev/null +++ b/packages/core/src/types/attachment.ts @@ -0,0 +1,35 @@ +export type AttachmentType = + | 'event.attachment' + | 'event.minidump' + | 'event.applecrashreport' + | 'unreal.context' + | 'unreal.logs' + | 'event.view_hierarchy'; + +/** + * An attachment to an event. This is used to upload arbitrary data to Sentry. + * + * Please take care to not add sensitive information in attachments. + * + * https://develop.sentry.dev/sdk/envelopes/#attachment + */ +export interface Attachment { + /** + * The attachment data. Can be a string or a binary data (byte array) + */ + data: string | Uint8Array; + /** + * The name of the uploaded file without a path component + */ + filename: string; + /** + * The content type of the attachment payload. Defaults to `application/octet-stream` if not specified. + * + * Any valid [media type](https://www.iana.org/assignments/media-types/media-types.xhtml) is allowed. + */ + contentType?: string; + /** + * The type of the attachment. Defaults to `event.attachment` if not specified. + */ + attachmentType?: AttachmentType; +} diff --git a/packages/core/src/types/breadcrumb.ts b/packages/core/src/types/breadcrumb.ts new file mode 100644 index 000000000000..391100a5a377 --- /dev/null +++ b/packages/core/src/types/breadcrumb.ts @@ -0,0 +1,108 @@ +import type { SeverityLevel } from './severity'; + +/** + * Sentry uses breadcrumbs to create a trail of events that happened prior to an issue. + * These events are very similar to traditional logs but can record more rich structured data. + * + * @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/ + */ +export interface Breadcrumb { + /** + * By default, all breadcrumbs are recorded as default, which makes them appear as a Debug entry, but Sentry provides + * other types that influence how the breadcrumbs are rendered. For more information, see the description of + * recognized breadcrumb types. + * + * @summary The type of breadcrumb. + * @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#breadcrumb-types + */ + type?: string; + + /** + * Allowed values are, from highest to lowest: + * `fatal`, `error`, `warning`, `info`, and `debug`. + * Levels are used in the UI to emphasize and deemphasize the crumb. The default is `info`. + * + * @summary This defines the severity level of the breadcrumb. + */ + level?: SeverityLevel; + + event_id?: string; + + /** + * Typically it is a module name or a descriptive string. For instance, `ui.click` could be used to + * indicate that a click happened in the UI or flask could be used to indicate that the event originated in + * the Flask framework. + * @private Internally we render some crumbs' color and icon based on the provided category. + * For more information, see the description of recognized breadcrumb types. + * @summary A dotted string indicating what the crumb is or from where it comes. + * @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#breadcrumb-types + */ + category?: string; + + /** + * If a message is provided, it is rendered as text with all whitespace preserved. + * + * @summary Human-readable message for the breadcrumb. + */ + message?: string; + + /** + * Contains a dictionary whose contents depend on the breadcrumb type. + * Additional parameters that are unsupported by the type are rendered as a key/value table. + * + * @summary Arbitrary data associated with this breadcrumb. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data?: { [key: string]: any }; + + /** + * The format is a numeric (integer or float) value representing + * the number of seconds that have elapsed since the Unixepoch. + * Breadcrumbs are most useful when they include a timestamp, as it creates a timeline + * leading up to an event expection/error. + * + * @note The API supports a string as defined in RFC 3339, but the SDKs only support a numeric value for now. + * + * @summary A timestamp representing when the breadcrumb occurred. + * @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#:~:text=is%20info.-,timestamp,-(recommended) + */ + timestamp?: number; +} + +/** JSDoc */ +export interface BreadcrumbHint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; +} + +export interface FetchBreadcrumbData { + method: string; + url: string; + status_code?: number; + request_body_size?: number; + response_body_size?: number; +} + +export interface XhrBreadcrumbData { + method?: string; + url?: string; + status_code?: number; + request_body_size?: number; + response_body_size?: number; +} + +export interface FetchBreadcrumbHint { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + input: any[]; + data?: unknown; + response?: unknown; + startTimestamp: number; + endTimestamp?: number; +} + +export interface XhrBreadcrumbHint { + xhr: unknown; + input: unknown; + startTimestamp: number; + endTimestamp: number; +} diff --git a/packages/core/src/types/browseroptions.ts b/packages/core/src/types/browseroptions.ts new file mode 100644 index 000000000000..39b414d5140b --- /dev/null +++ b/packages/core/src/types/browseroptions.ts @@ -0,0 +1,49 @@ +/** + * Options added to the Browser SDK's init options that are specific for Replay. + * Note: This type was moved to @sentry/core to avoid a circular dependency between Browser and Replay. + */ +export type BrowserClientReplayOptions = { + /** + * The sample rate for session-long replays. + * 1.0 will record all sessions and 0 will record none. + */ + replaysSessionSampleRate?: number; + + /** + * The sample rate for sessions that has had an error occur. + * This is independent of `sessionSampleRate`. + * 1.0 will record all sessions and 0 will record none. + */ + replaysOnErrorSampleRate?: number; +}; + +export type BrowserClientProfilingOptions = { + /** + * The sample rate for profiling + * 1.0 will profile all transactions and 0 will profile none. + * + * @deprecated Use `profileSessionSampleRate` and `profileLifecycle` instead. + */ + profilesSampleRate?: number; + + /** + * Sets profiling session sample rate for the entire profiling session. + * + * A profiling session corresponds to a user session, meaning it is set once at integration initialization and + * persisted until the next page reload. This rate determines what percentage of user sessions will have profiling enabled. + * @default 0 + */ + profileSessionSampleRate?: number; + + /** + * Set the lifecycle mode of the profiler. + * - **manual**: The profiler will be manually started and stopped via `startProfiler`/`stopProfiler`. + * If a session is sampled, is dependent on the `profileSessionSampleRate`. + * - **trace**: The profiler will be automatically started when a root span exists and stopped when there are no + * more sampled root spans. Whether a session is sampled, is dependent on the `profileSessionSampleRate` and the + * existing sampling configuration for tracing (`tracesSampleRate`/`tracesSampler`). + * + * @default 'manual' + */ + profileLifecycle?: 'manual' | 'trace'; +}; diff --git a/packages/core/src/types/checkin.ts b/packages/core/src/types/checkin.ts new file mode 100644 index 000000000000..6d25998099ad --- /dev/null +++ b/packages/core/src/types/checkin.ts @@ -0,0 +1,113 @@ +import type { TraceContext } from './context'; + +interface CrontabSchedule { + type: 'crontab'; + /** The crontab schedule string, e.g. 0 * * * *. */ + value: string; +} + +interface IntervalSchedule { + type: 'interval'; + value: number; + unit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute'; +} + +type MonitorSchedule = CrontabSchedule | IntervalSchedule; + +export interface SerializedCheckIn { + /** Check-In ID (unique and client generated). */ + check_in_id: string; + /** The distinct slug of the monitor. */ + monitor_slug: string; + /** The status of the check-in. */ + status: 'in_progress' | 'ok' | 'error'; + /** The duration of the check-in in seconds. Will only take effect if the status is ok or error. */ + duration?: number; + release?: string; + environment?: string; + monitor_config?: { + schedule: MonitorSchedule; + /** + * The allowed allowed margin of minutes after the expected check-in time that + * the monitor will not be considered missed for. + */ + checkin_margin?: number; + /** + * The allowed allowed duration in minutes that the monitor may be `in_progress` + * for before being considered failed due to timeout. + */ + max_runtime?: number; + /** + * A tz database string representing the timezone which the monitor's execution schedule is in. + * See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + */ + timezone?: string; + /** How many consecutive failed check-ins it takes to create an issue. */ + failure_issue_threshold?: number; + /** How many consecutive OK check-ins it takes to resolve an issue. */ + recovery_threshold?: number; + }; + contexts?: { + trace?: TraceContext; + }; +} + +export interface HeartbeatCheckIn { + /** The distinct slug of the monitor. */ + monitorSlug: SerializedCheckIn['monitor_slug']; + /** The status of the check-in. */ + status: 'ok' | 'error'; +} + +export interface InProgressCheckIn { + /** The distinct slug of the monitor. */ + monitorSlug: SerializedCheckIn['monitor_slug']; + /** The status of the check-in. */ + status: 'in_progress'; +} + +export interface FinishedCheckIn { + /** The distinct slug of the monitor. */ + monitorSlug: SerializedCheckIn['monitor_slug']; + /** The status of the check-in. */ + status: 'ok' | 'error'; + /** Check-In ID (unique and client generated). */ + checkInId: SerializedCheckIn['check_in_id']; + /** The duration of the check-in in seconds. Will only take effect if the status is ok or error. */ + duration?: SerializedCheckIn['duration']; +} + +export type CheckIn = HeartbeatCheckIn | InProgressCheckIn | FinishedCheckIn; + +type SerializedMonitorConfig = NonNullable; + +export interface MonitorConfig { + /** + * The schedule on which the monitor should run. Either a crontab schedule string or an interval. + */ + schedule: MonitorSchedule; + /** + * The allowed allowed margin of minutes after the expected check-in time that + * the monitor will not be considered missed for. + */ + checkinMargin?: SerializedMonitorConfig['checkin_margin']; + /** + * The allowed allowed duration in minutes that the monitor may be `in_progress` + * for before being considered failed due to timeout. + */ + maxRuntime?: SerializedMonitorConfig['max_runtime']; + /** + * A tz database string representing the timezone which the monitor's execution schedule is in. + * See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones + */ + timezone?: SerializedMonitorConfig['timezone']; + /** How many consecutive failed check-ins it takes to create an issue. */ + failureIssueThreshold?: SerializedMonitorConfig['failure_issue_threshold']; + /** How many consecutive OK check-ins it takes to resolve an issue. */ + recoveryThreshold?: SerializedMonitorConfig['recovery_threshold']; + /** + * If set to true, creates a new trace for the monitor callback instead of continuing the current trace. + * This allows distinguishing between different cron job executions. + */ + isolateTrace?: boolean; +} diff --git a/packages/core/src/types/clientreport.ts b/packages/core/src/types/clientreport.ts new file mode 100644 index 000000000000..154b58c5705e --- /dev/null +++ b/packages/core/src/types/clientreport.ts @@ -0,0 +1,26 @@ +import type { DataCategory } from './datacategory'; + +export type EventDropReason = + | 'before_send' + | 'event_processor' + | 'network_error' + | 'queue_overflow' + | 'ratelimit_backoff' + | 'sample_rate' + | 'send_error' + | 'internal_sdk_error' + | 'buffer_overflow' + | 'ignored' + | 'invalid' + | 'no_parent_span'; + +export type Outcome = { + reason: EventDropReason; + category: DataCategory; + quantity: number; +}; + +export type ClientReport = { + timestamp: number; + discarded_events: Outcome[]; +}; diff --git a/packages/core/src/types/context.ts b/packages/core/src/types/context.ts new file mode 100644 index 000000000000..9e52ff9d6834 --- /dev/null +++ b/packages/core/src/types/context.ts @@ -0,0 +1,141 @@ +import type { FeatureFlag } from '../utils/featureFlags'; +import type { SpanLinkJSON } from './link'; +import type { Primitive } from './misc'; +import type { SpanOrigin } from './span'; + +export type Context = Record; + +export interface Contexts extends Record { + app?: AppContext; + device?: DeviceContext; + os?: OsContext; + culture?: CultureContext; + response?: ResponseContext; + trace?: TraceContext; + cloud_resource?: CloudResourceContext; + state?: StateContext; + profile?: ProfileContext; + flags?: FeatureFlagContext; +} + +export interface StateContext extends Record { + state: { + type: string; + value: Record; + }; +} + +export interface AppContext extends Record { + app_name?: string; + app_start_time?: string; + app_version?: string; + app_identifier?: string; + build_type?: string; + app_memory?: number; + free_memory?: number; +} + +export interface DeviceContext extends Record { + name?: string; + family?: string; + model?: string; + model_id?: string; + arch?: string; + battery_level?: number; + orientation?: 'portrait' | 'landscape'; + manufacturer?: string; + brand?: string; + screen_resolution?: string; + screen_height_pixels?: number; + screen_width_pixels?: number; + screen_density?: number; + screen_dpi?: number; + online?: boolean; + charging?: boolean; + low_memory?: boolean; + simulator?: boolean; + memory_size?: number; + free_memory?: number; + usable_memory?: number; + storage_size?: number; + free_storage?: number; + external_storage_size?: number; + external_free_storage?: number; + boot_time?: string; + processor_count?: number; + cpu_description?: string; + processor_frequency?: number; + device_type?: string; + battery_status?: string; + device_unique_identifier?: string; + supports_vibration?: boolean; + supports_accelerometer?: boolean; + supports_gyroscope?: boolean; + supports_audio?: boolean; + supports_location_service?: boolean; +} + +export interface OsContext extends Record { + name?: string; + version?: string; + build?: string; + kernel_version?: string; +} + +export interface CultureContext extends Record { + calendar?: string; + display_name?: string; + locale?: string; + is_24_hour_format?: boolean; + timezone?: string; +} + +export interface ResponseContext extends Record { + type?: string; + cookies?: string[][] | Record; + headers?: Record; + status_code?: number; + body_size?: number; // in bytes +} + +export interface TraceContext extends Record { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data?: { [key: string]: any }; + op?: string; + parent_span_id?: string; + span_id: string; + status?: string; + tags?: { [key: string]: Primitive }; + trace_id: string; + origin?: SpanOrigin; + links?: SpanLinkJSON[]; +} + +export interface CloudResourceContext extends Record { + ['cloud.provider']?: string; + ['cloud.account.id']?: string; + ['cloud.region']?: string; + ['cloud.availability_zone']?: string; + ['cloud.platform']?: string; + ['host.id']?: string; + ['host.type']?: string; +} + +export interface ProfileContext extends Record { + profile_id: string; +} + +export interface MissingInstrumentationContext extends Record { + package: string; + ['javascript.is_cjs']?: boolean; +} + +/** + * Used to buffer flag evaluation data on the current scope and attach it to + * error events. `values` should be initialized as empty ([]), and modifying + * directly is not recommended. Use the functions in @sentry/browser + * src/utils/featureFlags instead. + */ +export interface FeatureFlagContext extends Record { + values: FeatureFlag[]; +} diff --git a/packages/core/src/types/csp.ts b/packages/core/src/types/csp.ts new file mode 100644 index 000000000000..d1c49be6b858 --- /dev/null +++ b/packages/core/src/types/csp.ts @@ -0,0 +1,15 @@ +export interface LegacyCSPReport { + readonly 'csp-report': { + readonly 'document-uri'?: string; + readonly referrer?: string; + readonly 'blocked-uri'?: string; + readonly 'effective-directive'?: string; + readonly 'violated-directive'?: string; + readonly 'original-policy'?: string; + readonly disposition: 'enforce' | 'report' | 'reporting'; + readonly 'status-code'?: number; + readonly status?: string; + readonly 'script-sample'?: string; + readonly sample?: string; + }; +} diff --git a/packages/core/src/types/datacategory.ts b/packages/core/src/types/datacategory.ts new file mode 100644 index 000000000000..ad1e61732816 --- /dev/null +++ b/packages/core/src/types/datacategory.ts @@ -0,0 +1,38 @@ +// This type is used in various places like Client Reports and Rate Limit Categories +// See: +// - https://develop.sentry.dev/sdk/rate-limiting/#definitions +// - https://github.com/getsentry/relay/blob/ec791fed9c2260688f25ea6a6d53ab913927e9a5/relay-base-schema/src/data_category.rs#L91 +// - https://develop.sentry.dev/sdk/client-reports/#envelope-item-payload under `discarded_events` +export type DataCategory = + // Reserved and only used in edgecases, unlikely to be ever actually used + | 'default' + // Error events + | 'error' + // Transaction type event + | 'transaction' + // Replay type event + | 'replay' + // Events with `event_type` csp, hpkp, expectct, expectstaple + | 'security' + // Attachment bytes stored (unused for rate limiting) + | 'attachment' + // Session update events + | 'session' + // SDK internal event, like client_reports + | 'internal' + // Profile event type + | 'profile' + // Check-in event (monitor) + | 'monitor' + // Feedback type event (v2) + | 'feedback' + // Span + | 'span' + // Log event + | 'log_item' + // Log bytes stored (unused for rate limiting) + | 'log_byte' + // Metric event + | 'metric' + // Unknown data category + | 'unknown'; diff --git a/packages/core/src/types/datacollection.ts b/packages/core/src/types/datacollection.ts new file mode 100644 index 000000000000..5a46462fd25e --- /dev/null +++ b/packages/core/src/types/datacollection.ts @@ -0,0 +1,72 @@ +/** + * Controls how key-value data (headers, cookies, query params) is collected and filtered. + * + * - `true`: Collect all data without filtering (empty denylist). Senstive values like keys and tokens are always filtered out. + * - `false`: Do not collect any data. + * - `{ allow: string[] }`: Collect only the specified keys. + * - `{ deny: string[] }`: Collect all keys except the specified ones. + */ +export type CollectBehavior = boolean | { allow: string[] } | { deny: string[] }; + +export type HttpBodyCollectionTarget = 'incomingRequest' | 'outgoingRequest' | 'incomingResponse' | 'outgoingResponse'; + +/** + * Controls what data the SDK collects and sends to Sentry. + * + * All fields are optional. Omitted fields use the documented defaults. + */ +export interface DataCollection { + /** + * Automatically populate `user.*` fields from instrumentation sources. + * @default false + */ + userInfo?: boolean; + + /** + * Controls cookie collection and sensitive value filtering. + * @default true + */ + cookies?: CollectBehavior; + + /** + * Controls HTTP header collection for requests and responses. + * @default { request: true, response: true } + */ + httpHeaders?: { + request?: CollectBehavior; + response?: CollectBehavior; + }; + + /** + * Which HTTP body types to collect. An empty array disables body collection. + * @default [] + */ + httpBodies?: HttpBodyCollectionTarget[]; + + /** + * Controls query parameter collection and sensitive value filtering. + * @default true + */ + queryParams?: CollectBehavior; + + /** + * Controls generative AI input/output recording. + * @default { inputs: true, outputs: true } + */ + genAI?: { + inputs?: boolean; + outputs?: boolean; + }; + + /** + * Capture local variable values in stack frames. + * @default true + */ + stackFrameVariables?: boolean; + + /** + * Number of source code context lines to capture around stack frames. + * @default 5 + */ + frameContextLines?: number; +} diff --git a/packages/core/src/types/debugMeta.ts b/packages/core/src/types/debugMeta.ts new file mode 100644 index 000000000000..44ada6fd0e86 --- /dev/null +++ b/packages/core/src/types/debugMeta.ts @@ -0,0 +1,30 @@ +/** + * Holds meta information to customize the behavior of Sentry's server-side event processing. + **/ +export interface DebugMeta { + images?: Array; +} + +export type DebugImage = WasmDebugImage | SourceMapDebugImage | MachoDebugImage; + +interface WasmDebugImage { + type: 'wasm'; + debug_id: string; + code_id?: string | null; + code_file: string; + debug_file?: string | null; +} + +interface SourceMapDebugImage { + type: 'sourcemap'; + code_file: string; // filename + debug_id: string; // uuid +} + +interface MachoDebugImage { + type: 'macho'; + debug_id: string; + image_addr: string; + image_size?: number; + code_file?: string; +} diff --git a/packages/core/src/types/dsn.ts b/packages/core/src/types/dsn.ts new file mode 100644 index 000000000000..761c52889caf --- /dev/null +++ b/packages/core/src/types/dsn.ts @@ -0,0 +1,23 @@ +/** Supported Sentry transport protocols in a Dsn. */ +export type DsnProtocol = 'http' | 'https'; + +/** Primitive components of a Dsn. */ +export interface DsnComponents { + /** Protocol used to connect to Sentry. */ + protocol: DsnProtocol; + /** Public authorization key. */ + publicKey?: string; + /** Private authorization key (deprecated, optional). */ + pass?: string; + /** Hostname of the Sentry instance. */ + host: string; + /** Port of the Sentry instance. */ + port?: string; + /** Sub path/ */ + path?: string; + /** Project ID */ + projectId: string; +} + +/** Anything that can be parsed into a Dsn. */ +export type DsnLike = string | DsnComponents; diff --git a/packages/core/src/types/envelope.ts b/packages/core/src/types/envelope.ts new file mode 100644 index 000000000000..8937c699a333 --- /dev/null +++ b/packages/core/src/types/envelope.ts @@ -0,0 +1,182 @@ +import type { AttachmentType } from './attachment'; +import type { SerializedCheckIn } from './checkin'; +import type { ClientReport } from './clientreport'; +import type { LegacyCSPReport } from './csp'; +import type { DsnComponents } from './dsn'; +import type { Event } from './event'; +import type { FeedbackEvent, UserFeedback } from './feedback'; +import type { SerializedLogContainer } from './log'; +import type { SerializedMetricContainer } from './metric'; +import type { Profile, ProfileChunk } from './profiling'; +import type { ReplayEvent, ReplayRecordingData } from './replay'; +import type { SdkInfo } from './sdkinfo'; +import type { SerializedSession, SessionAggregates } from './session'; +import type { SerializedStreamedSpanContainer, SpanJSON } from './span'; + +// Based on: https://develop.sentry.dev/sdk/envelopes/ + +// Based on https://github.com/getsentry/relay/blob/b23b8d3b2360a54aaa4d19ecae0231201f31df5e/relay-sampling/src/lib.rs#L685-L707 +export type DynamicSamplingContext = { + trace_id: string; + public_key: DsnComponents['publicKey']; + sample_rate?: string; + release?: string; + environment?: string; + transaction?: string; + replay_id?: string; + sampled?: string; + sample_rand?: string; + org_id?: string; +}; + +// https://github.com/getsentry/relay/blob/311b237cd4471042352fa45e7a0824b8995f216f/relay-server/src/envelope.rs#L154 +// https://develop.sentry.dev/sdk/envelopes/#data-model +export type EnvelopeItemType = + | 'client_report' + | 'user_report' + | 'feedback' + | 'session' + | 'sessions' + | 'transaction' + | 'attachment' + | 'event' + | 'profile' + | 'profile_chunk' + | 'replay_event' + | 'replay_recording' + | 'check_in' + | 'span' + | 'log' + | 'metric' + | 'trace_metric' + | 'raw_security'; + +export type BaseEnvelopeHeaders = { + [key: string]: unknown; + dsn?: string; + sdk?: SdkInfo; +}; + +export type BaseEnvelopeItemHeaders = { + [key: string]: unknown; + type: EnvelopeItemType; + length?: number; +}; + +type BaseEnvelopeItem = [ItemHeader & BaseEnvelopeItemHeaders, P]; // P is for payload + +type BaseEnvelope = [ + EnvelopeHeader & BaseEnvelopeHeaders, + Array>, +]; + +type EventItemHeaders = { + type: 'event' | 'transaction' | 'profile' | 'feedback'; +}; +type AttachmentItemHeaders = { + type: 'attachment'; + length: number; + filename: string; + content_type?: string; + attachment_type?: AttachmentType; +}; +type UserFeedbackItemHeaders = { type: 'user_report' }; +type FeedbackItemHeaders = { type: 'feedback' }; +type SessionItemHeaders = { type: 'session' }; +type SessionAggregatesItemHeaders = { type: 'sessions' }; +type ClientReportItemHeaders = { type: 'client_report' }; +type ReplayEventItemHeaders = { type: 'replay_event' }; +type ReplayRecordingItemHeaders = { type: 'replay_recording'; length: number }; +type CheckInItemHeaders = { type: 'check_in' }; +type ProfileItemHeaders = { type: 'profile' }; +type ProfileChunkItemHeaders = { type: 'profile_chunk' }; +type SpanItemHeaders = { type: 'span' }; +type SpanContainerItemHeaders = { + /** + * Same as v1 span item type but this envelope is distinguished by {@link SpanContainerItemHeaders.content_type}. + */ + type: 'span'; + /** + * The number of span items in the container. This must be the same as the number of span items in the payload. + */ + item_count: number; + /** + * The content type of the span items. This must be `application/vnd.sentry.items.span.v2+json`. + * (the presence of this field also distinguishes the span item from the v1 span item) + */ + content_type: 'application/vnd.sentry.items.span.v2+json'; +}; +type LogContainerItemHeaders = { + type: 'log'; + /** + * The number of log items in the container. This must be the same as the number of log items in the payload. + */ + item_count: number; + /** + * The content type of the log items. This must be `application/vnd.sentry.items.log+json`. + */ + content_type: 'application/vnd.sentry.items.log+json'; +}; +type MetricContainerItemHeaders = { + type: 'trace_metric'; + item_count: number; + content_type: 'application/vnd.sentry.items.trace-metric+json'; +}; +type RawSecurityHeaders = { type: 'raw_security'; sentry_release?: string; sentry_environment?: string }; + +export type EventItem = BaseEnvelopeItem; +export type AttachmentItem = BaseEnvelopeItem; +export type UserFeedbackItem = BaseEnvelopeItem; +export type SessionItem = + | BaseEnvelopeItem + | BaseEnvelopeItem; +export type ClientReportItem = BaseEnvelopeItem; +export type CheckInItem = BaseEnvelopeItem; +type ReplayEventItem = BaseEnvelopeItem; +type ReplayRecordingItem = BaseEnvelopeItem; +export type FeedbackItem = BaseEnvelopeItem; +export type ProfileItem = BaseEnvelopeItem; +export type ProfileChunkItem = BaseEnvelopeItem; +export type SpanItem = BaseEnvelopeItem>; +export type SpanContainerItem = BaseEnvelopeItem; +export type LogContainerItem = BaseEnvelopeItem; +export type MetricContainerItem = BaseEnvelopeItem; +export type RawSecurityItem = BaseEnvelopeItem; + +export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: Partial }; +type SessionEnvelopeHeaders = { sent_at: string }; +type CheckInEnvelopeHeaders = { trace?: DynamicSamplingContext }; +type ClientReportEnvelopeHeaders = BaseEnvelopeHeaders; +type ReplayEnvelopeHeaders = BaseEnvelopeHeaders; +type SpanEnvelopeHeaders = BaseEnvelopeHeaders & { trace?: DynamicSamplingContext }; +type StreamedSpanEnvelopeHeaders = BaseEnvelopeHeaders & { trace?: DynamicSamplingContext }; +type LogEnvelopeHeaders = BaseEnvelopeHeaders; +type MetricEnvelopeHeaders = BaseEnvelopeHeaders; +export type EventEnvelope = BaseEnvelope< + EventEnvelopeHeaders, + EventItem | AttachmentItem | UserFeedbackItem | FeedbackItem | ProfileItem | SpanContainerItem +>; +export type SessionEnvelope = BaseEnvelope; +export type ClientReportEnvelope = BaseEnvelope; +export type ReplayEnvelope = [ReplayEnvelopeHeaders, [ReplayEventItem, ReplayRecordingItem]]; +export type CheckInEnvelope = BaseEnvelope; +export type SpanEnvelope = BaseEnvelope; +export type StreamedSpanEnvelope = BaseEnvelope; +export type ProfileChunkEnvelope = BaseEnvelope; +export type RawSecurityEnvelope = BaseEnvelope; +export type LogEnvelope = BaseEnvelope; +export type MetricEnvelope = BaseEnvelope; + +export type Envelope = + | EventEnvelope + | SessionEnvelope + | ClientReportEnvelope + | ProfileChunkEnvelope + | ReplayEnvelope + | CheckInEnvelope + | SpanEnvelope + | StreamedSpanEnvelope + | RawSecurityEnvelope + | LogEnvelope + | MetricEnvelope; +export type EnvelopeItem = Envelope[1][number]; diff --git a/packages/core/src/types/error.ts b/packages/core/src/types/error.ts new file mode 100644 index 000000000000..ca92b924b933 --- /dev/null +++ b/packages/core/src/types/error.ts @@ -0,0 +1,8 @@ +/** + * Just an Error object with arbitrary attributes attached to it. + */ +export interface ExtendedError extends Error { + // TODO: fix in v11, convert any to unknown + // eslint-disable-next-line @typescript-eslint/no-explicit-any + [key: string]: any; +} diff --git a/packages/core/src/types/event.ts b/packages/core/src/types/event.ts new file mode 100644 index 000000000000..6b333bd2388e --- /dev/null +++ b/packages/core/src/types/event.ts @@ -0,0 +1,89 @@ +import type { CaptureContext, SdkProcessingMetadata } from '../scope'; +import type { Attachment } from './attachment'; +import type { Breadcrumb } from './breadcrumb'; +import type { Contexts } from './context'; +import type { DebugMeta } from './debugMeta'; +import type { Exception } from './exception'; +import type { Extras } from './extra'; +import type { Measurements } from './measurement'; +import type { Mechanism } from './mechanism'; +import type { Primitive } from './misc'; +import type { RequestEventData } from './request'; +import type { SdkInfo } from './sdkinfo'; +import type { SeverityLevel } from './severity'; +import type { SpanJSON } from './span'; +import type { Thread } from './thread'; +import type { TransactionSource } from './transaction'; +import type { User } from './user'; + +/** An event to be sent to Sentry. */ +export interface Event { + event_id?: string; + message?: string; + logentry?: { + message?: string; + params?: unknown[]; + }; + timestamp?: number; + start_timestamp?: number; + level?: SeverityLevel; + platform?: string; + logger?: string; + server_name?: string; + release?: string; + dist?: string; + environment?: string; + sdk?: SdkInfo; + request?: RequestEventData; + transaction?: string; + modules?: { [key: string]: string }; + fingerprint?: string[]; + exception?: { + values?: Exception[]; + }; + breadcrumbs?: Breadcrumb[]; + contexts?: Contexts; + tags?: { [key: string]: Primitive }; + extra?: Extras; + user?: User; + type?: EventType; + spans?: SpanJSON[]; + measurements?: Measurements; + debug_meta?: DebugMeta; + // A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get sent to Sentry + // Note: This is considered internal and is subject to change in minors + sdkProcessingMetadata?: SdkProcessingMetadata; + transaction_info?: { + source: TransactionSource; + }; + threads?: { + values: Thread[]; + }; +} + +/** + * The type of an `Event`. + * Note that `ErrorEvent`s do not have a type (hence its undefined), + * while all other events are required to have one. + */ +export type EventType = 'transaction' | 'profile' | 'replay_event' | 'feedback' | undefined; + +export interface ErrorEvent extends Event { + type: undefined; +} +export interface TransactionEvent extends Event { + type: 'transaction'; +} + +/** JSDoc */ +export interface EventHint { + event_id?: string; + captureContext?: CaptureContext; + mechanism?: Partial; + syntheticException?: Error | null; + originalException?: unknown; + attachments?: Attachment[]; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + data?: any; + integrations?: string[]; +} diff --git a/packages/core/src/types/eventprocessor.ts b/packages/core/src/types/eventprocessor.ts new file mode 100644 index 000000000000..54177388cdde --- /dev/null +++ b/packages/core/src/types/eventprocessor.ts @@ -0,0 +1,12 @@ +import type { Event, EventHint } from './event'; + +/** + * Event processors are used to change the event before it will be sent. + * We strongly advise to make this function sync. + * Returning a PromiseLike will work just fine, but better be sure that you know what you are doing. + * Event processing will be deferred until your Promise is resolved. + */ +export interface EventProcessor { + (event: Event, hint: EventHint): PromiseLike | Event | null; + id?: string; // This field can't be named "name" because functions already have this field natively +} diff --git a/packages/core/src/types/exception.ts b/packages/core/src/types/exception.ts new file mode 100644 index 000000000000..27b320363a82 --- /dev/null +++ b/packages/core/src/types/exception.ts @@ -0,0 +1,12 @@ +import type { Mechanism } from './mechanism'; +import type { Stacktrace } from './stacktrace'; + +/** JSDoc */ +export interface Exception { + type?: string; + value?: string; + mechanism?: Mechanism; + module?: string; + thread_id?: number | string; + stacktrace?: Stacktrace; +} diff --git a/packages/core/src/types/extra.ts b/packages/core/src/types/extra.ts new file mode 100644 index 000000000000..077eb4a226bb --- /dev/null +++ b/packages/core/src/types/extra.ts @@ -0,0 +1,2 @@ +export type Extra = unknown; +export type Extras = Record; diff --git a/packages/core/src/types/feedback/config.ts b/packages/core/src/types/feedback/config.ts new file mode 100644 index 000000000000..5d7db7636996 --- /dev/null +++ b/packages/core/src/types/feedback/config.ts @@ -0,0 +1,251 @@ +import type { Primitive } from '../misc'; +import type { FeedbackFormData } from './form'; +import type { FeedbackTheme } from './theme'; + +/** + * General feedback configuration + */ +export interface FeedbackGeneralConfiguration { + /** + * id to use for the main widget container (this will host the shadow DOM) + */ + id: string; + + /** + * Show the Sentry branding + */ + showBranding: boolean; + + /** + * Auto-inject default Feedback actor button to the DOM when integration is + * added. + */ + autoInject: boolean; + + /** + * Should the email field be required? + */ + isEmailRequired: boolean; + + /** + * Should the name field be required? + */ + isNameRequired: boolean; + + /** + * Should the email input field be visible? Note: email will still be collected if set via `Sentry.setUser()` + */ + showEmail: boolean; + + /** + * Should the name input field be visible? Note: name will still be collected if set via `Sentry.setUser()` + */ + showName: boolean; + + /** + * Should the screen shots field be included? + * Screen shots cannot be marked as required + */ + enableScreenshot: boolean; + + /** + * Fill in email/name input fields with Sentry user context if it exists. + * The value of the email/name keys represent the properties of your user context. + */ + useSentryUser: { + email: string; + name: string; + }; + + /** + * Set an object that will be merged sent as tags data with the event. + */ + tags?: { [key: string]: Primitive }; + + /** + * Set a nonce to be passed to the injected