From 82cd8608d34cf532cfe0e104d404e490b94f13e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Og=C3=B3rek?= Date: Wed, 30 Sep 2020 15:26:30 +0200 Subject: [PATCH] plz --- packages/apm/src/integrations/tracing.ts | 2 +- packages/hub/src/scope.ts | 6 ++++-- packages/types/src/context.ts | 2 ++ packages/types/src/event.ts | 8 ++++---- packages/types/src/index.ts | 1 + packages/types/src/scope.ts | 5 +++-- 6 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 packages/types/src/context.ts diff --git a/packages/apm/src/integrations/tracing.ts b/packages/apm/src/integrations/tracing.ts index 8bf32092c05c..9eace9e5769b 100644 --- a/packages/apm/src/integrations/tracing.ts +++ b/packages/apm/src/integrations/tracing.ts @@ -853,7 +853,7 @@ export class Tracing implements Integration { Tracing._log(`[Tracing] Transaction: ${SpanStatus.Cancelled} since it maxed out maxTransactionDuration`); if (event.contexts && event.contexts.trace) { event.contexts.trace = { - ...event.contexts.trace, + ...(typeof event.contexts.trace === 'object' && event.contexts.trace), status: SpanStatus.DeadlineExceeded, }; event.tags = { diff --git a/packages/hub/src/scope.ts b/packages/hub/src/scope.ts index 4799f465a7e8..149a117f3f3d 100644 --- a/packages/hub/src/scope.ts +++ b/packages/hub/src/scope.ts @@ -2,6 +2,7 @@ import { Breadcrumb, CaptureContext, + Contexts, Event, EventHint, EventProcessor, @@ -15,6 +16,7 @@ import { User, } from '@sentry/types'; import { getGlobalObject, isPlainObject, isThenable, SyncPromise, timestampWithMs } from '@sentry/utils'; +import { Context } from 'vm'; /** * Holds additional event information. {@link Scope.applyToEvent} will be @@ -43,7 +45,7 @@ export class Scope implements ScopeInterface { protected _extra: Extras = {}; /** Contexts */ - protected _contexts: { [key: string]: Record } = {}; + protected _contexts: Contexts = {}; /** Fingerprint */ protected _fingerprint?: string[]; @@ -183,7 +185,7 @@ export class Scope implements ScopeInterface { /** * @inheritDoc */ - public setContext(key: string, context: Record | null): this { + public setContext(key: string, context: Context | null): this { if (context === null) { // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete this._contexts[key]; diff --git a/packages/types/src/context.ts b/packages/types/src/context.ts new file mode 100644 index 000000000000..438244dd9486 --- /dev/null +++ b/packages/types/src/context.ts @@ -0,0 +1,2 @@ +export type Context = unknown; +export type Contexts = Record; diff --git a/packages/types/src/event.ts b/packages/types/src/event.ts index fc1b4205611b..38e7a6ad5a21 100644 --- a/packages/types/src/event.ts +++ b/packages/types/src/event.ts @@ -1,5 +1,7 @@ import { Breadcrumb } from './breadcrumb'; +import { Contexts } from './context'; import { Exception } from './exception'; +import { Extras } from './extra'; import { Request } from './request'; import { CaptureContext } from './scope'; import { SdkInfo } from './sdkinfo'; @@ -31,11 +33,9 @@ export interface Event { }; stacktrace?: Stacktrace; breadcrumbs?: Breadcrumb[]; - contexts?: { - [key: string]: Record; - }; + contexts?: Contexts; tags?: { [key: string]: string }; - extra?: { [key: string]: any }; + extra?: Extras; user?: User; type?: EventType; spans?: Span[]; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index da4fa2f6129f..98a429e9e455 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,5 +1,6 @@ export { Breadcrumb, BreadcrumbHint } from './breadcrumb'; export { Client } from './client'; +export { Context, Contexts } from './context'; export { Dsn, DsnComponents, DsnLike, DsnProtocol } from './dsn'; export { ExtendedError } from './error'; export { Event, EventHint } from './event'; diff --git a/packages/types/src/scope.ts b/packages/types/src/scope.ts index bea3217826d1..65f282ddce79 100644 --- a/packages/types/src/scope.ts +++ b/packages/types/src/scope.ts @@ -1,4 +1,5 @@ import { Breadcrumb } from './breadcrumb'; +import { Context, Contexts } from './context'; import { EventProcessor } from './eventprocessor'; import { Extra, Extras } from './extra'; import { Severity } from './severity'; @@ -14,7 +15,7 @@ export interface ScopeContext { user: User; level: Severity; extra: Extras; - contexts: { [key: string]: Record }; + contexts: Contexts; tags: { [key: string]: string }; fingerprint: string[]; } @@ -82,7 +83,7 @@ export interface Scope { * @param name of the context * @param context Any kind of data. This data will be normailzed. */ - setContext(name: string, context: Record | null): this; + setContext(name: string, context: Context | null): this; /** * Sets the Span on the scope.