Skip to content

Commit

Permalink
feat(core): Add types for logs protocol and envelope (#15530)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Feb 28, 2025
1 parent f024ccf commit d12c192
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/src/types-hoist/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { LegacyCSPReport } from './csp';
import type { DsnComponents } from './dsn';
import type { Event } from './event';
import type { FeedbackEvent, UserFeedback } from './feedback';
import type { Log } from './log';
import type { Profile, ProfileChunk } from './profiling';
import type { ReplayEvent, ReplayRecordingData } from './replay';
import type { SdkInfo } from './sdkinfo';
Expand Down Expand Up @@ -43,6 +44,7 @@ export type EnvelopeItemType =
| 'replay_recording'
| 'check_in'
| 'span'
| 'otel_log'
| 'raw_security';

export type BaseEnvelopeHeaders = {
Expand Down Expand Up @@ -85,6 +87,7 @@ type CheckInItemHeaders = { type: 'check_in' };
type ProfileItemHeaders = { type: 'profile' };
type ProfileChunkItemHeaders = { type: 'profile_chunk' };
type SpanItemHeaders = { type: 'span' };
type LogItemHeaders = { type: 'otel_log' };
type RawSecurityHeaders = { type: 'raw_security'; sentry_release?: string; sentry_environment?: string };

export type EventItem = BaseEnvelopeItem<EventItemHeaders, Event>;
Expand All @@ -101,6 +104,7 @@ export type FeedbackItem = BaseEnvelopeItem<FeedbackItemHeaders, FeedbackEvent>;
export type ProfileItem = BaseEnvelopeItem<ProfileItemHeaders, Profile>;
export type ProfileChunkItem = BaseEnvelopeItem<ProfileChunkItemHeaders, ProfileChunk>;
export type SpanItem = BaseEnvelopeItem<SpanItemHeaders, Partial<SpanJSON>>;
export type LogItem = BaseEnvelopeItem<LogItemHeaders, Log>;
export type RawSecurityItem = BaseEnvelopeItem<RawSecurityHeaders, LegacyCSPReport>;

export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: Partial<DynamicSamplingContext> };
Expand All @@ -109,6 +113,7 @@ type CheckInEnvelopeHeaders = { trace?: DynamicSamplingContext };
type ClientReportEnvelopeHeaders = BaseEnvelopeHeaders;
type ReplayEnvelopeHeaders = BaseEnvelopeHeaders;
type SpanEnvelopeHeaders = BaseEnvelopeHeaders & { trace?: DynamicSamplingContext };
type LogEnvelopeHeaders = BaseEnvelopeHeaders & { trace?: DynamicSamplingContext };

export type EventEnvelope = BaseEnvelope<
EventEnvelopeHeaders,
Expand All @@ -121,6 +126,7 @@ export type CheckInEnvelope = BaseEnvelope<CheckInEnvelopeHeaders, CheckInItem>;
export type SpanEnvelope = BaseEnvelope<SpanEnvelopeHeaders, SpanItem>;
export type ProfileChunkEnvelope = BaseEnvelope<BaseEnvelopeHeaders, ProfileChunkItem>;
export type RawSecurityEnvelope = BaseEnvelope<BaseEnvelopeHeaders, RawSecurityItem>;
export type LogEnvelope = BaseEnvelope<LogEnvelopeHeaders, LogItem>;

export type Envelope =
| EventEnvelope
Expand All @@ -130,6 +136,7 @@ export type Envelope =
| ReplayEnvelope
| CheckInEnvelope
| SpanEnvelope
| RawSecurityEnvelope;
| RawSecurityEnvelope
| LogEnvelope;

export type EnvelopeItem = Envelope[1][number];
1 change: 1 addition & 0 deletions packages/core/src/types-hoist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export type {
TraceFlag,
} from './span';
export type { SpanStatus } from './spanStatus';
export type { Log, LogAttribute, LogSeverityLevel, LogAttributeValueType } from './log';
export type { TimedEvent } from './timedEvent';
export type { StackFrame } from './stackframe';
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';
Expand Down
64 changes: 64 additions & 0 deletions packages/core/src/types-hoist/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
export type LogSeverityLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'critical';

export type LogAttributeValueType =
| {
stringValue: string;
}
| {
intValue: number;
}
| {
boolValue: boolean;
}
| {
doubleValue: number;
};

export type LogAttribute = {
key: string;
value: LogAttributeValueType;
};

export interface Log {
/**
* The severity level of the log.
*
* Allowed values are, from highest to lowest:
* `critical`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`.
*
* The log level changes how logs are filtered and displayed.
* Critical level logs are emphasized more than trace level logs.
*/
severityText?: LogSeverityLevel;

/**
* The severity number - generally higher severity are levels like 'error' and lower are levels like 'debug'
*/
severityNumber?: number;

/**
* The trace ID for this log
*/
traceId?: string;

/**
* The message to be logged - for example, 'hello world' would become a log like '[INFO] hello world'
*/
body: {
stringValue: string;
};

/**
* Arbitrary structured data that stores information about the log - e.g., userId: 100.
*/
attributes?: LogAttribute[];

/**
* This doesn't have to be explicitly specified most of the time. If you need to set it, the value
* is the number of seconds since midnight on January 1, 1970 ("unix epoch time")
*
* @summary A timestamp representing when the log occurred.
* @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#:~:text=is%20info.-,timestamp,-(recommended)
*/
timeUnixNano?: string;
}
1 change: 1 addition & 0 deletions packages/core/src/utils-hoist/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const ITEM_TYPE_TO_DATA_CATEGORY_MAP: Record<EnvelopeItemType, DataCategory> = {
feedback: 'feedback',
span: 'span',
raw_security: 'security',
otel_log: 'log_item',
};

/**
Expand Down

0 comments on commit d12c192

Please sign in to comment.