-
-
Notifications
You must be signed in to change notification settings - Fork 32
Feat(spotlight): metrics support #1265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f96f074
cf6f388
6278a52
d672ca2
96cfe84
003fb05
f4753db
6c91bc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| {"sdk":{"name":"sentry.javascript.react","version":"10.34.0"}} | ||
| {"type":"trace_metric","item_count":12,"content_type":"application/vnd.sentry.items.trace-metric+json"} | ||
| {"items":[{"timestamp":1769353796.9620998,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353796.9625998,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button2.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353797.2412999,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353797.2414,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button2.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353797.5262,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353797.5263999,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.button2.clicked","type":"counter","value":1,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353798.102,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.random.value","type":"gauge","value":60,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353798.3725,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.random.value","type":"gauge","value":69,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353799.0937998,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.response.time","type":"distribution","unit":"millisecond","value":125.4894445940432,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353799.2722998,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.response.time","type":"distribution","unit":"millisecond","value":880.0890658738737,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353799.5245998,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.response.time","type":"distribution","unit":"millisecond","value":350.38026520290623,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}},{"timestamp":1769353799.7902,"trace_id":"5becd2182ebd4b4bb5afe9fbc6b95866","name":"frontend.response.time","type":"distribution","unit":"millisecond","value":854.05904566557,"attributes":{"component":{"value":"SentryMetrics","type":"string"},"sentry.environment":{"value":"development","type":"string"},"sentry.sdk.name":{"value":"sentry.javascript.react","type":"string"},"sentry.sdk.version":{"value":"10.34.0","type":"string"},"sentry.replay_id":{"value":"e88e195d7a5249a2a0df5b3f2123816d","type":"string"}}}]} |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { isErrorEvent, isLogEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import { isErrorEvent, isLogEvent, isMetricEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import type { FormatterRegistry } from "../types.ts"; | ||
| import { formatError } from "./errors.ts"; | ||
| import { formatLog } from "./logs.ts"; | ||
| import { formatMetric } from "./metrics.ts"; | ||
| import { formatTrace } from "./traces.ts"; | ||
|
|
||
| export const formatters: FormatterRegistry = { | ||
| event: { typeGuard: isErrorEvent, format: formatError }, | ||
| log: { typeGuard: isLogEvent, format: formatLog }, | ||
| metric: { typeGuard: isMetricEvent, format: formatMetric }, | ||
| transaction: { typeGuard: isTraceEvent, format: formatTrace }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { Envelope } from "@sentry/core"; | ||
| import type { SentryMetricEvent, SentryMetricPayload } from "../../parser/index.ts"; | ||
| import { formatTimestamp } from "../utils.ts"; | ||
|
|
||
| function formatSingleMetric(metric: SentryMetricPayload): string { | ||
| const parts: string[] = []; | ||
|
|
||
| parts.push(`name=${metric.name}`); | ||
| parts.push(`type=${metric.type}`); | ||
| parts.push(`value=${metric.value}`); | ||
|
|
||
| if (metric.unit) { | ||
| parts.push(`unit=${metric.unit}`); | ||
| } | ||
|
|
||
| if (metric.trace_id) { | ||
| parts.push(`trace_id=${metric.trace_id}`); | ||
| } | ||
|
|
||
| if (metric.span_id) { | ||
| parts.push(`span_id=${metric.span_id}`); | ||
| } | ||
|
|
||
| if (metric.attributes) { | ||
| for (const [key, attr] of Object.entries(metric.attributes)) { | ||
| if (attr.value !== undefined && attr.value !== null) { | ||
| parts.push(`${key}=${attr.value}`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Use metric timestamp as primary timestamp | ||
| const ts = formatTimestamp(metric.timestamp); | ||
| parts.push(`@${ts}`); | ||
|
|
||
| return parts.join(" "); | ||
| } | ||
|
|
||
| export function formatMetric(event: SentryMetricEvent, _envelopeHeader: Envelope[0]): string[] { | ||
| return event.items.map(formatSingleMetric); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { isErrorEvent, isLogEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import { isErrorEvent, isLogEvent, isMetricEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import type { FormatterRegistry } from "../types.ts"; | ||
| import { formatError } from "./errors.ts"; | ||
| import { formatLog } from "./logs.ts"; | ||
| import { formatMetric } from "./metrics.ts"; | ||
| import { formatTrace } from "./traces.ts"; | ||
|
|
||
| export const formatters: FormatterRegistry = { | ||
| event: { typeGuard: isErrorEvent, format: formatError }, | ||
| log: { typeGuard: isLogEvent, format: formatLog }, | ||
| metric: { typeGuard: isMetricEvent, format: formatMetric }, | ||
| transaction: { typeGuard: isTraceEvent, format: formatTrace }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type { Envelope } from "@sentry/core"; | ||
| import type { SentryMetricEvent } from "../../parser/index.ts"; | ||
|
|
||
| export function formatMetric(event: SentryMetricEvent, _envelopeHeader: Envelope[0]): string[] { | ||
| return [JSON.stringify(event)]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { isErrorEvent, isLogEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import { isErrorEvent, isLogEvent, isMetricEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import type { FormatterRegistry } from "../types.ts"; | ||
| import { formatError } from "./errors.ts"; | ||
| import { formatLog } from "./logs.ts"; | ||
| import { formatMetric } from "./metrics.ts"; | ||
| import { formatTrace } from "./traces.ts"; | ||
|
|
||
| export const formatters: FormatterRegistry = { | ||
| event: { typeGuard: isErrorEvent, format: formatError }, | ||
| log: { typeGuard: isLogEvent, format: formatLog }, | ||
| metric: { typeGuard: isMetricEvent, format: formatMetric }, | ||
| transaction: { typeGuard: isTraceEvent, format: formatTrace }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import type { Envelope } from "@sentry/core"; | ||
| import logfmt from "logfmt"; | ||
| import type { SentryMetricEvent, SentryMetricPayload } from "../../parser/index.ts"; | ||
| import { formatTimestamp } from "../utils.ts"; | ||
|
|
||
| function formatSingleMetric(metric: SentryMetricPayload): string { | ||
| const data: Record<string, any> = { | ||
| timestamp: formatTimestamp(metric.timestamp), | ||
| type: "trace_metric", | ||
| name: metric.name, | ||
| metric_type: metric.type, | ||
| value: metric.value, | ||
| }; | ||
|
|
||
| if (metric.unit) { | ||
| data.unit = metric.unit; | ||
| } | ||
|
|
||
| if (metric.trace_id) { | ||
| data.trace_id = metric.trace_id; | ||
| } | ||
|
|
||
| if (metric.span_id) { | ||
| data.span_id = metric.span_id; | ||
| } | ||
|
|
||
| if (metric.attributes) { | ||
| for (const [key, attr] of Object.entries(metric.attributes)) { | ||
| data[`attr.${key}`] = attr.value; | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent null/undefined handling across metric formattersLow Severity The human formatter defensively checks Additional Locations (1) |
||
|
|
||
| return logfmt.stringify(data); | ||
| } | ||
|
|
||
| export function formatMetric(event: SentryMetricEvent, _envelopeHeader: Envelope[0]): string[] { | ||
| return event.items.map(formatSingleMetric); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import { isErrorEvent, isLogEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import { isErrorEvent, isLogEvent, isMetricEvent, isTraceEvent } from "../../parser/helpers.ts"; | ||
| import type { FormatterRegistry } from "../types.ts"; | ||
| import { formatError } from "./errors.ts"; | ||
| import { formatLog } from "./logs.ts"; | ||
| import { formatMetric } from "./metrics.ts"; | ||
| import { formatTrace } from "./traces.ts"; | ||
|
|
||
| export const formatters: FormatterRegistry = { | ||
| event: { typeGuard: isErrorEvent, format: formatError }, | ||
| log: { typeGuard: isLogEvent, format: formatLog }, | ||
| metric: { typeGuard: isMetricEvent, format: formatMetric }, | ||
| transaction: { typeGuard: isTraceEvent, format: formatTrace }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import type { Envelope } from "@sentry/core"; | ||
| import type { SentryMetricEvent, SentryMetricPayload } from "../../parser/index.ts"; | ||
| import { formatTimestamp } from "../utils.ts"; | ||
|
|
||
| function formatMetricRow(metric: SentryMetricPayload): string { | ||
| const timestamp = formatTimestamp(metric.timestamp); | ||
| const attributes = | ||
| metric.attributes && Object.keys(metric.attributes).length > 0 | ||
| ? Object.entries(metric.attributes) | ||
| .map(([key, attr]) => `${key}=${attr.value}`) | ||
| .join(", ") | ||
| : ""; | ||
|
|
||
| const traceInfo = metric.trace_id ? metric.trace_id.substring(0, 8) : ""; | ||
|
|
||
| return `| ${timestamp} | ${metric.name} | ${metric.type} | ${metric.value} | ${metric.unit ?? ""} | ${traceInfo} | ${attributes} |`; | ||
| } | ||
|
|
||
| export function formatMetric(event: SentryMetricEvent, _envelopeHeader: Envelope[0]): string[] { | ||
| const lines: string[] = []; | ||
|
|
||
| lines.push("## Metrics"); | ||
| lines.push(""); | ||
| lines.push("| Timestamp | Name | Type | Value | Unit | Trace | Attributes |"); | ||
| lines.push("|-----------|------|------|-------|------|-------|------------|"); | ||
|
|
||
| for (const metric of event.items) { | ||
| lines.push(formatMetricRow(metric)); | ||
| } | ||
|
|
||
| return lines; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.