-
-
Notifications
You must be signed in to change notification settings - Fork 60
feat: Add support for Sentry Metrics #1260
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
Open
AbhiPrasad
wants to merge
11
commits into
master
Choose a base branch
from
abhi-electron-metrics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
69526e2
feat: Add support for Sentry Metrics
AbhiPrasad 2b7ddc4
thanks sentry
AbhiPrasad 2e8677e
fix export in renderer
AbhiPrasad d2ab590
make tests better
AbhiPrasad 36366b8
revert changelog formatting
AbhiPrasad 57680be
Merge branch 'master' into abhi-electron-metrics
AbhiPrasad c47aff9
changelog again
AbhiPrasad 52e1691
better name
AbhiPrasad cf242a6
fix types
AbhiPrasad f8dadae
fix tests
AbhiPrasad 799d972
remove
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import { | ||
| _INTERNAL_captureMetric, | ||
| getClient, | ||
| getCurrentScope, | ||
| MetricOptions, | ||
| MetricType, | ||
| SerializedMetric, | ||
| } from '@sentry/core'; | ||
| import { getIPC } from './ipc.js'; | ||
|
|
||
| function captureMetric(type: MetricType, name: string, value: number, options?: MetricOptions): void { | ||
| const client = getClient(); | ||
| _INTERNAL_captureMetric( | ||
| { type, name, value, unit: options?.unit, attributes: options?.attributes }, | ||
| { | ||
| scope: options?.scope ?? getCurrentScope(), | ||
| captureSerializedMetric: (_: unknown, metric: SerializedMetric) => getIPC(client).sendMetric(metric), | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @summary Increment a counter metric. Requires the `_experiments.enableMetrics` option to be enabled. | ||
| * | ||
| * @param name - The name of the counter metric. | ||
| * @param value - The value to increment by (defaults to 1). | ||
| * @param options - Options for capturing the metric. | ||
| * | ||
| * @example | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.count('api.requests', 1, { | ||
| * attributes: { | ||
| * endpoint: '/api/users', | ||
| * method: 'GET', | ||
| * status: 200 | ||
| * } | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example With custom value | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.count('items.processed', 5, { | ||
| * attributes: { | ||
| * processor: 'batch-processor', | ||
| * queue: 'high-priority' | ||
| * } | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function count(name: string, value: number = 1, options?: MetricOptions): void { | ||
| captureMetric('counter', name, value, options); | ||
| } | ||
|
|
||
| /** | ||
| * @summary Set a gauge metric to a specific value. Requires the `_experiments.enableMetrics` option to be enabled. | ||
| * | ||
| * @param name - The name of the gauge metric. | ||
| * @param value - The current value of the gauge. | ||
| * @param options - Options for capturing the metric. | ||
| * | ||
| * @example | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.gauge('memory.usage', 1024, { | ||
| * unit: 'megabyte', | ||
| * attributes: { | ||
| * process: 'web-server', | ||
| * region: 'us-east-1' | ||
| * } | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example Without unit | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.gauge('active.connections', 42, { | ||
| * attributes: { | ||
| * server: 'api-1', | ||
| * protocol: 'websocket' | ||
| * } | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function gauge(name: string, value: number, options?: MetricOptions): void { | ||
| captureMetric('gauge', name, value, options); | ||
| } | ||
|
|
||
| /** | ||
| * @summary Record a value in a distribution metric. Requires the `_experiments.enableMetrics` option to be enabled. | ||
| * | ||
| * @param name - The name of the distribution metric. | ||
| * @param value - The value to record in the distribution. | ||
| * @param options - Options for capturing the metric. | ||
| * | ||
| * @example | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.distribution('task.duration', 500, { | ||
| * unit: 'millisecond', | ||
| * attributes: { | ||
| * task: 'data-processing', | ||
| * priority: 'high' | ||
| * } | ||
| * }); | ||
| * ``` | ||
| * | ||
| * @example Without unit | ||
| * | ||
| * ``` | ||
| * Sentry.metrics.distribution('batch.size', 100, { | ||
| * attributes: { | ||
| * processor: 'batch-1', | ||
| * type: 'async' | ||
| * } | ||
| * }); | ||
| * ``` | ||
| */ | ||
| export function distribution(name: string, value: number, options?: MetricOptions): void { | ||
| captureMetric('distribution', name, value, options); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "electron-metrics", | ||
| "description": "Electron Metrics", | ||
| "version": "1.0.0", | ||
| "main": "src/main.js", | ||
| "dependencies": { | ||
| "@sentry/electron": "7.2.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| const { init, metrics } = require('@sentry/electron/renderer'); | ||
|
|
||
| init({ | ||
| debug: true, | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| metrics.count('User clicked submit button', 1, { | ||
| attributes: { | ||
| buttonId: 'submit-form', | ||
| formId: 'user-profile', | ||
| }, | ||
| }); | ||
| }, 500); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| const path = require('path'); | ||
|
|
||
| const { app, BrowserWindow } = require('electron'); | ||
| const { init, metrics } = require('@sentry/electron/main'); | ||
|
|
||
| init({ | ||
| dsn: '__DSN__', | ||
| debug: true, | ||
| onFatalError: () => {}, | ||
| }); | ||
|
|
||
| app.on('ready', () => { | ||
| const mainWindow = new BrowserWindow({ | ||
| show: false, | ||
| webPreferences: { | ||
| nodeIntegration: true, | ||
| contextIsolation: false, | ||
| }, | ||
| }); | ||
|
|
||
| mainWindow.loadFile(path.join(__dirname, 'index.html')); | ||
|
|
||
| setTimeout(() => { | ||
| metrics.count('User profile updated', 1, { | ||
| attributes: { | ||
| userId: 'user_123', | ||
| updatedFields: ['email', 'preferences'], | ||
| }, | ||
| }); | ||
| }, 500); | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| app.quit(); | ||
| }, 4000); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.