Skip to content

Commit

Permalink
feat: Add Sentry Profiler and profiling for code renderers (#3141)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov authored Aug 21, 2024
1 parent eb08cd0 commit 845a181
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultConfig = {
STRIPE_KEY: '',
SENTRY_ENVIRONMENT: 'staging',
SENTRY_TRACING_SAMPLE_RATE: 1.0,
SENTRY_PROFILING_SAMPLE_RATE: 0.1,
SENTRY_SESSION_SAMPLE_RATE: 0.1,
SENTRY_ERROR_SAMPLE_RATE: 1.0,
GH_APP: 'codecov',
Expand Down Expand Up @@ -40,6 +41,12 @@ export function removeReactAppPrefix(obj) {
)
}

if ('SENTRY_PROFILING_SAMPLE_RATE' in keys) {
keys['SENTRY_PROFILING_SAMPLE_RATE'] = parseFloat(
keys['SENTRY_PROFILING_SAMPLE_RATE']
)
}

if ('SENTRY_SESSION_SAMPLE_RATE' in keys) {
keys['SENTRY_SESSION_SAMPLE_RATE'] = parseFloat(
keys['SENTRY_SESSION_SAMPLE_RATE']
Expand Down
5 changes: 5 additions & 0 deletions src/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ export const setupSentry = ({
// Adds Sentry Replay
Sentry.replayIntegration(),

// Adds Sentry browser profiling
Sentry.browserProfilingIntegration(),

// Adds routing instrumentation
Sentry.reactRouterV5BrowserTracingIntegration({
history,
Expand All @@ -134,6 +137,8 @@ export const setupSentry = ({
replaysSessionSampleRate: config?.SENTRY_SESSION_SAMPLE_RATE,
// Of the remaining x% of sessions, if an error happens start capturing
replaysOnErrorSampleRate: config?.SENTRY_ERROR_SAMPLE_RATE,
// profiling sample rate
profilesSampleRate: config?.SENTRY_PROFILING_SAMPLE_RATE,
beforeSend: (event, _hint) => {
if (checkForBlockedUserAgents()) {
return null
Expand Down
1 change: 1 addition & 0 deletions src/shared/RawFileViewer/RawFileViewer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jest.mock('@sentry/react', () => {
const originalModule = jest.requireActual('@sentry/react')
return {
...originalModule,
withProfiler: (component: any) => component,
captureMessage: jest.fn(),
}
})
Expand Down
9 changes: 9 additions & 0 deletions src/ui/CodeRenderer/CodeRenderer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react'

import CodeRenderer from './CodeRenderer'

jest.mock('@sentry/react', () => {
const originalModule = jest.requireActual('@sentry/react')
return {
...originalModule,
withProfiler: (component: any) => component,
captureMessage: jest.fn(),
}
})

window.requestAnimationFrame = (cb) => {
cb(1)
return 1
Expand Down
5 changes: 4 additions & 1 deletion src/ui/CodeRenderer/CodeRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Sentry from '@sentry/react'
import Highlight, { defaultProps } from 'prism-react-renderer'
import { useLayoutEffect, useRef } from 'react'

Expand Down Expand Up @@ -103,4 +104,6 @@ function CodeRenderer({
)
}

export default CodeRenderer
export default Sentry.withProfiler(CodeRenderer, {
name: 'CodeRenderer',
})
1 change: 1 addition & 0 deletions src/ui/VirtualFileRenderer/VirtualFileRenderer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jest.mock('@sentry/react', () => {
const originalModule = jest.requireActual('@sentry/react')
return {
...originalModule,
withProfiler: (component: any) => component,
captureMessage: jest.fn(),
}
})
Expand Down
9 changes: 8 additions & 1 deletion src/ui/VirtualFileRenderer/VirtualFileRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ interface VirtualFileRendererProps {
fileName: string
}

export function VirtualFileRenderer({
function VirtualFileRendererComponent({
code,
coverage,
fileName: fileType,
Expand Down Expand Up @@ -466,3 +466,10 @@ export function VirtualFileRenderer({
</div>
)
}

export const VirtualFileRenderer = Sentry.withProfiler(
VirtualFileRendererComponent,
{
name: 'VirtualFileRenderer',
}
)

0 comments on commit 845a181

Please sign in to comment.