Skip to content

Commit d12c192

Browse files
authored
feat(core): Add types for logs protocol and envelope (#15530)
ref #15526 Based on the work in #15442, we add definitions for the logs protocol and envelope to the JavaScript SDKs. Relay data category: https://github.com/getsentry/relay/blob/e36886a98c89af645e5c0d2109657deafa25d902/relay-server/src/envelope.rs#L182 Relay log protocol: https://github.com/getsentry/relay/blob/ad04adf6d6756c4e36328c8217bea0ee01f289ec/relay-event-schema/src/protocol/ourlog.rs#L12
1 parent f024ccf commit d12c192

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

packages/core/src/types-hoist/envelope.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { LegacyCSPReport } from './csp';
55
import type { DsnComponents } from './dsn';
66
import type { Event } from './event';
77
import type { FeedbackEvent, UserFeedback } from './feedback';
8+
import type { Log } from './log';
89
import type { Profile, ProfileChunk } from './profiling';
910
import type { ReplayEvent, ReplayRecordingData } from './replay';
1011
import type { SdkInfo } from './sdkinfo';
@@ -43,6 +44,7 @@ export type EnvelopeItemType =
4344
| 'replay_recording'
4445
| 'check_in'
4546
| 'span'
47+
| 'otel_log'
4648
| 'raw_security';
4749

4850
export type BaseEnvelopeHeaders = {
@@ -85,6 +87,7 @@ type CheckInItemHeaders = { type: 'check_in' };
8587
type ProfileItemHeaders = { type: 'profile' };
8688
type ProfileChunkItemHeaders = { type: 'profile_chunk' };
8789
type SpanItemHeaders = { type: 'span' };
90+
type LogItemHeaders = { type: 'otel_log' };
8891
type RawSecurityHeaders = { type: 'raw_security'; sentry_release?: string; sentry_environment?: string };
8992

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

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

113118
export type EventEnvelope = BaseEnvelope<
114119
EventEnvelopeHeaders,
@@ -121,6 +126,7 @@ export type CheckInEnvelope = BaseEnvelope<CheckInEnvelopeHeaders, CheckInItem>;
121126
export type SpanEnvelope = BaseEnvelope<SpanEnvelopeHeaders, SpanItem>;
122127
export type ProfileChunkEnvelope = BaseEnvelope<BaseEnvelopeHeaders, ProfileChunkItem>;
123128
export type RawSecurityEnvelope = BaseEnvelope<BaseEnvelopeHeaders, RawSecurityItem>;
129+
export type LogEnvelope = BaseEnvelope<LogEnvelopeHeaders, LogItem>;
124130

125131
export type Envelope =
126132
| EventEnvelope
@@ -130,6 +136,7 @@ export type Envelope =
130136
| ReplayEnvelope
131137
| CheckInEnvelope
132138
| SpanEnvelope
133-
| RawSecurityEnvelope;
139+
| RawSecurityEnvelope
140+
| LogEnvelope;
134141

135142
export type EnvelopeItem = Envelope[1][number];

packages/core/src/types-hoist/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export type {
110110
TraceFlag,
111111
} from './span';
112112
export type { SpanStatus } from './spanStatus';
113+
export type { Log, LogAttribute, LogSeverityLevel, LogAttributeValueType } from './log';
113114
export type { TimedEvent } from './timedEvent';
114115
export type { StackFrame } from './stackframe';
115116
export type { Stacktrace, StackParser, StackLineParser, StackLineParserFn } from './stacktrace';

packages/core/src/types-hoist/log.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
export type LogSeverityLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal' | 'critical';
2+
3+
export type LogAttributeValueType =
4+
| {
5+
stringValue: string;
6+
}
7+
| {
8+
intValue: number;
9+
}
10+
| {
11+
boolValue: boolean;
12+
}
13+
| {
14+
doubleValue: number;
15+
};
16+
17+
export type LogAttribute = {
18+
key: string;
19+
value: LogAttributeValueType;
20+
};
21+
22+
export interface Log {
23+
/**
24+
* The severity level of the log.
25+
*
26+
* Allowed values are, from highest to lowest:
27+
* `critical`, `fatal`, `error`, `warn`, `info`, `debug`, `trace`.
28+
*
29+
* The log level changes how logs are filtered and displayed.
30+
* Critical level logs are emphasized more than trace level logs.
31+
*/
32+
severityText?: LogSeverityLevel;
33+
34+
/**
35+
* The severity number - generally higher severity are levels like 'error' and lower are levels like 'debug'
36+
*/
37+
severityNumber?: number;
38+
39+
/**
40+
* The trace ID for this log
41+
*/
42+
traceId?: string;
43+
44+
/**
45+
* The message to be logged - for example, 'hello world' would become a log like '[INFO] hello world'
46+
*/
47+
body: {
48+
stringValue: string;
49+
};
50+
51+
/**
52+
* Arbitrary structured data that stores information about the log - e.g., userId: 100.
53+
*/
54+
attributes?: LogAttribute[];
55+
56+
/**
57+
* This doesn't have to be explicitly specified most of the time. If you need to set it, the value
58+
* is the number of seconds since midnight on January 1, 1970 ("unix epoch time")
59+
*
60+
* @summary A timestamp representing when the log occurred.
61+
* @link https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#:~:text=is%20info.-,timestamp,-(recommended)
62+
*/
63+
timeUnixNano?: string;
64+
}

packages/core/src/utils-hoist/envelope.ts

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ const ITEM_TYPE_TO_DATA_CATEGORY_MAP: Record<EnvelopeItemType, DataCategory> = {
223223
feedback: 'feedback',
224224
span: 'span',
225225
raw_security: 'security',
226+
otel_log: 'log_item',
226227
};
227228

228229
/**

0 commit comments

Comments
 (0)