Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/core/src/logs/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,12 @@ export function _INTERNAL_captureLog(
...beforeLog.attributes,
};

const { user } = getMergedScopeData(currentScope);
// Only attach user to log attributes if sendDefaultPii is enabled
if (client.getOptions().sendDefaultPii) {
const { id, email, username } = user;
setLogAttribute(processedLogAttributes, 'user.id', id, false);
setLogAttribute(processedLogAttributes, 'user.email', email, false);
setLogAttribute(processedLogAttributes, 'user.name', username, false);
}
const {
user: { id, email, username },
} = getMergedScopeData(currentScope);
setLogAttribute(processedLogAttributes, 'user.id', id, false);
setLogAttribute(processedLogAttributes, 'user.email', email, false);
setLogAttribute(processedLogAttributes, 'user.name', username, false);

setLogAttribute(processedLogAttributes, 'sentry.release', release);
setLogAttribute(processedLogAttributes, 'sentry.environment', environment);
Expand Down
23 changes: 1 addition & 22 deletions packages/core/test/lib/logs/exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,10 @@ describe('_INTERNAL_captureLog', () => {
});

describe('user functionality', () => {
it('includes user data in log attributes when sendDefaultPii is enabled', () => {
it('includes user data in log attributes', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
_experiments: { enableLogs: true },
sendDefaultPii: true,
});
const client = new TestClient(options);
const scope = new Scope();
Expand Down Expand Up @@ -410,26 +409,6 @@ describe('_INTERNAL_captureLog', () => {
});
});

it('does not include user data in log attributes when sendDefaultPii is disabled', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
_experiments: { enableLogs: true },
sendDefaultPii: false,
});
const client = new TestClient(options);
const scope = new Scope();
scope.setUser({
id: '123',
email: 'user@example.com',
username: 'testuser',
});

_INTERNAL_captureLog({ level: 'info', message: 'test log without user' }, client, scope);

const logAttributes = _INTERNAL_getLogBuffer(client)?.[0]?.attributes;
expect(logAttributes).toEqual({});
});

it('includes partial user data when only some fields are available', () => {
const options = getDefaultTestClientOptions({
dsn: PUBLIC_DSN,
Expand Down
Loading