MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / _buildSerializedMetric

Function _buildSerializedMetric

packages/core/src/metrics/internal.ts:127–156  ·  view source on GitHub ↗

* Creates a serialized metric ready to be sent to Sentry.

(
  metric: Metric,
  client: Client,
  currentScope: Scope,
  scopeAttributes: RawAttributes<Record<string, unknown>> | undefined,
)

Source from the content-addressed store, hash-verified

125 * Creates a serialized metric ready to be sent to Sentry.
126 */
127function _buildSerializedMetric(
128 metric: Metric,
129 client: Client,
130 currentScope: Scope,
131 scopeAttributes: RawAttributes<Record<string, unknown>> | undefined,
132): SerializedMetric {
133 // Get trace context
134 const [, traceContext] = _getTraceInfoFromScope(client, currentScope);
135 const span = _getSpanForScope(currentScope);
136 const traceId = span ? span.spanContext().traceId : traceContext?.trace_id;
137 const spanId = span ? span.spanContext().spanId : undefined;
138
139 const timestamp = timestampInSeconds();
140 const sequenceAttr = getSequenceAttribute(timestamp);
141
142 return {
143 timestamp,
144 trace_id: traceId ?? '',
145 span_id: spanId,
146 name: metric.name,
147 type: metric.type,
148 unit: metric.unit,
149 value: metric.value,
150 attributes: {
151 ...serializeAttributes(scopeAttributes),
152 ...serializeAttributes(metric.attributes, 'skip-undefined'),
153 [sequenceAttr.key]: sequenceAttr.value,
154 },
155 };
156}
157
158/**
159 * Captures a metric event and sends it to Sentry.

Callers 1

_INTERNAL_captureMetricFunction · 0.85

Calls 6

_getTraceInfoFromScopeFunction · 0.90
_getSpanForScopeFunction · 0.90
timestampInSecondsFunction · 0.90
getSequenceAttributeFunction · 0.90
serializeAttributesFunction · 0.90
spanContextMethod · 0.65

Tested by

no test coverage detected