This is the third day of my participation in the August More text Challenge. For details, see:August is more challenging

The first step is to install dependencies

# Using yarn
yarn add @sentry/browser @sentry/tracing
# Using npm
npm install --save @sentry/browser @sentry/tracing
Copy the code

Step 2 Configuration

Front-end monitoring should not monitor a single module, it should monitor the entire project, so it should be configured in an entry file such as main.js

import * as Sentry from "@sentry/browser"; import { Integrations } from "@sentry/tracing"; Sentry.init({ dsn: "https://[email protected]/0", // Alternatively, use `process.env.npm_package_version` for a dynamic release version // if your build tool supports it. release: "[email protected] integrations: [new Integrations.BrowserTracing()], // Set tracesSampleRate to 1.0 to capture 100% // of transactions for performance monitoring. // We recommend adjusting Production tracesSampleRate: 1.0, maxValueLength: Before 999999999999999999999999999999999999999, / / a single value is truncated can have the maximum number of characters});Copy the code

PS: There must be some people wondering where the above DSN all come from, don’t worry, the next will talk about

Step 3 Configure the server

1. Log in to the Sentry account or create an account. 2

This is what it looks like when I open it

3, after creating a new project, enter the project, click Settings, there is the DNS mentioned above

Step 4 Verify

Write a random error code in the project, and then go to the project corresponding to the Sentry to see the error message.

That’s the basic configuration of sentry.


In my practical application, I found that the returned data was too long and truncated through the captureMessage method (similar to the buried point function, as shown in the code below)

Sentry.captureMessage(JSON.stringify({
    type: 'save',
    parms,
    res: res.data
  }));
Copy the code

After looking up the data, I found that the maxValueLength parameter (the maximum number of characters a single value can have before being truncated) can be configured at access time to control the length of the string (as in step 2).

Website address: sentry. IO