Skip to content

Commit 2e3d6e3

Browse files
authored
feat(core): Add sdk name and version to logs (#16005)
resolves https://linear.app/getsentry/issue/LOGS-16/
1 parent b4ef25d commit 2e3d6e3

File tree

4 files changed

+291
-6
lines changed

4 files changed

+291
-6
lines changed

dev-packages/browser-integration-tests/suites/public-api/logger/integration/test.ts

+84
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
3030
stringValue: 'auto.console.logging',
3131
},
3232
},
33+
{
34+
key: 'sentry.sdk.name',
35+
value: {
36+
stringValue: 'sentry.javascript.browser',
37+
},
38+
},
39+
{
40+
key: 'sentry.sdk.version',
41+
value: {
42+
stringValue: expect.any(String),
43+
},
44+
},
3345
],
3446
timeUnixNano: expect.any(String),
3547
traceId: expect.any(String),
@@ -51,6 +63,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
5163
stringValue: 'auto.console.logging',
5264
},
5365
},
66+
{
67+
key: 'sentry.sdk.name',
68+
value: {
69+
stringValue: 'sentry.javascript.browser',
70+
},
71+
},
72+
{
73+
key: 'sentry.sdk.version',
74+
value: {
75+
stringValue: expect.any(String),
76+
},
77+
},
5478
],
5579
timeUnixNano: expect.any(String),
5680
traceId: expect.any(String),
@@ -72,6 +96,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
7296
stringValue: 'auto.console.logging',
7397
},
7498
},
99+
{
100+
key: 'sentry.sdk.name',
101+
value: {
102+
stringValue: 'sentry.javascript.browser',
103+
},
104+
},
105+
{
106+
key: 'sentry.sdk.version',
107+
value: {
108+
stringValue: expect.any(String),
109+
},
110+
},
75111
],
76112
timeUnixNano: expect.any(String),
77113
traceId: expect.any(String),
@@ -93,6 +129,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
93129
stringValue: 'auto.console.logging',
94130
},
95131
},
132+
{
133+
key: 'sentry.sdk.name',
134+
value: {
135+
stringValue: 'sentry.javascript.browser',
136+
},
137+
},
138+
{
139+
key: 'sentry.sdk.version',
140+
value: {
141+
stringValue: expect.any(String),
142+
},
143+
},
96144
],
97145
timeUnixNano: expect.any(String),
98146
traceId: expect.any(String),
@@ -114,6 +162,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
114162
stringValue: 'auto.console.logging',
115163
},
116164
},
165+
{
166+
key: 'sentry.sdk.name',
167+
value: {
168+
stringValue: 'sentry.javascript.browser',
169+
},
170+
},
171+
{
172+
key: 'sentry.sdk.version',
173+
value: {
174+
stringValue: expect.any(String),
175+
},
176+
},
117177
],
118178
timeUnixNano: expect.any(String),
119179
traceId: expect.any(String),
@@ -135,6 +195,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
135195
stringValue: 'auto.console.logging',
136196
},
137197
},
198+
{
199+
key: 'sentry.sdk.name',
200+
value: {
201+
stringValue: 'sentry.javascript.browser',
202+
},
203+
},
204+
{
205+
key: 'sentry.sdk.version',
206+
value: {
207+
stringValue: expect.any(String),
208+
},
209+
},
138210
],
139211
timeUnixNano: expect.any(String),
140212
traceId: expect.any(String),
@@ -156,6 +228,18 @@ sentryTest('should capture console object calls', async ({ getLocalTestUrl, page
156228
stringValue: 'auto.console.logging',
157229
},
158230
},
231+
{
232+
key: 'sentry.sdk.name',
233+
value: {
234+
stringValue: 'sentry.javascript.browser',
235+
},
236+
},
237+
{
238+
key: 'sentry.sdk.version',
239+
value: {
240+
stringValue: expect.any(String),
241+
},
242+
},
159243
],
160244
timeUnixNano: expect.any(String),
161245
traceId: expect.any(String),

dev-packages/browser-integration-tests/suites/public-api/logger/simple/test.ts

