diff --git a/packages/tracing/src/span.ts b/packages/tracing/src/span.ts index 43fbef08f623..be070c0cbfa3 100644 --- a/packages/tracing/src/span.ts +++ b/packages/tracing/src/span.ts @@ -1,5 +1,5 @@ /* eslint-disable max-lines */ -import { Instrumenter, Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types'; +import { Instrumenter, Primitive, Span as SpanInterface, SpanContext, TraceContext, Transaction } from '@sentry/types'; import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils'; /** @@ -305,17 +305,7 @@ export class Span implements SpanInterface { /** * @inheritDoc */ - public getTraceContext(): { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - data?: { [key: string]: any }; - description?: string; - op?: string; - parent_span_id?: string; - span_id: string; - status?: string; - tags?: { [key: string]: Primitive }; - trace_id: string; - } { + public getTraceContext(): TraceContext { return dropUndefinedKeys({ data: Object.keys(this.data).length > 0 ? this.data : undefined, description: this.description, diff --git a/packages/types/src/context.ts b/packages/types/src/context.ts index 3a342373c3fe..120bd82cda9d 100644 --- a/packages/types/src/context.ts +++ b/packages/types/src/context.ts @@ -1,3 +1,5 @@ +import { Primitive } from './misc'; + export type Context = Record; export interface Contexts extends Record { @@ -79,3 +81,14 @@ export interface ResponseContext extends Record { status_code?: number; body_size?: number; // in bytes } + +export interface TraceContext extends Record { + data?: { [key: string]: any }; + description?: string; + op?: string; + parent_span_id?: string; + span_id: string; + status?: string; + tags?: { [key: string]: Primitive }; + trace_id: string; +} diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index a3437df77f1f..0b52fac74e02 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -2,7 +2,7 @@ export type { Attachment } from './attachment'; export type { Breadcrumb, BreadcrumbHint } from './breadcrumb'; export type { Client } from './client'; export type { ClientReport, Outcome, EventDropReason } from './clientreport'; -export type { Context, Contexts, DeviceContext, OsContext, AppContext, CultureContext } from './context'; +export type { Context, Contexts, DeviceContext, OsContext, AppContext, CultureContext, TraceContext } from './context'; export type { DataCategory } from './datacategory'; export type { DsnComponents, DsnLike, DsnProtocol } from './dsn'; export type { DebugImage, DebugImageType, DebugMeta } from './debugMeta';