@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
130 lines (122 loc) • 3.02 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const internal = require('./internal.js');
/**
* Options for capturing a metric.
*/
/**
* Capture a metric with the given type, name, and value.
*
* @param type - The type of the metric.
* @param name - The name of the metric.
* @param value - The value of the metric.
* @param options - Options for capturing the metric.
*/
function captureMetric(type, name, value, options) {
internal._INTERNAL_captureMetric(
{ type, name, value, unit: options?.unit, attributes: options?.attributes },
{ scope: options?.scope },
);
}
/**
* @summary Increment a counter metric. Requires the `_experiments.enableMetrics` option to be enabled.
*
* @param name - The name of the counter metric.
* @param value - The value to increment by (defaults to 1).
* @param options - Options for capturing the metric.
*
* @example
*
* ```
* Sentry.metrics.count('api.requests', 1, {
* attributes: {
* endpoint: '/api/users',
* method: 'GET',
* status: 200
* }
* });
* ```
*
* @example With custom value
*
* ```
* Sentry.metrics.count('items.processed', 5, {
* attributes: {
* processor: 'batch-processor',
* queue: 'high-priority'
* }
* });
* ```
*/
function count(name, value = 1, options) {
captureMetric('counter', name, value, options);
}
/**
* @summary Set a gauge metric to a specific value. Requires the `_experiments.enableMetrics` option to be enabled.
*
* @param name - The name of the gauge metric.
* @param value - The current value of the gauge.
* @param options - Options for capturing the metric.
*
* @example
*
* ```
* Sentry.metrics.gauge('memory.usage', 1024, {
* unit: 'megabyte',
* attributes: {
* process: 'web-server',
* region: 'us-east-1'
* }
* });
* ```
*
* @example Without unit
*
* ```
* Sentry.metrics.gauge('active.connections', 42, {
* attributes: {
* server: 'api-1',
* protocol: 'websocket'
* }
* });
* ```
*/
function gauge(name, value, options) {
captureMetric('gauge', name, value, options);
}
/**
* @summary Record a value in a distribution metric. Requires the `_experiments.enableMetrics` option to be enabled.
*
* @param name - The name of the distribution metric.
* @param value - The value to record in the distribution.
* @param options - Options for capturing the metric.
*
* @example
*
* ```
* Sentry.metrics.distribution('task.duration', 500, {
* unit: 'millisecond',
* attributes: {
* task: 'data-processing',
* priority: 'high'
* }
* });
* ```
*
* @example Without unit
*
* ```
* Sentry.metrics.distribution('batch.size', 100, {
* attributes: {
* processor: 'batch-1',
* type: 'async'
* }
* });
* ```
*/
function distribution(name, value, options) {
captureMetric('distribution', name, value, options);
}
exports.count = count;
exports.distribution = distribution;
exports.gauge = gauge;
//# sourceMappingURL=public-api.js.map