* Creates a serialized metric ready to be sent to Sentry.
( metric: Metric, client: Client, currentScope: Scope, scopeAttributes: RawAttributes<Record<string, unknown>> | undefined, )
| 125 | * Creates a serialized metric ready to be sent to Sentry. |
| 126 | */ |
| 127 | function _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. |
no test coverage detected