# Browser Error Monitoring - Sentry.io
### 05/23
* 已在Browswer, Relay, Sentry端分別進行資料過濾
### Concern
* 確認不會有預期外的資料流出
* 不同SDK(PHP, JS ...)可能送出不同的欄位, 需要各別檢查(?
## Relay - `Static` Mode for Advanced Data Scrubbing
> When running Relay in either `static` or `proxy` mode, you can configure project settings on the file system. Static project configurations are found under the projects subdirectory of the Relay configuration directory, By default, this is located at .relay/projects.
* ([Tutorial1](https://docs.sentry.io/product/data-management-settings/scrubbing/advanced-datascrubbing/), [Tutorial2](https://docs.sentry.io/product/relay/pii-and-data-scrubbing/)) Advanced Data Scrubbing allows you to:
* Define custom regular expressions to match on sensitive data
* Detailed tuning on which parts of an event to scrub
* Partial removal or hashing of sensitive data instead of deletion
### Configuration
```yaml=
# config.yml
relay:
mode: static
logging:
level: trace
type: json
```
## Sensitive Data Category
* **Stack-locals**:Some SDKs (Python, PHP and Node) will **pick up variable values within the stacktrace**. These can be scrubbed, or this behavior can be disabled altogether if necessary.
* 【Breadcrumbs】 Some SDKs (JavaScript and the Java logging integrations, for example) will pick up previously executed log statements. Do not log PII if using this feature and including log statements as breadcrumbs in the event. Some backend SDKs will also record database queries, which may need to be scrubbed.
* 【User context】 Automated behavior is controlled via sendDefaultPii.
* 【HTTP context】 Query strings may be picked up in some frameworks as part of the HTTP request context.
* 【Transaction Names】 In certain situations, transaction names might contain sensitive data. For example, a browser's pageload transaction might have a raw URL like /users/1234/details as its name (where 1234 is a user id, which may be considered PII). In most cases, our SDKs can parameterize URLs and routes successfully, that is, turn /users/1234/details into /users/:userid/details. However, depending on the framework, your routing configuration, race conditions, and a few other factors, the SDKs might not be able to completely parameterize all of your URLs.
### Sentry Javascript SDK for Scrubbing
We recommend using `beforeSend` and `beforeSendTransaction` in the SDKs to scrub any data before it is sent, to ensure that sensitive data never leaves the local environment.
* `beforeSend`:invoked before an error or message event is sent.
* `beforeSendTransaction`:invoked before a transaction is sent.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://js.sentry-cdn.com/eda104d5e3834801b99fffa58b0feb49.min.js" crossorigin="anonymous"></script>
<title>Document</title>
</head>
<body>
helloworld
<script>
Sentry.init({
dsn: "http://eda104d5e3834801b99fffa58b0feb49@localhost:3000/4505185930510336",
beforeSend(event) {
console.log(event);
return event;
},
beforeSendTransaction(event) {
console.log(event);
return event;
},
});
test123();
</script>
</body>
</html>
```
### `beforeSend` Output
```javascript=
{
"exception": {
"values": [
{
"type": "ReferenceError",
"value": "test123 is not defined",
"stacktrace": {
"frames": [
{
"filename": "file:///home/kasm-user/Documents/index.html",
"function": "?",
"in_app": true,
"lineno": 26,
"colno": 9
}
]
},
"mechanism": {
"type": "onerror",
"handled": false
}
}
]
},
"level": "error",
"platform": "javascript",
"event_id": "a729e45fbd1c41e7b94288377eca540d",
"timestamp": 1684302159.799,
"environment": "production",
"sdk": {
"integrations": [
"InboundFilters",
"FunctionToString",
"TryCatch",
"Breadcrumbs",
"GlobalHandlers",
"LinkedErrors",
"Dedupe",
"HttpContext",
"BrowserTracing",
"Replay"
],
"name": "sentry.javascript.browser",
"version": "7.52.1",
"packages": [
{
"name": "loader:@sentry/browser",
"version": "7.52.1"
}
]
},
"contexts": {
"trace": {
"op": "pageload",
"span_id": "8fa177479d705fa9",
"status": "internal_error",
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
}
},
"tags": {
"transaction": "/home/kasm-user/Documents/index.html"
},
"request": {
"url": "file:///home/kasm-user/Documents/index.html",
"headers": {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
}
}
}
```
### `beforeSendTransaction` Output
```javascript=
{
"contexts": {
"trace": {
"op": "pageload",
"span_id": "8fa177479d705fa9",
"status": "internal_error",
"tags": {
"effectiveConnectionType": "4g",
"deviceMemory": "8 GB",
"hardwareConcurrency": "2",
"lcp.element": "body",
"lcp.size": 1190
},
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
}
},
"spans": [
{
"description": "domContentLoadedEvent",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "94e837078adb8022",
"start_timestamp": 1684302159.7561,
"timestamp": 1684302159.7561,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "loadEvent",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "9b87cbb90392e2d1",
"start_timestamp": 1684302159.8297,
"timestamp": 1684302159.8297,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "connect",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "ae6c0a59a77118cb",
"start_timestamp": 1684302159.7114,
"timestamp": 1684302159.7114,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "cache",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "8396efa9b309e79c",
"start_timestamp": 1684302159.7114,
"timestamp": 1684302159.7114,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "DNS",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "ba6621e7ef44f5f2",
"start_timestamp": 1684302159.7114,
"timestamp": 1684302159.7114,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "request",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "91f317723a105eef",
"start_timestamp": 1684302159.7114,
"timestamp": 1684302159.7182,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "response",
"op": "browser",
"parent_span_id": "8fa177479d705fa9",
"span_id": "ba47383de6f349a3",
"start_timestamp": 1684302159.7114,
"timestamp": 1684302159.7182,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"data": {
"http.response_transfer_size": 0,
"http.response_content_length": 1246,
"http.decoded_response_content_length": 2503,
"resource.render_blocking_status": "blocking"
},
"description": "https://js.sentry-cdn.com/eda104d5e3834801b99fffa58b0feb49.min.js",
"op": "resource.script",
"parent_span_id": "8fa177479d705fa9",
"span_id": "a871bac662069216",
"start_timestamp": 1684302159.7319999,
"timestamp": 1684302159.7408,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"data": {
"http.response_transfer_size": 1546,
"http.response_content_length": 1246,
"http.decoded_response_content_length": 2503,
"resource.render_blocking_status": "non-blocking"
},
"description": "https://js.sentry-cdn.com/eda104d5e3834801b99fffa58b0feb49.min.js",
"op": "resource.other",
"parent_span_id": "8fa177479d705fa9",
"span_id": "9cfbbe6d8540fd12",
"start_timestamp": 1684302159.746,
"timestamp": 1684302159.9701002,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"data": {
"http.response_transfer_size": 0,
"http.response_content_length": 0,
"http.decoded_response_content_length": 0,
"resource.render_blocking_status": "non-blocking"
},
"description": "https://browser.sentry-cdn.com/7.52.1/bundle.tracing.replay.min.js",
"op": "resource.script",
"parent_span_id": "8fa177479d705fa9",
"span_id": "9fa1a99fb6bd82b1",
"start_timestamp": 1684302159.7466,
"timestamp": 1684302159.7552998,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "sentry-tracing-init",
"op": "mark",
"parent_span_id": "8fa177479d705fa9",
"span_id": "bb49d51b15105e96",
"start_timestamp": 1684302159.7882,
"timestamp": 1684302159.7882,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "first-paint",
"op": "paint",
"parent_span_id": "8fa177479d705fa9",
"span_id": "b813437a382a2f02",
"start_timestamp": 1684302160.001,
"timestamp": 1684302160.001,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
},
{
"description": "first-contentful-paint",
"op": "paint",
"parent_span_id": "8fa177479d705fa9",
"span_id": "a48d0aae0d822178",
"start_timestamp": 1684302160.001,
"timestamp": 1684302160.001,
"trace_id": "1e94f73c34224410a1ca2acdb66711e2"
}
],
"start_timestamp": 1684302159.711,
"tags": {
"effectiveConnectionType": "4g",
"deviceMemory": "8 GB",
"hardwareConcurrency": "2",
"lcp.element": "body",
"lcp.size": 1190
},
"timestamp": 1684302160.001,
"transaction": "/home/kasm-user/Documents/index.html",
"type": "transaction",
"transaction_info": {
"source": "url"
},
"measurements": {
"lcp": {
"value": 290,
"unit": "millisecond"
},
"fp": {
"value": 290,
"unit": "millisecond"
},
"fcp": {
"value": 290,
"unit": "millisecond"
},
"connection.rtt": {
"value": 0,
"unit": "millisecond"
},
"ttfb": {
"value": 0.4000663757324219,
"unit": "millisecond"
},
"ttfb.requestTime": {
"value": 0,
"unit": "millisecond"
}
},
"platform": "javascript",
"event_id": "6207ab8dcf6f446da41d84fd7f5c5b37",
"environment": "production",
"sdk": {
"integrations": [
"InboundFilters",
"FunctionToString",
"TryCatch",
"Breadcrumbs",
"GlobalHandlers",
"LinkedErrors",
"Dedupe",
"HttpContext",
"BrowserTracing",
"Replay"
],
"name": "sentry.javascript.browser",
"version": "7.52.1",
"packages": [
{
"name": "loader:@sentry/browser",
"version": "7.52.1"
}
]
},
"breadcrumbs": [
{
"timestamp": 1684302159.801,
"category": "console",
"data": {
"arguments": [
"a"
],
"logger": "console"
},
"level": "log",
"message": "a"
},
{
"timestamp": 1684302159.802,
"category": "console",
"data": {
"arguments": [
{
"exception": "[Object]",
"level": "error",
"platform": "javascript",
"event_id": "a729e45fbd1c41e7b94288377eca540d",
"timestamp": 1684302159.799,
"environment": "production",
"sdk": "[Object]",
"contexts": "[Object]",
"tags": "[Object]",
"request": "[Object]"
},
{
"event_id": "a729e45fbd1c41e7b94288377eca540d",
"integrations": "[Array]"
}
],
"logger": "console"
},
"level": "log",
"message": "[object Object] [object Object]"
},
{
"timestamp": 1684302159.803,
"category": "sentry.event",
"event_id": "a729e45fbd1c41e7b94288377eca540d",
"level": "error",
"message": "ReferenceError: test123 is not defined"
}
],
"request": {
"url": "file:///home/kasm-user/Documents/index.html",
"headers": {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36"
}
}
}
```