-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: queue time metric #16030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: queue time metric #16030
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ed1cb82
add last_updated information to develop docs
dingsdax 16ad85f
fix TS null vs undefined
dingsdax 4e916b6
Lint
dingsdax 2fa50bb
Merge branch 'master' into develop_doc_last_updated
dingsdax 928a878
[getsentry/action-github-commit] Auto commit
getsantry[bot] 60325f6
[getsentry/action-github-commit] Auto commit
getsantry[bot] 2261774
Fix for only showing on develop docs
dingsdax 353c895
[getsentry/action-github-commit] Auto commit
getsantry[bot] f387289
return new object copies, preventing reference sharing in cached meta…
dingsdax df13418
[getsentry/action-github-commit] Auto commit
getsantry[bot] af1d879
Add some debug code
dingsdax 6733525
Update getGitMetadata.ts
dingsdax dbee391
Capture queue time docs
dingsdax 8a1891a
Merge branch 'master' into queue-time-metric
dingsdax 340aa90
[getsentry/action-github-commit] Auto commit
getsantry[bot] d421c30
[getsentry/action-github-commit] Auto commit
getsantry[bot] 72c0502
remove unrelated code
dingsdax de260a4
Merge branch 'master' into queue-time-metric
dingsdax 9dec483
Apply suggestions from code review
dingsdax f7ddb6f
Fix attribute name, simplify options
dingsdax 7381a33
Merge branch 'master' into queue-time-metric
dingsdax 1d55734
Merge branch 'master' into queue-time-metric
dingsdax 100bfc5
docs(ruby): Review and fix queue time capture docs
dingsdax 5894dc4
fix(ruby): Use PlatformLink for queue time capture reference in options
dingsdax faf703b
Merge branch 'master' into queue-time-metric
dingsdax d26bcc0
Merge branch 'master' into queue-time-metric
dingsdax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
| ## Automatic Queue Time Capture | ||
|
|
||
| The Ruby SDK automatically captures queue time for Rack-based applications when the `X-Request-Start` header is present. This measures how long requests wait in the web server queue (e.g., waiting for a Puma thread) before your application begins processing them. | ||
|
|
||
| Queue time is attached to transactions as `http.queue_time_ms` and helps identify server capacity issues. | ||
|
|
||
| ### Setup | ||
|
|
||
| Configure your reverse proxy to add the `X-Request-Start` header: | ||
|
|
||
| **Nginx:** | ||
|
|
||
| ```nginx | ||
| location / { | ||
| proxy_pass http://your-app; | ||
| proxy_set_header X-Request-Start "t=${msec}"; | ||
| } | ||
| ``` | ||
|
|
||
| **HAProxy:** | ||
|
|
||
| ```haproxy | ||
| frontend http-in | ||
| http-request set-header X-Request-Start t=%Ts%ms | ||
| ``` | ||
|
|
||
| **Heroku:** The header is automatically set by Heroku's router. | ||
|
|
||
| ### How It Works | ||
|
|
||
| The SDK: | ||
|
|
||
| 1. Reads the `X-Request-Start` header timestamp from your reverse proxy | ||
| 2. Calculates the time difference between the header timestamp and when the request reaches your application | ||
| 3. Subtracts `puma.request_body_wait` (if present) to exclude time spent waiting for slow client uploads | ||
| 4. Attaches the result as `http.queue_time_ms` to the transaction | ||
|
|
||
| ### Disable Queue Time Capture | ||
|
|
||
| If you don't want queue time captured, disable it in your configuration: | ||
|
|
||
| ```ruby | ||
| Sentry.init do |config| | ||
| config.capture_queue_time = false | ||
| end | ||
| ``` | ||
|
|
||
| ### Viewing Queue Time | ||
|
|
||
| Queue time appears in the Sentry transaction details under the "Data" section as `http.queue_time_ms` (measured in milliseconds). |
This file contains hidden or 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 hidden or 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,101 @@ | ||
| 'use client'; | ||
|
|
||
| import Link from 'next/link'; | ||
|
|
||
| interface GitMetadata { | ||
| author: string; | ||
| commitHash: string; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| interface LastUpdatedProps { | ||
| gitMetadata: GitMetadata; | ||
| } | ||
|
|
||
| /** | ||
| * Format a timestamp as a relative time string (e.g., "2 days ago") | ||
| */ | ||
| function formatRelativeTime(timestamp: number): string { | ||
| const now = Date.now(); | ||
| const diff = now - timestamp * 1000; // timestamp is in seconds | ||
| const seconds = Math.floor(diff / 1000); | ||
| const minutes = Math.floor(seconds / 60); | ||
| const hours = Math.floor(minutes / 60); | ||
| const days = Math.floor(hours / 24); | ||
| const months = Math.floor(days / 30); | ||
| const years = Math.floor(days / 365); | ||
|
|
||
| if (years > 0) { | ||
| return years === 1 ? '1 year ago' : `${years} years ago`; | ||
| } | ||
| if (months > 0) { | ||
| return months === 1 ? '1 month ago' : `${months} months ago`; | ||
| } | ||
| if (days > 0) { | ||
| return days === 1 ? '1 day ago' : `${days} days ago`; | ||
| } | ||
| if (hours > 0) { | ||
| return hours === 1 ? '1 hour ago' : `${hours} hours ago`; | ||
| } | ||
| if (minutes > 0) { | ||
| return minutes === 1 ? '1 minute ago' : `${minutes} minutes ago`; | ||
| } | ||
| return 'just now'; | ||
| } | ||
|
|
||
| /** | ||
| * Format a timestamp as a full date string for tooltip | ||
| */ | ||
| function formatFullDate(timestamp: number): string { | ||
| const date = new Date(timestamp * 1000); | ||
| return date.toLocaleString('en-US', { | ||
| year: 'numeric', | ||
| month: 'long', | ||
| day: 'numeric', | ||
| hour: 'numeric', | ||
| minute: '2-digit', | ||
| hour12: true, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Abbreviate a commit hash to first 7 characters | ||
| */ | ||
| function abbreviateHash(hash: string): string { | ||
| return hash.substring(0, 7); | ||
| } | ||
|
|
||
| export function LastUpdated({gitMetadata}: LastUpdatedProps) { | ||
| const {commitHash, author, timestamp} = gitMetadata; | ||
| const relativeTime = formatRelativeTime(timestamp); | ||
| const fullDate = formatFullDate(timestamp); | ||
| const abbreviatedHash = abbreviateHash(commitHash); | ||
| const commitUrl = `https://github.com/getsentry/sentry-docs/commit/${commitHash}`; | ||
|
|
||
| return ( | ||
| <div className="flex flex-wrap items-center gap-1 text-xs text-[var(--foreground-secondary)] mt-1 mb-4"> | ||
| {/* Text content */} | ||
| <span className="flex flex-wrap items-center gap-1"> | ||
| <span>updated by</span> | ||
| <span className="font-medium">{author}</span> | ||
| {/* Relative time with tooltip */} | ||
| <span title={fullDate} className="cursor-help"> | ||
| {relativeTime} | ||
| </span> | ||
| </span> | ||
|
|
||
| {/* Commit link */} | ||
| <span className="flex items-center gap-1"> | ||
| <span className="text-[var(--foreground-secondary)]">•</span> | ||
| <Link | ||
| href={commitUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className="hover:text-[var(--accent-purple)] underline" | ||
| > | ||
| #{abbreviatedHash} | ||
| </Link> | ||
| </span> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,70 @@ | ||
| import {execSync} from 'child_process'; | ||
| import path from 'path'; | ||
|
|
||
| export interface GitMetadata { | ||
| author: string; | ||
| commitHash: string; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| // Cache to avoid repeated git calls during build | ||
| const gitMetadataCache = new Map<string, GitMetadata | null>(); | ||
|
|
||
| /** | ||
| * Get git metadata for a file | ||
| * @param filePath - Path to the file relative to the repository root | ||
| * @returns Git metadata or null if unavailable | ||
| */ | ||
| export function getGitMetadata(filePath: string): GitMetadata | null { | ||
| // Check cache first | ||
| if (gitMetadataCache.has(filePath)) { | ||
| const cached = gitMetadataCache.get(filePath); | ||
| // Return a NEW copy to avoid reference sharing | ||
| return cached ? {...cached} : null; | ||
| } | ||
|
|
||
| try { | ||
| // Get commit hash, author name, and timestamp | ||
| const logOutput = execSync(`git log -1 --format="%H|%an|%at" -- "${filePath}"`, { | ||
| encoding: 'utf8', | ||
| cwd: path.resolve(process.cwd()), | ||
| stdio: ['pipe', 'pipe', 'ignore'], // Suppress stderr | ||
| }).trim(); | ||
|
|
||
| // Log for debugging on Vercel | ||
| if (process.env.CI || process.env.VERCEL) { | ||
| console.log(`[getGitMetadata] File: ${filePath} -> Output: ${logOutput}`); | ||
| } | ||
|
|
||
| if (!logOutput) { | ||
| // No commits found for this file | ||
| gitMetadataCache.set(filePath, null); | ||
| return null; | ||
| } | ||
|
|
||
| const [commitHash, author, timestampStr] = logOutput.split('|'); | ||
| const timestamp = parseInt(timestampStr, 10); | ||
|
cursor[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| // Create a fresh object for each call to avoid reference sharing | ||
| const metadata: GitMetadata = { | ||
| commitHash, | ||
| author, | ||
| timestamp, | ||
| }; | ||
|
|
||
| // Cache the metadata | ||
| gitMetadataCache.set(filePath, metadata); | ||
|
|
||
| // IMPORTANT: Return a NEW object, not the cached one | ||
| // This prevents all pages from sharing the same object reference | ||
| return { | ||
| commitHash: metadata.commitHash, | ||
| author: metadata.author, | ||
| timestamp: metadata.timestamp, | ||
| }; | ||
| } catch (error) { | ||
| // Git command failed or file doesn't exist in git | ||
| gitMetadataCache.set(filePath, null); | ||
| return null; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.