Skip to content

Commit 6f0251d

Browse files
authored
feat(core)!: Type sdkProcessingMetadata more strictly (#14855)
This ensures we use a consistent and proper type for `setSdkProcessingMetadata()` and related APIs. Closes #14341
1 parent 4415881 commit 6f0251d

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

packages/core/src/scope.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ import type {
55
Client,
66
Context,
77
Contexts,
8+
DynamicSamplingContext,
89
Event,
910
EventHint,
1011
EventProcessor,
1112
Extra,
1213
Extras,
14+
PolymorphicRequest,
1315
Primitive,
1416
PropagationContext,
17+
RequestEventData,
1518
Session,
1619
SeverityLevel,
1720
Span,
@@ -58,6 +61,12 @@ export interface SdkProcessingMetadata {
5861
requestSession?: {
5962
status: 'ok' | 'errored' | 'crashed';
6063
};
64+
request?: PolymorphicRequest;
65+
normalizedRequest?: RequestEventData;
66+
dynamicSamplingContext?: Partial<DynamicSamplingContext>;
67+
capturedSpanScope?: Scope;
68+
capturedSpanIsolationScope?: Scope;
69+
spanCountBeforeProcessing?: number;
6170
}
6271

6372
/**
@@ -537,10 +546,8 @@ export class Scope {
537546

538547
/**
539548
* Add data which will be accessible during event processing but won't get sent to Sentry.
540-
*
541-
* TODO(v9): We should type this stricter, so that e.g. `normalizedRequest` is strictly typed.
542549
*/
543-
public setSDKProcessingMetadata(newData: { [key: string]: unknown }): this {
550+
public setSDKProcessingMetadata(newData: SdkProcessingMetadata): this {
544551
this._sdkProcessingMetadata = merge(this._sdkProcessingMetadata, newData, 2);
545552
return this;
546553
}

packages/core/src/types-hoist/event.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import type { CaptureContext, Scope } from '../scope';
1+
import type { CaptureContext, SdkProcessingMetadata } from '../scope';
22
import type { Attachment } from './attachment';
33
import type { Breadcrumb } from './breadcrumb';
44
import type { Contexts } from './context';
55
import type { DebugMeta } from './debugMeta';
6-
import type { DynamicSamplingContext } from './envelope';
76
import type { Exception } from './exception';
87
import type { Extras } from './extra';
98
import type { Measurements } from './measurement';
109
import type { Mechanism } from './mechanism';
1110
import type { Primitive } from './misc';
12-
import type { PolymorphicRequest } from './polymorphics';
1311
import type { RequestEventData } from './request';
1412
import type { SdkInfo } from './sdkinfo';
1513
import type { SeverityLevel } from './severity';
@@ -54,14 +52,7 @@ export interface Event {
5452
debug_meta?: DebugMeta;
5553
// 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
5654
// Note: This is considered internal and is subject to change in minors
57-
sdkProcessingMetadata?: { [key: string]: unknown } & {
58-
request?: PolymorphicRequest;
59-
normalizedRequest?: RequestEventData;
60-
dynamicSamplingContext?: Partial<DynamicSamplingContext>;
61-
capturedSpanScope?: Scope;
62-
capturedSpanIsolationScope?: Scope;
63-
spanCountBeforeProcessing?: number;
64-
};
55+
sdkProcessingMetadata?: SdkProcessingMetadata;
6556
transaction_info?: {
6657
source: TransactionSource;
6758
};

packages/core/src/types-hoist/request.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
export interface RequestEventData {
55
url?: string;
66
method?: string;
7-
data?: any;
7+
data?: unknown;
88
query_string?: QueryParams;
9-
cookies?: { [key: string]: string };
10-
env?: { [key: string]: string };
9+
cookies?: Record<string, string>;
10+
env?: Record<string, string>;
1111
headers?: { [key: string]: string };
1212
}
1313

0 commit comments

Comments
 (0)