Skip to content

Commit

Permalink
linting, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-sentry committed Feb 18, 2025
1 parent a2c10e7 commit 1328016
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
20 changes: 14 additions & 6 deletions packages/core/src/ourlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ function addLog(log: Log): void {
return;
}

// if (!client.getOptions()._experiments?.logSupport) {
// return;
// }
if (!client.getOptions()._experiments?.logSupport) {
return;
}

const globalScope = getGlobalScope();
const dsn = client.getDsn();
Expand Down Expand Up @@ -99,16 +99,24 @@ function valueToAttribute(key: string, value: unknown): LogAttribute {
* A utility function to be able to create methods like Sentry.info`...`
*
* The first parameter is bound with, e.g., const info = captureLog.bind(null, 'info')
* The other parameters are in the format to be passed a template, Sentry.info`hello ${world}`
* The other parameters are in the format to be passed a tagged template, Sentry.info`hello ${world}`
*/
export function captureLog(level: LogSeverityLevel, messages: string[] | string, ...values: unknown[]): void {
const message = Array.isArray(messages) ? messages.reduce((acc, str, i) => acc + str + (values[i] ?? ''), '') : messages;

const attributes = values.map<LogAttribute>((value, index) => valueToAttribute(`param${index}`, value));
if (Array.isArray(messages)) {
attributes.push({
key: 'sentry.template',
value: {
stringValue: messages.map((s, i) => s + (i < messages.length - 1 ? `$param${i}` : '')).join('')
}
})
}
addLog({
severityText: level,
body: {
stringValue: message,
},
attributes: values.map<LogAttribute>((value, index) => valueToAttribute(`param${index}`, value)),
attributes: attributes,
})
}
2 changes: 1 addition & 1 deletion packages/core/src/types-hoist/envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { ReplayEvent, ReplayRecordingData } from './replay';
import type { SdkInfo } from './sdkinfo';
import type { SerializedSession, SessionAggregates } from './session';
import type { SpanJSON } from './span';
import { Log } from './ourlogs';
import type { Log } from './ourlogs';

// Based on: https://develop.sentry.dev/sdk/envelopes/

Expand Down

0 comments on commit 1328016

Please sign in to comment.