From 8c7e2d06cf9a6135fe69ed0a46bf1ef21a4d0af0 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 30 Dec 2024 12:08:41 +0100 Subject: [PATCH] feat(core)!: Type sdkProcessingMetadata more strictly --- packages/core/src/scope.ts | 13 ++++++++++--- packages/core/src/types-hoist/event.ts | 13 ++----------- packages/core/src/types-hoist/request.ts | 6 +++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index 3f66d2053b34..d4fcd1e27743 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -5,13 +5,16 @@ import type { Client, Context, Contexts, + DynamicSamplingContext, Event, EventHint, EventProcessor, Extra, Extras, + PolymorphicRequest, Primitive, PropagationContext, + RequestEventData, Session, SeverityLevel, Span, @@ -58,6 +61,12 @@ export interface SdkProcessingMetadata { requestSession?: { status: 'ok' | 'errored' | 'crashed'; }; + request?: PolymorphicRequest; + normalizedRequest?: RequestEventData; + dynamicSamplingContext?: Partial; + capturedSpanScope?: Scope; + capturedSpanIsolationScope?: Scope; + spanCountBeforeProcessing?: number; } /** @@ -537,10 +546,8 @@ export class Scope { /** * Add data which will be accessible during event processing but won't get sent to Sentry. - * - * TODO(v9): We should type this stricter, so that e.g. `normalizedRequest` is strictly typed. */ - public setSDKProcessingMetadata(newData: { [key: string]: unknown }): this { + public setSDKProcessingMetadata(newData: SdkProcessingMetadata): this { this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2); return this; } diff --git a/packages/core/src/types-hoist/event.ts b/packages/core/src/types-hoist/event.ts index 69d6776a54ac..5b4d87337236 100644 --- a/packages/core/src/types-hoist/event.ts +++ b/packages/core/src/types-hoist/event.ts @@ -1,15 +1,13 @@ -import type { CaptureContext, Scope } from '../scope'; +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 { DynamicSamplingContext } from './envelope'; 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 { PolymorphicRequest } from './polymorphics'; import type { RequestEventData } from './request'; import type { SdkInfo } from './sdkinfo'; import type { SeverityLevel } from './severity'; @@ -54,14 +52,7 @@ export interface Event { 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?: { [key: string]: unknown } & { - request?: PolymorphicRequest; - normalizedRequest?: RequestEventData; - dynamicSamplingContext?: Partial; - capturedSpanScope?: Scope; - capturedSpanIsolationScope?: Scope; - spanCountBeforeProcessing?: number; - }; + sdkProcessingMetadata?: SdkProcessingMetadata; transaction_info?: { source: TransactionSource; }; diff --git a/packages/core/src/types-hoist/request.ts b/packages/core/src/types-hoist/request.ts index 6ba060219dfd..4db44c190a9e 100644 --- a/packages/core/src/types-hoist/request.ts +++ b/packages/core/src/types-hoist/request.ts @@ -4,10 +4,10 @@ export interface RequestEventData { url?: string; method?: string; - data?: any; + data?: unknown; query_string?: QueryParams; - cookies?: { [key: string]: string }; - env?: { [key: string]: string }; + cookies?: Record; + env?: Record; headers?: { [key: string]: string }; }