View Source Sentry.Metric (Sentry v13.0.1)

Represents a metric that can be sent to Sentry.

Metrics follow the Sentry Metrics Protocol as defined in: https://develop.sentry.dev/sdk/telemetry/metrics/

This module is used by Sentry.Metrics to create and send metric data to Sentry.

Summary

Types

t()

A metric struct.

Functions

Attaches default attributes to a metric.

Converts a metric to a map suitable for JSON encoding.

Types

Link to this type

metric_type()

View Source (since 13.0.0)
@type metric_type() :: :counter | :gauge | :distribution
@type t() :: %Sentry.Metric{
  attributes: map(),
  name: String.t(),
  span_id: String.t() | nil,
  timestamp: float(),
  trace_id: String.t() | nil,
  type: metric_type(),
  unit: String.t() | nil,
  value: number()
}

A metric struct.

Functions

Link to this function

attach_default_attributes(metric)

View Source (since 13.0.0)
@spec attach_default_attributes(t()) :: t()

Attaches default attributes to a metric.

This adds Sentry-specific attributes like environment, release, SDK info, and server name. Per the Sentry Metrics spec, default attributes should be attached before the before_send_metric callback is applied (step 5 before step 6).

Link to this function

to_map(metric)

View Source (since 13.0.0)
@spec to_map(t()) :: %{optional(atom()) => term()}

Converts a metric to a map suitable for JSON encoding.

The output matches the Sentry metrics schema with top-level fields: timestamp, type, name, value, unit, trace_id, span_id, and attributes. The attributes are formatted with type information as required by the protocol.