diff --git a/packages/core/src/types-hoist/envelope.ts b/packages/core/src/types-hoist/envelope.ts index 5a54ffc7b8c2..d78cccc8384a 100644 --- a/packages/core/src/types-hoist/envelope.ts +++ b/packages/core/src/types-hoist/envelope.ts @@ -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'; @@ -43,6 +44,7 @@ export type EnvelopeItemType = | 'replay_recording' | 'check_in' | 'span' + | 'otel_log' | 'raw_security'; export type BaseEnvelopeHeaders = { @@ -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; @@ -101,6 +104,7 @@ export type FeedbackItem = BaseEnvelopeItem; export type ProfileItem = BaseEnvelopeItem; export type ProfileChunkItem = BaseEnvelopeItem; export type SpanItem = BaseEnvelopeItem>; +export type LogItem = BaseEnvelopeItem; export type RawSecurityItem = BaseEnvelopeItem; export type EventEnvelopeHeaders = { event_id: string; sent_at: string; trace?: Partial }; @@ -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, @@ -121,6 +126,7 @@ export type CheckInEnvelope = BaseEnvelope; export type SpanEnvelope = BaseEnvelope; export type ProfileChunkEnvelope = BaseEnvelope; export type RawSecurityEnvelope = BaseEnvelope; +export type LogEnvelope = BaseEnvelope; export type Envelope = | EventEnvelope @@ -130,6 +136,7 @@ export type Envelope = | ReplayEnvelope | CheckInEnvelope | SpanEnvelope - | RawSecurityEnvelope; + | RawSecurityEnvelope + | LogEnvelope; export type EnvelopeItem = Envelope[1][number]; diff --git a/packages/core/src/types-hoist/index.ts b/packages/core/src/types-hoist/index.ts index 524856d514c9..95bc5fc55bd4 100644 --- a/packages/core/src/types-hoist/index.ts +++ b/packages/core/src/types-hoist/index.ts @@ -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'; diff --git a/packages/core/src/types-hoist/log.ts b/packages/core/src/types-hoist/log.ts new file mode 100644 index 000000000000..45df68008315 --- /dev/null +++ b/packages/core/src/types-hoist/log.ts @@ -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; +} diff --git a/packages/core/src/utils-hoist/envelope.ts b/packages/core/src/utils-hoist/envelope.ts index 46512850cefc..9655f9312579 100644 --- a/packages/core/src/utils-hoist/envelope.ts +++ b/packages/core/src/utils-hoist/envelope.ts @@ -223,6 +223,7 @@ const ITEM_TYPE_TO_DATA_CATEGORY_MAP: Record = { feedback: 'feedback', span: 'span', raw_security: 'security', + otel_log: 'log_item', }; /**