Example Use Cases
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.
Count button clicks on subpages
- Metric type:
counter
- Example JavaScript code:
Copied
Sentry.metrics.increment("button_click", 1, {
tags: { browser: "Firefox", subpage: "signup" }
});
Track number of user signups
- Metric type:
counter
- Example JavaScript code:
Copied
Sentry.metrics.increment("signups", 1, {
tags: { plan_type: “freemium”, region: "EU" }
});
Measure UX improvement to signup form
- Metric type:
distribution
- Example JavaScript code:
Copied
Sentry.metrics.distribution("login.time_to_finish_form", 14.3, {
tags: { subpage: “signup” },
unit: “second”
});
Track the loading time for a component
- Metric type:
distribution
- Example JavaScript code:
Copied
Sentry.metrics.distribution("component_load_time", 15.0, {
tags: { type: "important" },
unit: "millisecond"
});
Track API request payloads
- Metric type:
distribution
- Example JavaScript code:
Copied
Sentry.metrics.distribution("api_request_payload", 136.3, {
tags: { api_name: “maps_provider”, subpage: “signup” },
unit: “kilobyte”
});
Count concurrent users in application
- Metric type:
gauge
- Example JavaScript code:
Copied
Sentry.metrics.gauge("concurrent_users", 10, {
tags: { browser: "Firefox" }
});
Track the number of items in a shopping cart
- Metric type:
gauge
- Example JavaScript code:
Copied
Sentry.metrics.gauge("shopping_cart_item_count", itemCount, {
tags: { platform: "web" }
});
Count the unique number of users on a page
- Metric type:
set
- Example JavaScript code:
Copied
Sentry.metrics.set("user_view", "jane", {
tags: {"page": "/home" }
});
Count unique number of user sessions
- Metric type:
set
- Example JavaScript code:
Copied
Sentry.metrics.set("unique_active_sessions", sessionId, {
tags: { platform: "mobile" }
});
Count of API calls of a 3rd party API
- Metric type:
counter
- Example Python code:
Copied
sentry_sdk.metrics.incr(
key = "api_calls",
value = 1,
tags = {"api": "third_party"}
)
Count of jobs executed per worker
- Metric type:
counter
- Example Python code:
Copied
sentry_sdk.metrics.incr(
key = ”external_api_calls”,
value = 1,
tags = {”worker_id”: “485ea324-003d-4f30-a0f9”, “type”: ”standard”}
)
Processing time for a task
- Metric type:
distribution
- Example Python code:
Copied
sentry_sdk.metrics.distribution(
key = ”processing_time”,
value = 0.002,
unit = ”second”,
tags = {”task”: “example_task”}
)
Track ML model confidence during inference
- Metric type:
distribution
- Example Python code:
Copied
sentry_sdk.metrics.distribution(
key = ”model_confidence”,
value = 0.72,
unit = ”ratio”,
tags = {”model_id”: “a294c108”}
)
Track CPU usage over time
- Metric type:
gauge
- Example Python code:
Copied
sentry_sdk.metrics.gauge(
key = ”cpu_usage”,
value = 94,
unit = ”percent”
)
Track cache hit ratio
- Metric type:
gauge
- Example Python code:
Copied
sentry_sdk.metrics.gauge(
key = ”cache_hit_ratio”,
value = 85,
unit = ”percent”
)
Count unique server ids running a software version
- Metric type:
set
- Example Python code:
Copied
sentry_sdk.metrics.set(
key = ”server_ids_running”,
value = “server_id”,
tags = {"software_version": software_version}
)
Track number of unique DB queries executed
- Metric type:
set
- Example Python code:
Copied
sentry_sdk.metrics.set(
key = ”db_queries”,
value = query,
tags = {"query_type": "read"}
)
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").