{"id":49786,"date":"2025-06-23T05:13:41","date_gmt":"2025-06-23T05:13:41","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=49786"},"modified":"2025-06-23T05:17:47","modified_gmt":"2025-06-23T05:17:47","slug":"sentry-how-sentry-captures-errors-internally","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/sentry-how-sentry-captures-errors-internally\/","title":{"rendered":"Sentry: How Sentry Captures Errors Internally"},"content":{"rendered":"\n<p>Behind the Scenes: How Sentry Works at Runtime Level<\/p>\n\n\n\n<p><strong>Sentry SDK sits inside your application, listens for errors at runtime, and sends them to the Sentry cloud<\/strong>, where you can <strong>view, debug, and track them in the dashboard.<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>Complete Beginner-to-Intermediate Guide to How Sentry Captures Errors Internally<\/strong><\/h1>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Learn how Sentry <strong>really works<\/strong> \u2014 how it collects errors, what it captures by default, how it integrates with your app runtime, and how it differs from traditional log readers.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udded What is Sentry?<\/h2>\n\n\n\n<p><strong>Sentry<\/strong> is a powerful <strong>real-time error tracking and performance monitoring tool<\/strong> used by developers and DevOps teams to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Capture runtime errors and exceptions from applications<\/li>\n\n\n\n<li>Monitor performance issues (slow transactions, bottlenecks)<\/li>\n\n\n\n<li>Debug problems faster with detailed context (stack trace, user, request, etc.)<\/li>\n<\/ul>\n\n\n\n<p>It supports <strong>40+ programming languages and frameworks<\/strong> like Node.js, Python, PHP, Java, .NET, React, Flutter, and more.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Here&#8217;s the full flow in simple terms:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>You install and initialize the Sentry SDK<\/strong> in your app (e.g., Node, Laravel, Python, Flutter, etc.)<\/li>\n\n\n\n<li>When your app <strong>throws an error or exception<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Sentry <strong>captures it automatically<\/strong> from the language runtime<\/li>\n\n\n\n<li>OR you can <strong>capture it manually<\/strong> using <code>Sentry.captureException()<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Sentry SDK <strong>collects contextual information<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Stack trace<\/li>\n\n\n\n<li>Request info (URL, headers, etc.)<\/li>\n\n\n\n<li>User info (if added)<\/li>\n\n\n\n<li>Environment (browser, OS, app version)<\/li>\n\n\n\n<li>Recent events (breadcrumbs)<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>The SDK <strong>sends that data as a JSON payload via HTTPS<\/strong> to your Sentry project (Sentry Cloud or self-hosted server)<\/li>\n\n\n\n<li>You log into the <strong>Sentry Dashboard<\/strong> and:\n<ul class=\"wp-block-list\">\n<li>View errors grouped by issue<\/li>\n\n\n\n<li>See full trace &amp; context<\/li>\n\n\n\n<li>Track how often they happen<\/li>\n\n\n\n<li>Get alerts via Slack\/email<\/li>\n\n\n\n<li>Fix and mark issues as resolved<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd0c How Does Sentry Work?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u274c Misconception:<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>&#8220;Sentry reads from log files, right?&#8221;<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Truth:<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Sentry does NOT read logs from files.<\/strong><br>It works by embedding a lightweight <strong>SDK (software library)<\/strong> directly inside your application code.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 How Sentry Collects Errors Internally<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Step-by-Step Breakdown:<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>You install the Sentry SDK<\/strong> into your application.<\/li>\n\n\n\n<li><strong>You initialize the SDK<\/strong> with a DSN (Data Source Name).<\/li>\n\n\n\n<li>The SDK <strong>hooks into the runtime environment<\/strong> (not the app server).<\/li>\n\n\n\n<li>It automatically listens to:\n<ul class=\"wp-block-list\">\n<li>Uncaught exceptions<\/li>\n\n\n\n<li>Unhandled promise rejections<\/li>\n\n\n\n<li>Warnings<\/li>\n\n\n\n<li>Framework-specific errors<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Errors are immediately <strong>serialized into JSON and sent to Sentry<\/strong> via HTTPS.<\/li>\n\n\n\n<li>You see the data inside the <strong>Sentry web dashboard<\/strong> in real-time.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 What Does Sentry Capture <em>Automatically<\/em>?<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Feature<\/th><th>Captured by Default<\/th><\/tr><\/thead><tbody><tr><td>Uncaught Exceptions<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Unhandled Promise Errors<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Stack Trace<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>HTTP Request Context<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Environment Info (OS, Browser)<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Breadcrumbs (User actions, logs)<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>User Agent<\/td><td>\u2705 Yes<\/td><\/tr><tr><td>Performance Traces (if enabled)<\/td><td>\u2705 Yes<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udee0\ufe0f What You Can Add Manually<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Manual Method<\/th><th>Use Case<\/th><\/tr><\/thead><tbody><tr><td><code>Sentry.captureException(err)<\/code><\/td><td>To capture handled errors<\/td><\/tr><tr><td><code>Sentry.captureMessage(\"info\")<\/code><\/td><td>To log messages without errors<\/td><\/tr><tr><td><code>Sentry.setUser({id, email})<\/code><\/td><td>To attach user context<\/td><\/tr><tr><td><code>Sentry.setTag(\"env\", \"prod\")<\/code><\/td><td>To add custom tags<\/td><\/tr><tr><td><code>Sentry.setContext(\"cart\", {...})<\/code><\/td><td>To pass structured metadata<\/td><\/tr><tr><td><code>Sentry.addBreadcrumb({...})<\/code><\/td><td>To log custom breadcrumbs<\/td><\/tr><tr><td><code>Sentry.startTransaction()<\/code><\/td><td>To start a manual performance trace<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd2c How Sentry Hooks into Runtime Environments<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Language \/ Stack<\/th><th>How It Hooks<\/th><\/tr><\/thead><tbody><tr><td><strong>Node.js<\/strong><\/td><td><code>process.on('uncaughtException')<\/code>, middleware, monkey patching <code>http<\/code>, <code>express<\/code>, etc.<\/td><\/tr><tr><td><strong>Python<\/strong><\/td><td><code>sys.excepthook<\/code>, <code>threading<\/code>, <code>logging<\/code>, Flask\/Django signal wrapping<\/td><\/tr><tr><td><strong>PHP<\/strong><\/td><td><code>register_shutdown_function()<\/code>, <code>set_exception_handler()<\/code><\/td><\/tr><tr><td><strong>Java<\/strong><\/td><td><code>Thread.UncaughtExceptionHandler<\/code>, servlet filters, AOP<\/td><\/tr><tr><td><strong>Flutter\/Dart<\/strong><\/td><td><code>FlutterError.onError<\/code>, <code>runZonedGuarded()<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>These hooks let Sentry <strong>capture exceptions at the lowest level<\/strong> before they&#8217;re written to logs.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udd1d Can Sentry Integrate with Logging Frameworks?<\/h2>\n\n\n\n<p>Yes. You can integrate it with your logging stack like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>winston<\/code> (Node.js)<\/li>\n\n\n\n<li><code>monolog<\/code> (Laravel, PHP)<\/li>\n\n\n\n<li><code>logback<\/code> \/ <code>slf4j<\/code> (Java)<\/li>\n\n\n\n<li>Python&#8217;s built-in <code>logging<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Node.js + Winston<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">const<\/span> winston = <span class=\"hljs-keyword\">require<\/span>(<span class=\"hljs-string\">'winston'<\/span>);\n<span class=\"hljs-keyword\">const<\/span> Sentry = <span class=\"hljs-keyword\">require<\/span>(<span class=\"hljs-string\">'@sentry\/node'<\/span>);\n<span class=\"hljs-keyword\">const<\/span> SentryTransport = <span class=\"hljs-keyword\">require<\/span>(<span class=\"hljs-string\">'@sentry\/winston'<\/span>).<span class=\"hljs-keyword\">default<\/span>;\n\nSentry.init({ dsn: <span class=\"hljs-string\">'https:\/\/your-dsn@sentry.io\/projectId'<\/span> });\n\n<span class=\"hljs-keyword\">const<\/span> logger = winston.createLogger({\n  transports: &#91;\n    <span class=\"hljs-keyword\">new<\/span> winston.transports.Console(),\n    <span class=\"hljs-keyword\">new<\/span> SentryTransport({ level: <span class=\"hljs-string\">'error'<\/span> }), <span class=\"hljs-comment\">\/\/ sends to Sentry<\/span>\n  ],\n});\n\nlogger.error(<span class=\"hljs-string\">'Database connection failed!'<\/span>);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd10 Is Sentry Safe to Use?<\/h2>\n\n\n\n<p>Yes. But:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Avoid sending sensitive data (PII, passwords)<\/li>\n\n\n\n<li>Use Sentry&#8217;s <strong>data scrubbing<\/strong> features<\/li>\n\n\n\n<li>Use <strong>self-hosted Sentry<\/strong> if compliance is critical (e.g., GDPR, HIPAA)<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcca Where Sentry Runs in the Stack<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Layer<\/th><th>Used by Sentry?<\/th><\/tr><\/thead><tbody><tr><td>OS \/ Kernel<\/td><td>\u274c No<\/td><\/tr><tr><td>Application Server<\/td><td>\u274c No<\/td><\/tr><tr><td><strong>Language Runtime<\/strong><\/td><td>\u2705 YES<\/td><\/tr><tr><td><strong>Application Code<\/strong><\/td><td>\u2705 YES (SDK)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>So Sentry works <strong>inside your app process<\/strong>, not outside it.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udf93 Recap \u2014 How Sentry Works (Simple Flow)<\/h2>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">Your App Code\n     \u2193\nSentry SDK hooks into language runtime\n     \u2193\n<span class=\"hljs-built_in\">Error<\/span> occurs (auto or manual capture)\n     \u2193\n<span class=\"hljs-built_in\">Error<\/span> serialized into <span class=\"hljs-built_in\">JSON<\/span>\n     \u2193\nSent via HTTPS to sentry.io (or on-prem server)\n     \u2193\nVisible <span class=\"hljs-keyword\">in<\/span> real-time on dashboard\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Behind the Scenes: How Sentry Works at Runtime Level Sentry SDK sits inside your application, listens for errors at runtime, and sends them to the Sentry cloud, where you can&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-49786","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=49786"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49786\/revisions"}],"predecessor-version":[{"id":49789,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49786\/revisions\/49789"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=49786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=49786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=49786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}