From f8e2719f0179ff89bd9a2ebfa3e7de00e4ce0640 Mon Sep 17 00:00:00 2001 From: Alexandra Cota Date: Thu, 25 Jul 2024 10:47:51 +0200 Subject: [PATCH 1/6] Custom to Span metrics updates --- docs/product/explore/metrics/index.mdx | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/docs/product/explore/metrics/index.mdx b/docs/product/explore/metrics/index.mdx index d497782e7821e..0b927eb9c850c 100644 --- a/docs/product/explore/metrics/index.mdx +++ b/docs/product/explore/metrics/index.mdx @@ -12,17 +12,6 @@ Sentry metrics are numerical values that allow you to pinpoint and solve issues ![Metrics UI](./img/Index.png) -## Metric Types - -Metrics at Sentry come in different flavors, in order to help you track your data in the most efficient and cost-effective way. The metric types we currently support are: - -- **Counters:** Tracks a value that can only be incremented (for example, button clicks) -- **Distributions:** Tracks a list of values which can be aggregated over time like `max`, `min`, `avg` (for example, page load times) -- **Gauges:** Tracks a value that can go up or down (for example, available disk space, memory used) -- **Sets:** Tracks a set of values on which can be aggregations over time such as `count_unique` (for example, number of unique users) - -Each metric also needs to have a unit associated with it, so that you know what you're dealing with. Examples of units are seconds, milliseconds, bytes, or even potatoes if you like. - ## Augmenting Metrics with Tags Metrics are powerful on their own, but you can enrich them further by adding dimensions in the form of Tags. Metrics can be categorized, organized, and filtered based on these different dimensions, providing more granularity and flexibility in analyzing and querying your data. From 1de7cfb0bf5cf471eb6104883a9ec3ef800e0cdd Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Thu, 25 Jul 2024 13:50:25 +0200 Subject: [PATCH 2/6] adapt front-end code examples --- .../explore/metrics/metrics-examples.mdx | 108 ++++++------------ 1 file changed, 37 insertions(+), 71 deletions(-) diff --git a/docs/product/explore/metrics/metrics-examples.mdx b/docs/product/explore/metrics/metrics-examples.mdx index f36b4522b8b0b..42147cb608aa1 100644 --- a/docs/product/explore/metrics/metrics-examples.mdx +++ b/docs/product/explore/metrics/metrics-examples.mdx @@ -5,74 +5,61 @@ description: "Get some inspiration by browsing through example use cases for cus --- If you're not sure where to start, here are a few examples of how you can use custom metrics. +To track something using ## Frontend Examples
Count button clicks on subpages - * Metric type: `counter` + * Aggregation: `count` * Example JavaScript code: ```JavaScript - Sentry.metrics.increment("button_click", 1, { - tags: { browser: "Firefox", subpage: "signup" } - }); + Sentry.startSpan({ name: "mySpan"}, (span) => { + span.setAttributes({ +  ”button_click”: 1, +  browser: "Firefox", +  subpage: "signup", + }); + } ``` -
- -
- Track number of user signups - * Metric type: `counter` - * Example JavaScript code: + * Example - ```JavaScript - Sentry.metrics.increment("signups", 1, { -  tags: { plan_type: “freemium”, region: "EU" } - }); - ```
- Measure UX improvement to signup form + Track number of user signups - * Metric type: `distribution` + * Metric type: `count` * Example JavaScript code: ```JavaScript - Sentry.metrics.distribution("login.time_to_finish_form", 14.3, { -  tags: { subpage: “signup” }, -  unit: “second” + const span = Sentry.startInactiveSpan({name: “mySpan”}); +  span.setAttributes({ +  ”signups”: 1, +  “plan_type”: “freemium”, +  region: "EU", }); + span.end() ```
- Track the loading time for a component + Measure UX improvement to signup form * Metric type: `distribution` * Example JavaScript code: ```JavaScript - Sentry.metrics.distribution("component_load_time", 15.0, { -  tags: { type: "important" }, -  unit: "millisecond" - }); - ``` -
-
- Track API request payloads - - * Metric type: `distribution` - * Example JavaScript code: - - ```JavaScript - Sentry.metrics.distribution("api_request_payload", 136.3, { -  tags: { api_name: “maps_provider”, subpage: “signup” }, -  unit: “kilobyte” - }); + Sentry.startSpan({ name: "mySpan"}, (span) => { + span.setAttributes({ +  ”login.time_to_finish_form”: 14.3, +  subpage: "signup", + }); + } ```
@@ -83,22 +70,12 @@ If you're not sure where to start, here are a few examples of how you can use cu * Example JavaScript code: ```JavaScript - Sentry.metrics.gauge("concurrent_users", 10, { -  tags: { browser: "Firefox" } - }); - ``` - - -
- Track the number of items in a shopping cart - - * Metric type: `gauge` - * Example JavaScript code: - - ```JavaScript - Sentry.metrics.gauge("shopping_cart_item_count", itemCount, { -  tags: { platform: "web" } - }); + Sentry.startSpan({ name: "mySpan"}, (span) => { +  span.setAttributes({ +  ”concurrent_users”: 10, +  browser: "firefox", +  }); + } ```
@@ -109,27 +86,16 @@ If you're not sure where to start, here are a few examples of how you can use cu * Example JavaScript code: ```JavaScript - Sentry.metrics.set("user_view", "jane", { -  tags: {"page": "/home" } - }); - ``` - - -
- Count unique number of user sessions - - * Metric type: `set` - * Example JavaScript code: - - ```JavaScript - Sentry.metrics.set("unique_active_sessions", sessionId, { -  tags: { platform: "mobile" } - }); + Sentry.startSpan({ name: "mySpan"}, (span) => { +  span.setAttributes({ +  ”user_view”: “jane”, +  page: "home", +  }); + } ```
- ## Backend Examples
From 180a8cd1b9895193d8132df8b174b8d1d25198e8 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Thu, 25 Jul 2024 14:05:01 +0200 Subject: [PATCH 3/6] add aggregations instead of metric types and backend examples --- .../explore/metrics/metrics-examples.mdx | 89 ++++++++----------- 1 file changed, 35 insertions(+), 54 deletions(-) diff --git a/docs/product/explore/metrics/metrics-examples.mdx b/docs/product/explore/metrics/metrics-examples.mdx index 42147cb608aa1..249cc24d7c3fc 100644 --- a/docs/product/explore/metrics/metrics-examples.mdx +++ b/docs/product/explore/metrics/metrics-examples.mdx @@ -32,7 +32,7 @@ To track something using
Track number of user signups - * Metric type: `count` + * Aggregation: `count` * Example JavaScript code: ```JavaScript @@ -49,7 +49,7 @@ To track something using
Measure UX improvement to signup form - * Metric type: `distribution` + * Aggregation: `p90` * Example JavaScript code: ```JavaScript @@ -66,7 +66,7 @@ To track something using
Count concurrent users in application - * Metric type: `gauge` + * Aggregation: `avg` * Example JavaScript code: ```JavaScript @@ -82,7 +82,7 @@ To track something using
Count the unique number of users on a page - * Metric type: `set` + * Aggregation: `count_unique` * Example JavaScript code: ```JavaScript @@ -101,121 +101,102 @@ To track something using
Count of API calls of a 3rd party API - * Metric type: `counter` + * Aggregation: `count` * Example Python code: ```Python - sentry_sdk.metrics.incr( -  key = "api_calls", -  value = 1, -  tags = {"api": "third_party"} - ) + with sentry_sdk.start_span(’my_span’): +  span.set_tag(”api”, “third_party”) +  span.set_attribute(”api_calls”, 1) ```
Count of jobs executed per worker - * Metric type: `counter` + * Aggregation: `count` * Example Python code: ```Python - sentry_sdk.metrics.incr( -  key = ”external_api_calls”, -  value = 1, -  tags = {”worker_id”: “485ea324-003d-4f30-a0f9”, “type”: ”standard”} - ) + with sentry_sdk.start_span(’my_span’): +  span.set_tag(”worker_id”, “485ea324-003d-4f30-a0f9”) +  span.set_tag(”type”, “standard”) +  span.set_attribute(”external_api_calls”, 1) ```
Processing time for a task - * Metric type: `distribution` + * Aggregation: `p99` * Example Python code: ```Python - sentry_sdk.metrics.distribution( -  key = ”processing_time”, -  value = 0.002, -  unit = ”second”, -  tags = {”task”: “example_task”} - ) + with sentry_sdk.start_span(’my_span’): +  span.set_tag(”task”, “example_task”) +  span.set_attribute(”processing_time”, 0.002) ```
Track ML model confidence during inference - * Metric type: `distribution` + * Aggregation: `p50` * Example Python code: ```Python - sentry_sdk.metrics.distribution( - key = ”model_confidence”, - value = 0.72, - unit = ”ratio”, - tags = {”model_id”: “a294c108”} - ) + with sentry_sdk.start_span(’model_confidence’): +  span.set_tag(”model_id”, “a294c108”) +  span.set_attribute(”model_confidence”, 0.72) ```
Track CPU usage over time - * Metric type: `gauge` + * Aggregation: `max` * Example Python code: ```Python - sentry_sdk.metrics.gauge( -  key = ”cpu_usage”, -  value = 94, -  unit = ”percent” - ) + with sentry_sdk.start_span(’my_span’): +  span.set_attribute(”cpu_usage”, 94) ```
Track cache hit ratio - * Metric type: `gauge` + * Aggregation: `avg` * Example Python code: ```Python - sentry_sdk.metrics.gauge( -  key = ”cache_hit_ratio”, -  value = 85, -  unit = ”percent” - ) + with sentry_sdk.start_span(’my_span’): +  span.set_attribute(”cache_hit_ratio”, 85) ```
Count unique server ids running a software version - * Metric type: `set` + * Aggregation: `count_unique` * Example Python code: ```Python - sentry_sdk.metrics.set( -  key = ”server_ids_running”, -  value = “server_id”, -  tags = {"software_version": software_version} - ) + with sentry_sdk.start_span(’my_span’): +  span.set_tag(”software_version”, software_version) +  span.set_attribute(”server_ids_running”, server_id) ```
Track number of unique DB queries executed - * Metric type: `set` + * Aggregation: `count_unique` * Example Python code: ```Python - sentry_sdk.metrics.set( -  key = ”db_queries”, -  value = query, -  tags = {"query_type": "read"} - ) + with sentry_sdk.start_span(’my_span’): +  span.set_tag(”query_type”, “read”) +  span.set_attribute(”db_queries”, query) ```
From af9df36bf90623520a6519848d70d69028738ffc Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Fri, 26 Jul 2024 09:43:32 +0200 Subject: [PATCH 4/6] fix quotation marks --- .../explore/metrics/metrics-examples.mdx | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/product/explore/metrics/metrics-examples.mdx b/docs/product/explore/metrics/metrics-examples.mdx index 249cc24d7c3fc..8d686efaf6a7f 100644 --- a/docs/product/explore/metrics/metrics-examples.mdx +++ b/docs/product/explore/metrics/metrics-examples.mdx @@ -18,7 +18,7 @@ To track something using ```JavaScript Sentry.startSpan({ name: "mySpan"}, (span) => { span.setAttributes({ -  ”button_click”: 1, +  button_click: 1,   browser: "Firefox",   subpage: "signup", }); @@ -36,10 +36,10 @@ To track something using * Example JavaScript code: ```JavaScript - const span = Sentry.startInactiveSpan({name: “mySpan”}); + const span = Sentry.startInactiveSpan({name: "mySpan"});   span.setAttributes({ -  ”signups”: 1, -  “plan_type”: “freemium”, +  signups: 1, +  plan_type: "freemium",   region: "EU", }); span.end() @@ -56,7 +56,7 @@ To track something using Sentry.startSpan({ name: "mySpan"}, (span) => { span.setAttributes({ -  ”login.time_to_finish_form”: 14.3, +  login.time_to_finish_form: 14.3,   subpage: "signup", }); } @@ -72,7 +72,7 @@ To track something using ```JavaScript Sentry.startSpan({ name: "mySpan"}, (span) => {   span.setAttributes({ -  ”concurrent_users”: 10, +  concurrent_users: 10,   browser: "firefox",   });  } @@ -88,7 +88,7 @@ To track something using ```JavaScript Sentry.startSpan({ name: "mySpan"}, (span) => {   span.setAttributes({ -  ”user_view”: “jane”, +  user_view: "jane",   page: "home",   });  } @@ -105,9 +105,9 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_tag(”api”, “third_party”) -  span.set_attribute(”api_calls”, 1) + with sentry_sdk.start_span("my_span"): +  span.set_tag("api", "third_party") +  span.set_attribute("api_calls", 1) ```
@@ -118,10 +118,10 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_tag(”worker_id”, “485ea324-003d-4f30-a0f9”) -  span.set_tag(”type”, “standard”) -  span.set_attribute(”external_api_calls”, 1) + with sentry_sdk.start_span("my_span"): +  span.set_tag("worker_id", "485ea324-003d-4f30-a0f9") +  span.set_tag("type", "standard") +  span.set_attribute("external_api_calls", 1) ```
@@ -132,9 +132,9 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_tag(”task”, “example_task”) -  span.set_attribute(”processing_time”, 0.002) + with sentry_sdk.start_span("my_span"): +  span.set_tag("task", “example_task") +  span.set_attribute("processing_time", 0.002) ```
@@ -146,8 +146,8 @@ To track something using ```Python with sentry_sdk.start_span(’model_confidence’): -  span.set_tag(”model_id”, “a294c108”) -  span.set_attribute(”model_confidence”, 0.72) +  span.set_tag("model_id", “a294c108") +  span.set_attribute("model_confidence", 0.72) ```
@@ -158,8 +158,8 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_attribute(”cpu_usage”, 94) + with sentry_sdk.start_span("my_span"): +  span.set_attribute("cpu_usage", 94) ```
@@ -170,8 +170,8 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_attribute(”cache_hit_ratio”, 85) + with sentry_sdk.start_span("my_span"): +  span.set_attribute("cache_hit_ratio", 85) ``` @@ -182,9 +182,9 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_tag(”software_version”, software_version) -  span.set_attribute(”server_ids_running”, server_id) + with sentry_sdk.start_span("my_span"): +  span.set_tag("software_version", software_version) +  span.set_attribute("server_ids_running", server_id) ``` @@ -195,8 +195,8 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’my_span’): -  span.set_tag(”query_type”, “read”) -  span.set_attribute(”db_queries”, query) + with sentry_sdk.start_span("my_span"): +  span.set_tag("query_type", “read") +  span.set_attribute("db_queries", query) ``` From 8348607f576283706950c057f2a2e64f7a5759f7 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Fri, 26 Jul 2024 11:32:12 +0200 Subject: [PATCH 5/6] fix quotation marks --- docs/product/explore/metrics/metrics-examples.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/product/explore/metrics/metrics-examples.mdx b/docs/product/explore/metrics/metrics-examples.mdx index 8d686efaf6a7f..9f5a806fabc1b 100644 --- a/docs/product/explore/metrics/metrics-examples.mdx +++ b/docs/product/explore/metrics/metrics-examples.mdx @@ -145,7 +145,7 @@ To track something using * Example Python code: ```Python - with sentry_sdk.start_span(’model_confidence’): + with sentry_sdk.start_span("model_confidence"):   span.set_tag("model_id", “a294c108")   span.set_attribute("model_confidence", 0.72) ``` @@ -196,7 +196,7 @@ To track something using ```Python with sentry_sdk.start_span("my_span"): -  span.set_tag("query_type", “read") +  span.set_tag("query_type", "read")   span.set_attribute("db_queries", query) ``` From 515d2ba3d75309a77d85f8107e0cf49a2c089306 Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Fri, 26 Jul 2024 13:00:03 +0200 Subject: [PATCH 6/6] remove dangling text and add callout for metric ui config --- docs/product/explore/metrics/metrics-examples.mdx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/product/explore/metrics/metrics-examples.mdx b/docs/product/explore/metrics/metrics-examples.mdx index 9f5a806fabc1b..d898edcc9605d 100644 --- a/docs/product/explore/metrics/metrics-examples.mdx +++ b/docs/product/explore/metrics/metrics-examples.mdx @@ -4,8 +4,13 @@ sidebar_order: 18 description: "Get some inspiration by browsing through example use cases for custom metrics." --- -If you're not sure where to start, here are a few examples of how you can use custom metrics. -To track something using +If you're not sure where to start, here are a few examples of how you can configure spans in order to extract span metrics. + + +Keep in mind that metrics need to configured in the UI before they can be seen in the Metrics Explorer. +Go to [Set Up and Configure](https://develop.sentry.dev/product/explore/metrics/metrics-set-up/) to see how metrics can be configured in the UI. + + ## Frontend Examples @@ -25,8 +30,6 @@ To track something using } ``` - * Example -