+156-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
2323
{
2424
severityText: 'trace',
2525
body: { stringValue: 'test trace' },
26-
attributes: [],
26+
attributes: [
27+
{
28+
key: 'sentry.sdk.name',
29+
value: {
30+
stringValue: 'sentry.javascript.browser',
31+
},
32+
},
33+
{
34+
key: 'sentry.sdk.version',
35+
value: {
36+
stringValue: expect.any(String),
37+
},
38+
},
39+
],
2740
timeUnixNano: expect.any(String),
2841
traceId: expect.any(String),
2942
severityNumber: 1,
@@ -37,7 +50,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
3750
{
3851
severityText: 'debug',
3952
body: { stringValue: 'test debug' },
40-
attributes: [],
53+
attributes: [
54+
{
55+
key: 'sentry.sdk.name',
56+
value: {
57+
stringValue: 'sentry.javascript.browser',
58+
},
59+
},
60+
{
61+
key: 'sentry.sdk.version',
62+
value: {
63+
stringValue: expect.any(String),
64+
},
65+
},
66+
],
4167
timeUnixNano: expect.any(String),
4268
traceId: expect.any(String),
4369
severityNumber: 5,
@@ -51,7 +77,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
5177
{
5278
severityText: 'info',
5379
body: { stringValue: 'test info' },
54-
attributes: [],
80+
attributes: [
81+
{
82+
key: 'sentry.sdk.name',
83+
value: {
84+
stringValue: 'sentry.javascript.browser',
85+
},
86+
},
87+
{
88+
key: 'sentry.sdk.version',
89+
value: {
90+
stringValue: expect.any(String),
91+
},
92+
},
93+
],
5594
timeUnixNano: expect.any(String),
5695
traceId: expect.any(String),
5796
severityNumber: 9,
@@ -65,7 +104,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
65104
{
66105
severityText: 'warn',
67106
body: { stringValue: 'test warn' },
68-
attributes: [],
107+
attributes: [
108+
{
109+
key: 'sentry.sdk.name',
110+
value: {
111+
stringValue: 'sentry.javascript.browser',
112+
},
113+
},
114+
{
115+
key: 'sentry.sdk.version',
116+
value: {
117+
stringValue: expect.any(String),
118+
},
119+
},
120+
],
69121
timeUnixNano: expect.any(String),
70122
traceId: expect.any(String),
71123
severityNumber: 13,
@@ -79,7 +131,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
79131
{
80132
severityText: 'error',
81133
body: { stringValue: 'test error' },
82-
attributes: [],
134+
attributes: [
135+
{
136+
key: 'sentry.sdk.name',
137+
value: {
138+
stringValue: 'sentry.javascript.browser',
139+
},
140+
},
141+
{
142+
key: 'sentry.sdk.version',
143+
value: {
144+
stringValue: expect.any(String),
145+
},
146+
},
147+
],
83148
timeUnixNano: expect.any(String),
84149
traceId: expect.any(String),
85150
severityNumber: 17,
@@ -93,7 +158,20 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
93158
{
94159
severityText: 'fatal',
95160
body: { stringValue: 'test fatal' },
96-
attributes: [],
161+
attributes: [
162+
{
163+
key: 'sentry.sdk.name',
164+
value: {
165+
stringValue: 'sentry.javascript.browser',
166+
},
167+
},
168+
{
169+
key: 'sentry.sdk.version',
170+
value: {
171+
stringValue: expect.any(String),
172+
},
173+
},
174+
],
97175
timeUnixNano: expect.any(String),
98176
traceId: expect.any(String),
99177
severityNumber: 21,
@@ -108,6 +186,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
108186
severityText: 'trace',
109187
body: { stringValue: 'test trace stringArg false 123' },
110188
attributes: [
189+
{
190+
key: 'sentry.sdk.name',
191+
value: {
192+
stringValue: 'sentry.javascript.browser',
193+
},
194+
},
195+
{
196+
key: 'sentry.sdk.version',
197+
value: {
198+
stringValue: expect.any(String),
199+
},
200+
},
111201
{
112202
key: 'sentry.message.template',
113203
value: {
@@ -153,6 +243,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
153243
severityText: 'debug',
154244
body: { stringValue: 'test debug stringArg false 123' },
155245
attributes: [
246+
{
247+
key: 'sentry.sdk.name',
248+
value: {
249+
stringValue: 'sentry.javascript.browser',
250+
},
251+
},
252+
{
253+
key: 'sentry.sdk.version',
254+
value: {
255+
stringValue: expect.any(String),
256+
},
257+
},
156258
{
157259
key: 'sentry.message.template',
158260
value: {
@@ -198,6 +300,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
198300
severityText: 'info',
199301
body: { stringValue: 'test info stringArg false 123' },
200302
attributes: [
303+
{
304+
key: 'sentry.sdk.name',
305+
value: {
306+
stringValue: 'sentry.javascript.browser',
307+
},
308+
},
309+
{
310+
key: 'sentry.sdk.version',
311+
value: {
312+
stringValue: expect.any(String),
313+
},
314+
},
201315
{
202316
key: 'sentry.message.template',
203317
value: {
@@ -243,6 +357,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
243357
severityText: 'warn',
244358
body: { stringValue: 'test warn stringArg false 123' },
245359
attributes: [
360+
{
361+
key: 'sentry.sdk.name',
362+
value: {
363+
stringValue: 'sentry.javascript.browser',
364+
},
365+
},
366+
{
367+
key: 'sentry.sdk.version',
368+
value: {
369+
stringValue: expect.any(String),
370+
},
371+
},
246372
{
247373
key: 'sentry.message.template',
248374
value: {
@@ -288,6 +414,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
288414
severityText: 'error',
289415
body: { stringValue: 'test error stringArg false 123' },
290416
attributes: [
417+
{
418+
key: 'sentry.sdk.name',
419+
value: {
420+
stringValue: 'sentry.javascript.browser',
421+
},
422+
},
423+
{
424+
key: 'sentry.sdk.version',
425+
value: {
426+
stringValue: expect.any(String),
427+
},
428+
},
291429
{
292430
key: 'sentry.message.template',
293431
value: {
@@ -333,6 +471,18 @@ sentryTest('should capture all logging methods', async ({ getLocalTestUrl, page
333471
severityText: 'fatal',
334472
body: { stringValue: 'test fatal stringArg false 123' },
335473
attributes: [
474+
{
475+
key: 'sentry.sdk.name',
476+
value: {
477+
stringValue: 'sentry.javascript.browser',
478+
},
479+
},
480+
{
481+
key: 'sentry.sdk.version',
482+
value: {
483+
stringValue: expect.any(String),
484+
},
485+
},
336486
{
337487
key: 'sentry.message.template',
338488
value: {

packages/core/src/logs/exports.ts

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ export function _INTERNAL_captureLog(
104104
logAttributes['sentry.environment'] = environment;
105105
}
106106

107+
const { sdk } = client.getSdkMetadata() ?? {};
108+
if (sdk) {
109+
logAttributes['sentry.sdk.name'] = sdk.name;
110+
logAttributes['sentry.sdk.version'] = sdk.version;
111+
}
112+
107113
if (isParameterizedString(message)) {
108114
const { __sentry_template_string__, __sentry_template_values__ = [] } = message;
109115
logAttributes['sentry.message.template'] = __sentry_template_string__;

0 commit comments

Comments
 (0)