Sentry(v20.12.1) K8S 云原生架构探索,1分钟上手 JavaScript 性能监控-LMLPHP

系列

  1. Sentry-Go SDK 中文实践指南
  2. 一起来刷 Sentry For Go 官方文档之 Enriching Events
  3. Snuba:Sentry 新的搜索基础设施(基于 ClickHouse 之上)
  4. Sentry 10 K8S 云原生架构探索,Vue App 1 分钟快速接入
  5. Sentry(v20.12.1) K8S云原生架构探索,玩转前/后端监控与事件日志大数据分析,高性能高可用+可扩展可伸缩集群部署
  6. Sentry(v20.12.1) K8S 云原生架构探索,Sentry JavaScript SDK 三种安装加载方式
  7. Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT SDK 配置详解
  8. Sentry(v20.12.1) K8S 云原生架构探索, SENTRY FOR JAVASCRIPT 手动捕获事件基本用法
  9. Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT Source Maps 详解
  10. Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT 故障排除

通过性能监视,Sentry 可以跟踪您的软件性能,测量吞吐量和延迟等指标,并显示多个系统之间的错误影响。

安装

安装跟踪软件包:

ESM

# Using yarn
yarn add @sentry/tracing

# Using npm
npm install @sentry/tracing

CDN

<script
  <!--
    Note that `bundle.tracing.min.js` contains both `@sentry/browser` AND
    `@sentry/tracing`, and should therefore be used in place of
    `@sentry/browser`'s bundle rather than in addition to it.
  -->
  src="https://browser.sentry-cdn.com/5.29.2/bundle.tracing.min.js"
  integrity="sha384-4zxA5Bnxor/VkZae20EqPP3A/6vDlw1ZhqF7EvpmeTfWYFjPIDdaUSOk/q7G/bYw"
  crossorigin="anonymous"
></script>

配置

通过以下两种方式在您的应用中启用性能监控:

  1. 使用 SDK 配置中的 tracesSampleRate 选项将所有 transactions 的统一采样率设置为 01 之间的数字。(例如,要发送 20%transactions,请将 tracesSampleRate 设置为 0.2。)
  2. 通过为 tracesSampler 配置选项提供功能,基于 transaction 本身及其捕获的上下文动态控制采样率。

ESM

// If you're using one of our integration packages, like `@sentry/react` or
// `@sentry/angular`, substitute its name for `@sentry/browser` here
import * as Sentry from "@sentry/browser";

// If taking advantage of automatic instrumentation (highly recommended)
import { Integrations as TracingIntegrations } from "@sentry/tracing";
// Or, if only manually tracing
// import * as _ from "@sentry/tracing"
// Note: You MUST import the package in some way for tracing to work

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  // This enables automatic instrumentation (highly recommended), but is not
  // necessary for purely manual usage
  integrations: [new TracingIntegrations.BrowserTracing()],

  // To set a uniform sample rate
  tracesSampleRate: 0.2

  // Alternatively, to control sampling dynamically
  tracesSampler: samplingContext => { ... }
});

CDN

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  // This enables automatic instrumentation (highly recommended), but is not
  // necessary for purely manual usage
  integrations: [new Sentry.Integrations.BrowserTracing()],

  // To set a uniform sample rate
  tracesSampleRate: 0.2

  // Alternatively, to control sampling dynamically
  tracesSampler: samplingContext => { ... }
});

如果设置了这些选项之一,则将在您的应用程序中启用跟踪。虽然这些选项是互斥的,但是如果您同时设置了这两个选项,tracesSampler 将具有优先权。您可以在 Sampling Transactions 中了解有关它们如何工作的更多信息。

验证

首次启用跟踪时,通过将 tracesSampleRate 设置为 1.0 来验证其是否正常运行,因为这可以确保将每个事务发送到 Sentry。

一旦测试完成,我们建议在生产中降低这个值,方法是降低您的 tracesSampleRate 值,或者切换到使用 tracesSampler 来动态取样和过滤您的 transaction。

在没有采样的情况下,我们的自动检测将在任何用户加载任何页面或在应用程序中的任何位置导航时发送 transaction。那是很多 transactions!采样可以实现代表性数据,而无需占用系统或 Sentry transaction 配额。

中文文档陆续同步到:

我是为少。
微信:uuhells123。
公众号:黑客下午茶。
谢谢点赞支持👍👍👍!
01-21 18:56