:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
import { StepDefinition } from '../steps'
import { SDK_DEFAULTS_DATE } from './_snippets/sdkDefaults'
export const getSentrySteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
const { CodeBlock, Markdown, CalloutBox, dedent } = ctx
return [
{
title: 'Install the packages',
badge: 'required',
content: (
<>
<Markdown>
Sentry is an error tracking platform. The PostHog-Sentry integration links error data to your
analytics, allowing you to see which users experienced errors.
</Markdown>
<CodeBlock
blocks={[
{
language: 'bash',
file: 'Terminal',
code: dedent`
npm install --save posthog-js @sentry/browser
`,
},
]}
/>
</>
),
},
{
title: 'Configure the integration',
badge: 'required',
content: (
<>
<Markdown>Add the Sentry integration when initializing PostHog:</Markdown>
<CodeBlock
blocks={[
{
language: 'javascript',
file: 'JavaScript',
code: dedent`
import posthog from 'posthog-js'
import * as Sentry from '@sentry/browser'
// Initialize Sentry first
Sentry.init({
dsn: 'your-sentry-dsn',
})
// Initialize PostHog with Sentry integration
posthog.init('<ph_project_token>', {
api_host: '<ph_client_api_host>',
defaults: '${SDK_DEFAULTS_DATE}'
})
// Set PostHog session ID on Sentry scope
Sentry.getCurrentScope().setTag('posthog_session_id', posthog.get_session_id())
`,
},
]}
/>
<CalloutBox type="fyi" title="Full setup guide">
<Markdown>
This allows you to link Sentry errors to PostHog sessions. See the [Sentry integration
docs](https://posthog.com/docs/libraries/sentry) for the full setup guide.
</Markdown>
</CalloutBox>
</>
),
},
]
}
export const SentryInstallation = createInstallation(getSentrySteps)