Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/src/metrics/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ export function _INTERNAL_captureMetric(beforeMetric: Metric, options?: Internal
const traceId = span ? span.spanContext().traceId : traceContext?.trace_id;
const spanId = span ? span.spanContext().spanId : undefined;

if (!traceId) {
DEBUG_BUILD && debug.warn('[Metric] No trace ID available, will not send metric.');
return;
}

const serializedMetric: SerializedMetric = {
timestamp: timestampInSeconds(),
trace_id: traceId,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/metrics/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface MetricOptions {
* @param value - The value of the metric.
* @param options - Options for capturing the metric.
*/
function captureMetric(type: MetricType, name: string, value: number | string, options?: MetricOptions): void {
function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void {
_INTERNAL_captureMetric(
{ type, name, value, unit: options?.unit, attributes: options?.attributes },
{ scope: options?.scope },
Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/server-runtime-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ function estimateMetricSizeInBytes(metric: Metric): number {
}

// Add weight for the value
if (typeof metric.value === 'string') {
weight += metric.value.length * 2;
} else {
weight += 8; // number
}
weight += 8; // number

if (metric.attributes) {
Object.values(metric.attributes).forEach(value => {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types-hoist/metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Metric {
/**
* The value of the metric.
*/
value: number | string;
value: number;

/**
* The type of metric.
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface SerializedMetric {
/**
* The trace ID for this metric.
*/
trace_id?: string;
trace_id: string;

/**
* The span ID for this metric.
Expand All @@ -67,7 +67,7 @@ export interface SerializedMetric {
/**
* The value of the metric.
*/
value: number | string;
value: number;

/**
* Arbitrary structured data that stores information about the metric.
Expand Down
Loading