Skip to content

Commit c31b0db

Browse files
committed
always send v2 envelopes
1 parent c7885f8 commit c31b0db

3 files changed

Lines changed: 13 additions & 57 deletions

File tree

packages/core/src/logs/envelope.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ import { isBrowser } from '../utils/isBrowser';
99
/**
1010
* Creates a log container envelope item for a list of logs.
1111
*
12-
* When `spanStreamingEnabled` is false, the payload is emitted in the legacy (v1) shape for
13-
* backwards compatibility: Relay's historical behavior for log envelopes was to always infer
14-
* end-user IP and User-Agent. Sending `version: 2` opts the payload into the explicit
15-
* `ingest_settings` protocol, which would silently turn that inference off for SDKs that
16-
* haven't adopted the new behavior.
17-
*
1812
* @param items - The logs to include in the envelope.
19-
* @param spanStreamingEnabled - If true, emit the v2 payload shape with explicit `ingest_settings`.
2013
* @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
14+
* Only emitted as `ingest_settings` in browser environments.
2115
* @returns The created log container envelope item.
2216
*/
2317
export function createLogContainerEnvelopeItem(
2418
items: Array<SerializedLog>,
25-
spanStreamingEnabled?: boolean,
2619
inferUserData?: boolean,
2720
): LogContainerItem {
2821
const inferSetting = inferUserData ? 'auto' : 'never';
@@ -33,11 +26,9 @@ export function createLogContainerEnvelopeItem(
3326
content_type: 'application/vnd.sentry.items.log+json',
3427
},
3528
{
36-
...(spanStreamingEnabled && {
37-
version: 2,
38-
...(isBrowser() && {
39-
ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },
40-
}),
29+
version: 2,
30+
...(isBrowser() && {
31+
ingest_settings: { infer_ip: inferSetting, infer_user_agent: inferSetting },
4132
}),
4233
items,
4334
},
@@ -53,7 +44,6 @@ export function createLogContainerEnvelopeItem(
5344
* @param metadata - The metadata to include in the envelope.
5445
* @param tunnel - The tunnel to include in the envelope.
5546
* @param dsn - The DSN to include in the envelope.
56-
* @param spanStreamingEnabled - If true, emit the v2 payload shape with explicit `ingest_settings`.
5747
* @param inferUserData - If true, tells Relay to infer the end-user IP and User-Agent from the incoming request.
5848
* @returns The created envelope.
5949
*/
@@ -62,7 +52,6 @@ export function createLogEnvelope(
6252
metadata?: SdkMetadata,
6353
tunnel?: string,
6454
dsn?: DsnComponents,
65-
spanStreamingEnabled?: boolean,
6655
inferUserData?: boolean,
6756
): LogEnvelope {
6857
const headers: LogEnvelope[0] = {};
@@ -78,7 +67,5 @@ export function createLogEnvelope(
7867
headers.dsn = dsnToString(dsn);
7968
}
8069

81-
return createEnvelope<LogEnvelope>(headers, [
82-
createLogContainerEnvelopeItem(logs, spanStreamingEnabled, inferUserData),
83-
]);
70+
return createEnvelope<LogEnvelope>(headers, [createLogContainerEnvelopeItem(logs, inferUserData)]);
8471
}

packages/core/src/logs/internal.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { getGlobalSingleton } from '../carrier';
33
import type { Client } from '../client';
44
import { getClient, getCurrentScope, getIsolationScope } from '../currentScopes';
55
import { DEBUG_BUILD } from '../debug-build';
6-
import { hasSpanStreamingEnabled } from '../tracing/spans/hasSpanStreamingEnabled';
76
import type { Integration } from '../types-hoist/integration';
87
import type { Log, SerializedLog } from '../types-hoist/log';
98
import { consoleSandbox, debug } from '../utils/debug-logger';
@@ -198,7 +197,6 @@ export function _INTERNAL_flushLogsBuffer(client: Client, maybeLogBuffer?: Array
198197
clientOptions._metadata,
199198
clientOptions.tunnel,
200199
client.getDsn(),
201-
hasSpanStreamingEnabled(client),
202200
clientOptions.sendDefaultPii,
203201
);
204202

packages/core/test/lib/logs/envelope.test.ts

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,23 @@ afterEach(() => {
2323
});
2424

2525
describe('createLogContainerEnvelopeItem', () => {
26-
it('creates an envelope item with legacy shape when span streaming is disabled', () => {
27-
const mockLog: SerializedLog = {
28-
timestamp: 1713859200,
29-
level: 'error',
30-
body: 'Test error message',
31-
};
32-
33-
const result = createLogContainerEnvelopeItem([mockLog, mockLog]);
34-
35-
expect(result).toHaveLength(2);
36-
expect(result[0]).toEqual({ type: 'log', item_count: 2, content_type: 'application/vnd.sentry.items.log+json' });
37-
expect(result[1]).toEqual({ items: [mockLog, mockLog] });
38-
});
39-
40-
it('emits version: 2 without ingest_settings when span streaming is enabled but not in browser', () => {
26+
it('emits version: 2 without ingest_settings when not in browser', () => {
4127
const mockLog: SerializedLog = {
4228
timestamp: 1713859200,
4329
level: 'info',
4430
body: 'Test log message',
4531
};
4632

47-
const result = createLogContainerEnvelopeItem([mockLog], true, true);
33+
const result = createLogContainerEnvelopeItem([mockLog], true);
4834

35+
expect(result[0]).toEqual({ type: 'log', item_count: 1, content_type: 'application/vnd.sentry.items.log+json' });
4936
expect(result[1]).toEqual({
5037
version: 2,
5138
items: [mockLog],
5239
});
5340
});
5441

55-
it("includes ingest_settings with 'auto' values when span streaming is enabled, in browser, and inferUserData is true", () => {
42+
it("includes ingest_settings with 'auto' values when in browser and inferUserData is true", () => {
5643
vi.mocked(isBrowser).mockReturnValue(true);
5744

5845
const mockLog: SerializedLog = {
@@ -61,7 +48,7 @@ describe('createLogContainerEnvelopeItem', () => {
6148
body: 'Test log message',
6249
};
6350

64-
const result = createLogContainerEnvelopeItem([mockLog], true, true);
51+
const result = createLogContainerEnvelopeItem([mockLog], true);
6552

6653
expect(result[1]).toEqual({
6754
version: 2,
@@ -70,7 +57,7 @@ describe('createLogContainerEnvelopeItem', () => {
7057
});
7158
});
7259

73-
it("includes ingest_settings with 'never' values when span streaming is enabled, in browser, and inferUserData is false", () => {
60+
it("includes ingest_settings with 'never' values when in browser and inferUserData is false", () => {
7461
vi.mocked(isBrowser).mockReturnValue(true);
7562

7663
const mockLog: SerializedLog = {
@@ -79,30 +66,14 @@ describe('createLogContainerEnvelopeItem', () => {
7966
body: 'Test log message',
8067
};
8168

82-
const result = createLogContainerEnvelopeItem([mockLog], true, false);
69+
const result = createLogContainerEnvelopeItem([mockLog], false);
8370

8471
expect(result[1]).toEqual({
8572
version: 2,
8673
ingest_settings: { infer_ip: 'never', infer_user_agent: 'never' },
8774
items: [mockLog],
8875
});
8976
});
90-
91-
it('omits version and ingest_settings when span streaming is disabled even if in browser', () => {
92-
vi.mocked(isBrowser).mockReturnValue(true);
93-
94-
const mockLog: SerializedLog = {
95-
timestamp: 1713859200,
96-
level: 'info',
97-
body: 'Test log message',
98-
};
99-
100-
const result = createLogContainerEnvelopeItem([mockLog], false, true);
101-
102-
expect(result[1]).toEqual({
103-
items: [mockLog],
104-
});
105-
});
10677
});
10778

10879
describe('createLogEnvelope', () => {
@@ -208,7 +179,7 @@ describe('createLogEnvelope', () => {
208179
expect.arrayContaining([
209180
expect.arrayContaining([
210181
{ type: 'log', item_count: 2, content_type: 'application/vnd.sentry.items.log+json' },
211-
{ items: mockLogs },
182+
{ version: 2, items: mockLogs },
212183
]),
213184
]),
214185
);

0 commit comments

Comments
 (0)