-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for performance metrics (#811)
- Loading branch information
Showing
16 changed files
with
223 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 @@ | ||
import { BrowserClient } from '@sentry/browser'; | ||
import { convertIntegrationFnToClass } from '@sentry/core'; | ||
import type { IntegrationFn } from '@sentry/types'; | ||
|
||
import { ElectronRendererMetricsAggregator } from '../metrics'; | ||
|
||
const INTEGRATION_NAME = 'MetricsAggregator'; | ||
|
||
const metricsAggregatorIntegration: IntegrationFn = () => { | ||
return { | ||
name: INTEGRATION_NAME, | ||
setup(client: BrowserClient) { | ||
client.metricsAggregator = new ElectronRendererMetricsAggregator(); | ||
}, | ||
}; | ||
}; | ||
|
||
/** | ||
* Enables Sentry metrics monitoring. | ||
* | ||
* @experimental This API is experimental and might having breaking changes in the future. | ||
*/ | ||
// eslint-disable-next-line deprecation/deprecation | ||
export const MetricsAggregator = convertIntegrationFnToClass(INTEGRATION_NAME, metricsAggregatorIntegration); |
This file contains 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 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,42 @@ | ||
import { MeasurementUnit, MetricsAggregator, Primitive } from '@sentry/types'; | ||
|
||
import { IPCInterface } from '../common/ipc'; | ||
import { getIPC } from './ipc'; | ||
|
||
/** | ||
* Sends metrics to the Electron main process where they can be aggregated in a single process | ||
*/ | ||
export class ElectronRendererMetricsAggregator implements MetricsAggregator { | ||
private readonly _ipc: IPCInterface; | ||
|
||
public constructor() { | ||
this._ipc = getIPC(); | ||
} | ||
|
||
/** @inheritdoc */ | ||
public add( | ||
metricType: 'c' | 'g' | 's' | 'd', | ||
name: string, | ||
value: string | number, | ||
unit?: MeasurementUnit | undefined, | ||
tags?: Record<string, Primitive> | undefined, | ||
timestamp?: number | undefined, | ||
): void { | ||
this._ipc.sendAddMetric({ metricType, name, value, unit, tags, timestamp }); | ||
} | ||
|
||
/** @inheritdoc */ | ||
public flush(): void { | ||
// do nothing | ||
} | ||
|
||
/** @inheritdoc */ | ||
public close(): void { | ||
// do nothing | ||
} | ||
|
||
/** @inheritdoc */ | ||
public toString(): string { | ||
return ''; | ||
} | ||
} |
This file contains 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 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 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 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,6 @@ | ||
{ | ||
"method": "envelope", | ||
"sentryKey": "37f8a2ee37c0409d8970bc7559c7c7e4", | ||
"appId": "277345", | ||
"metrics": "parallel_requests@none:2:2:2:2:1|g|#release:metrics@1.0.0,environment:development,type:a|T0000000000\nhits@none:4|c|T0000000000\n" | ||
} |
This file contains 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,8 @@ | ||
{ | ||
"name": "metrics", | ||
"version": "1.0.0", | ||
"main": "src/main.js", | ||
"dependencies": { | ||
"@sentry/electron": "3.0.0" | ||
} | ||
} |
This file contains 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,3 @@ | ||
description: Metrics | ||
command: yarn | ||
|
This file contains 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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<script> | ||
const Sentry = require('@sentry/electron/renderer'); | ||
|
||
Sentry.init(); | ||
Sentry.metrics.increment('hits', 4); | ||
</script> | ||
</body> | ||
</html> |
This file contains 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,32 @@ | ||
const path = require('path'); | ||
|
||
const { app, BrowserWindow } = require('electron'); | ||
const Sentry = require('@sentry/electron'); | ||
|
||
Sentry.init({ | ||
dsn: '__DSN__', | ||
debug: true, | ||
autoSessionTracking: false, | ||
onFatalError: () => {}, | ||
_experiments: { | ||
metricsAggregator: true, | ||
}, | ||
}); | ||
|
||
Sentry.metrics.gauge('parallel_requests', 2, { tags: { type: 'a' } }); | ||
|
||
app.on('ready', () => { | ||
const mainWindow = new BrowserWindow({ | ||
show: false, | ||
webPreferences: { | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
}, | ||
}); | ||
|
||
mainWindow.loadFile(path.join(__dirname, 'index.html')); | ||
|
||
setTimeout(() => { | ||
Sentry.flush(2000); | ||
}, 2000); | ||
}); |