GeezerVison is showing github.com — ref(core): Keep log and metric capture helpers as deprecated aliases · getsentry/sentry-javascript@0a6ff37
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/core/src/index.ts +16-2Lines changed: 16 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -186,10 +186,24 @@ export { profiler } from './profiling'; | 186 | 186 | export { instrumentFetchRequest, _INTERNAL_getTracingHeadersForFetchRequest } from './fetch'; | 187 | 187 | export { captureFeedback } from './feedback'; | 188 | 188 | export type { ReportDialogOptions } from './report-dialog'; | 189 | | -export { _INTERNAL_captureLog, _INTERNAL_flushLogsBuffer } from './logs/internal'; | | 189 | +export { | | 190 | + _INTERNAL_captureLog, | | 191 | + _INTERNAL_flushLogsBuffer, | | 192 | + captureSerializedLog, | | 193 | + // oxlint-disable-next-line typescript/no-deprecated | | 194 | + _INTERNAL_captureSerializedLog, | | 195 | +} from './logs/internal'; | 190 | 196 | export { logger } from './logs/public-api'; | 191 | 197 | export { consoleLoggingIntegration } from './logs/console-integration'; | 192 | | -export { _INTERNAL_flushMetricsBuffer } from './metrics/internal'; | | 198 | +export { | | 199 | + _INTERNAL_flushMetricsBuffer, | | 200 | + captureMetric, | | 201 | + captureSerializedMetric, | | 202 | + // oxlint-disable-next-line typescript/no-deprecated | | 203 | + _INTERNAL_captureMetric, | | 204 | + // oxlint-disable-next-line typescript/no-deprecated | | 205 | + _INTERNAL_captureSerializedMetric, | | 206 | +} from './metrics/internal'; | 193 | 207 | export { metrics } from './metrics/public-api'; | 194 | 208 | export type { MetricOptions } from './metrics/public-api'; | 195 | 209 | export { createConsolaReporter } from './integrations/consola'; | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/logs/internal.ts +10-4Lines changed: 10 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,7 +60,7 @@ function setLogAttribute( | 60 | 60 | * @experimental This method will experience breaking changes. This is not yet part of | 61 | 61 | * the stable Sentry SDK API and can be changed or removed without warning. | 62 | 62 | */ | 63 | | -export function _INTERNAL_captureSerializedLog(client: Client, serializedLog: SerializedLog): void { | | 63 | +export function captureSerializedLog(client: Client, serializedLog: SerializedLog): void { | 64 | 64 | const bufferMap = _getBufferMap(); | 65 | 65 | const logBuffer = _INTERNAL_getLogBuffer(client); | 66 | 66 |
| @@ -78,21 +78,27 @@ export function _INTERNAL_captureSerializedLog(client: Client, serializedLog: Se | 78 | 78 | } | 79 | 79 | } | 80 | 80 |
| | 81 | +/** | | 82 | + * @deprecated Use `captureSerializedLog` instead. | | 83 | + */ | | 84 | +// TODO(v12): Remove once the Electron SDK no longer uses it. | | 85 | +export const _INTERNAL_captureSerializedLog = captureSerializedLog; | | 86 | + | 81 | 87 | /** | 82 | 88 | * Captures a log event and sends it to Sentry. | 83 | 89 | * | 84 | 90 | * @param log - The log event to capture. | 85 | 91 | * @param scope - A scope. Uses the current scope if not provided. | 86 | 92 | * @param client - A client. Uses the current client if not provided. | 87 | | - * @param captureSerializedLog - A function to capture the serialized log. | | 93 | + * @param captureSerialized - A function to capture the serialized log. | 88 | 94 | * | 89 | 95 | * @experimental This method will experience breaking changes. This is not yet part of | 90 | 96 | * the stable Sentry SDK API and can be changed or removed without warning. | 91 | 97 | */ | 92 | 98 | export function _INTERNAL_captureLog( | 93 | 99 | beforeLog: Log, | 94 | 100 | currentScope = getCurrentScope(), | 95 | | - captureSerializedLog: (client: Client, log: SerializedLog) => void = _INTERNAL_captureSerializedLog, | | 101 | + captureSerialized: (client: Client, log: SerializedLog) => void = captureSerializedLog, | 96 | 102 | ): void { | 97 | 103 | const client = currentScope?.getClient() ?? getClient(); | 98 | 104 | if (!client) { | @@ -195,7 +201,7 @@ export function _INTERNAL_captureLog( | 195 | 201 | }), | 196 | 202 | }; | 197 | 203 |
| 198 | | - captureSerializedLog(client, serializedLog); | | 204 | + captureSerialized(client, serializedLog); | 199 | 205 |
| 200 | 206 | client.emit('afterCaptureLog', log); | 201 | 207 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/metrics/internal.ts +16-4Lines changed: 16 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,7 +57,7 @@ function setMetricAttribute( | 57 | 57 | * @experimental This method will experience breaking changes. This is not yet part of | 58 | 58 | * the stable Sentry SDK API and can be changed or removed without warning. | 59 | 59 | */ | 60 | | -export function _INTERNAL_captureSerializedMetric(client: Client, serializedMetric: SerializedMetric): void { | | 60 | +export function captureSerializedMetric(client: Client, serializedMetric: SerializedMetric): void { | 61 | 61 | const bufferMap = _getBufferMap(); | 62 | 62 | const metricBuffer = _INTERNAL_getMetricBuffer(client); | 63 | 63 |
| @@ -81,6 +81,12 @@ export function _INTERNAL_captureSerializedMetric(client: Client, serializedMetr | 81 | 81 | } | 82 | 82 | } | 83 | 83 |
| | 84 | +/** | | 85 | + * @deprecated Use `captureSerializedMetric` instead. | | 86 | + */ | | 87 | +// TODO(v12): Remove once the Electron SDK no longer uses it. | | 88 | +export const _INTERNAL_captureSerializedMetric = captureSerializedMetric; | | 89 | + | 84 | 90 | /** | 85 | 91 | * Options for capturing a metric internally. | 86 | 92 | */ | @@ -184,9 +190,9 @@ function _buildSerializedMetric( | 184 | 190 | * @experimental This method will experience breaking changes. This is not yet part of | 185 | 191 | * the stable Sentry SDK API and can be changed or removed without warning. | 186 | 192 | */ | 187 | | -export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: InternalCaptureMetricOptions): void { | | 193 | +export function captureMetric(beforeMetric: Metric, options?: InternalCaptureMetricOptions): void { | 188 | 194 | const currentScope = options?.scope ?? getCurrentScope(); | 189 | | - const captureSerializedMetric = options?.captureSerializedMetric ?? _INTERNAL_captureSerializedMetric; | | 195 | + const captureSerialized = options?.captureSerializedMetric ?? captureSerializedMetric; | 190 | 196 | const client = currentScope?.getClient() ?? getClient(); | 191 | 197 | if (!client) { | 192 | 198 | DEBUG_BUILD && debug.warn('No client available to capture metric.'); | @@ -224,11 +230,17 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal | 224 | 230 |
| 225 | 231 | DEBUG_BUILD && debug.log('[Metric]', serializedMetric); | 226 | 232 |
| 227 | | - captureSerializedMetric(client, serializedMetric); | | 233 | + captureSerialized(client, serializedMetric); | 228 | 234 |
| 229 | 235 | client.emit('afterCaptureMetric', processedMetric); | 230 | 236 | } | 231 | 237 |
| | 238 | +/** | | 239 | + * @deprecated Use `captureMetric` instead. | | 240 | + */ | | 241 | +// TODO(v12): Remove once the Electron SDK no longer uses it. | | 242 | +export const _INTERNAL_captureMetric = captureMetric; | | 243 | + | 232 | 244 | /** | 233 | 245 | * Flushes the metrics buffer to Sentry. | 234 | 246 | * | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/src/metrics/public-api.ts +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { Scope } from '../scope'; | 2 | 2 | import type { MetricUnit } from '../types/measurement'; | 3 | 3 | import type { Metric, MetricType } from '../types/metric'; | 4 | | -import { _INTERNAL_captureMetric } from './internal'; | | 4 | +import { captureMetric as captureMetricEvent } from './internal'; | 5 | 5 |
| 6 | 6 | /** | 7 | 7 | * Options for capturing a metric. | @@ -32,7 +32,7 @@ export interface MetricOptions { | 32 | 32 | * @param options - Options for capturing the metric. | 33 | 33 | */ | 34 | 34 | function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void { | 35 | | - _INTERNAL_captureMetric( | | 35 | + captureMetricEvent( | 36 | 36 | { type, name, value, unit: options?.unit, attributes: options?.attributes }, | 37 | 37 | { scope: options?.scope }, | 38 | 38 | ); | |
Collapse file Copy file name to clipboardExpand all lines: packages/core/test/lib/client.test.ts +12-12Lines changed: 12 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,7 @@ import { | 19 | 19 | import * as integrationModule from '../../src/integration'; | 20 | 20 | import * as logsInternalModule from '../../src/logs/internal'; | 21 | 21 | import { _INTERNAL_captureLog } from '../../src/logs/internal'; | 22 | | -import { _INTERNAL_captureMetric } from '../../src/metrics/internal'; | | 22 | +import { captureMetric } from '../../src/metrics/internal'; | 23 | 23 | import * as traceModule from '../../src/tracing/trace'; | 24 | 24 | import { DEFAULT_TRANSPORT_BUFFER_SIZE } from '../../src/transports/base'; | 25 | 25 | import type { Envelope } from '../../src/types/envelope'; | @@ -4425,11 +4425,11 @@ describe('Client', () => { | 4425 | 4425 |
| 4426 | 4426 | expect(onSpy).not.toHaveBeenCalledWith('afterCaptureMetric', expect.any(Function)); | 4427 | 4427 |
| 4428 | | - _INTERNAL_captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | | 4428 | + captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | 4429 | 4429 | expect(onSpy).toHaveBeenCalledWith('afterCaptureMetric', expect.any(Function)); | 4430 | 4430 |
| 4431 | 4431 | onSpy.mockClear(); | 4432 | | - _INTERNAL_captureMetric({ name: 'metric2', value: 2, type: 'counter', attributes: {} }, { scope }); | | 4432 | + captureMetric({ name: 'metric2', value: 2, type: 'counter', attributes: {} }, { scope }); | 4433 | 4433 | expect(onSpy).not.toHaveBeenCalledWith('afterCaptureMetric', expect.any(Function)); | 4434 | 4434 |
| 4435 | 4435 | onSpy.mockRestore(); | @@ -4447,7 +4447,7 @@ describe('Client', () => { | 4447 | 4447 |
| 4448 | 4448 | // Create large metrics that will exceed the 800KB threshold | 4449 | 4449 | const largeValue = 'x'.repeat(400_000); // 400KB string | 4450 | | - _INTERNAL_captureMetric( | | 4450 | + captureMetric( | 4451 | 4451 | { name: 'large_metric', value: 1, type: 'counter', attributes: { large_value: largeValue } }, | 4452 | 4452 | { scope }, | 4453 | 4453 | ); | @@ -4466,7 +4466,7 @@ describe('Client', () => { | 4466 | 4466 | const sendEnvelopeSpy = vi.spyOn(client, 'sendEnvelope'); | 4467 | 4467 |
| 4468 | 4468 | // Create metrics that won't exceed the threshold | 4469 | | - _INTERNAL_captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | | 4469 | + captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | 4470 | 4470 |
| 4471 | 4471 | expect(sendEnvelopeSpy).not.toHaveBeenCalled(); | 4472 | 4472 | }); | @@ -4482,8 +4482,8 @@ describe('Client', () => { | 4482 | 4482 | const sendEnvelopeSpy = vi.spyOn(client, 'sendEnvelope'); | 4483 | 4483 |
| 4484 | 4484 | // Add some metrics | 4485 | | - _INTERNAL_captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | 4486 | | - _INTERNAL_captureMetric({ name: 'metric2', value: 2, type: 'counter', attributes: {} }, { scope }); | | 4485 | + captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | | 4486 | + captureMetric({ name: 'metric2', value: 2, type: 'counter', attributes: {} }, { scope }); | 4487 | 4487 |
| 4488 | 4488 | // Trigger flush event | 4489 | 4489 | client.emit('flush'); | @@ -4502,7 +4502,7 @@ describe('Client', () => { | 4502 | 4502 | scope.setClient(client); | 4503 | 4503 |
| 4504 | 4504 | // Capture a metric which will start the flush timer | 4505 | | - _INTERNAL_captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | | 4505 | + captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | 4506 | 4506 |
| 4507 | 4507 | // Verify safeUnref was called on the timer | 4508 | 4508 | expect(safeUnrefSpy).toHaveBeenCalledTimes(1); | @@ -4522,7 +4522,7 @@ describe('Client', () => { | 4522 | 4522 | client.on('flushMetrics', flushMetricsHandler); | 4523 | 4523 |
| 4524 | 4524 | // Capture a metric which starts the weight-based flush timer | 4525 | | - _INTERNAL_captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | | 4525 | + captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | 4526 | 4526 |
| 4527 | 4527 | expect(flushMetricsHandler).not.toHaveBeenCalled(); | 4528 | 4528 |
| @@ -4543,7 +4543,7 @@ describe('Client', () => { | 4543 | 4543 | const scope = new Scope(); | 4544 | 4544 | scope.setClient(client); | 4545 | 4545 |
| 4546 | | - _INTERNAL_captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | | 4546 | + captureMetric({ name: 'test_metric', value: 42, type: 'counter', attributes: {} }, { scope }); | 4547 | 4547 |
| 4548 | 4548 | expect(safeUnrefSpy).not.toHaveBeenCalled(); | 4549 | 4549 |
| @@ -4561,7 +4561,7 @@ describe('Client', () => { | 4561 | 4561 |
| 4562 | 4562 | const sendEnvelopeSpy = vi.spyOn(client, 'sendEnvelope'); | 4563 | 4563 |
| 4564 | | - _INTERNAL_captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | | 4564 | + captureMetric({ name: 'metric1', value: 1, type: 'counter', attributes: {} }, { scope }); | 4565 | 4565 |
| 4566 | 4566 | expect(sendEnvelopeSpy).not.toHaveBeenCalled(); | 4567 | 4567 |
| @@ -4582,7 +4582,7 @@ describe('Client', () => { | 4582 | 4582 | const sendEnvelopeSpy = vi.spyOn(client, 'sendEnvelope'); | 4583 | 4583 |
| 4584 | 4584 | const largeValue = 'x'.repeat(400_000); | 4585 | | - _INTERNAL_captureMetric( | | 4585 | + captureMetric( | 4586 | 4586 | { name: 'large_metric', value: 1, type: 'counter', attributes: { large_value: largeValue } }, | 4587 | 4587 | { scope }, | 4588 | 4588 | ); | |
|