Skip to content

Commit e332ae1

Browse files
authored
feat(types): Add Trace Context type (#6714)
1 parent 9bd6296 commit e332ae1

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

packages/tracing/src/span.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines */
2-
import { Instrumenter, Primitive, Span as SpanInterface, SpanContext, Transaction } from '@sentry/types';
2+
import { Instrumenter, Primitive, Span as SpanInterface, SpanContext, TraceContext, Transaction } from '@sentry/types';
33
import { dropUndefinedKeys, logger, timestampWithMs, uuid4 } from '@sentry/utils';
44

55
/**
@@ -305,17 +305,7 @@ export class Span implements SpanInterface {
305305
/**
306306
* @inheritDoc
307307
*/
308-
public getTraceContext(): {
309-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
310-
data?: { [key: string]: any };
311-
description?: string;
312-
op?: string;
313-
parent_span_id?: string;
314-
span_id: string;
315-
status?: string;
316-
tags?: { [key: string]: Primitive };
317-
trace_id: string;
318-
} {
308+
public getTraceContext(): TraceContext {
319309
return dropUndefinedKeys({
320310
data: Object.keys(this.data).length > 0 ? this.data : undefined,
321311
description: this.description,

packages/types/src/context.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Primitive } from './misc';
2+
13
export type Context = Record<string, unknown>;
24

35
export interface Contexts extends Record<string, Context | undefined> {
@@ -79,3 +81,14 @@ export interface ResponseContext extends Record<string, unknown> {
7981
status_code?: number;
8082
body_size?: number; // in bytes
8183
}
84+
85+
export interface TraceContext extends Record<string, unknown> {
86+
data?: { [key: string]: any };
87+
description?: string;
88+
op?: string;
89+
parent_span_id?: string;
90+
span_id: string;
91+
status?: string;
92+
tags?: { [key: string]: Primitive };
93+
trace_id: string;
94+
}

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export type { Attachment } from './attachment';
22
export type { Breadcrumb, BreadcrumbHint } from './breadcrumb';
33
export type { Client } from './client';
44
export type { ClientReport, Outcome, EventDropReason } from './clientreport';
5-
export type { Context, Contexts, DeviceContext, OsContext, AppContext, CultureContext } from './context';
5+
export type { Context, Contexts, DeviceContext, OsContext, AppContext, CultureContext, TraceContext } from './context';
66
export type { DataCategory } from './datacategory';
77
export type { DsnComponents, DsnLike, DsnProtocol } from './dsn';
88
export type { DebugImage, DebugImageType, DebugMeta } from './debugMeta';

0 commit comments

Comments
 (0)