|
| 1 | +import {ExternalLink} from 'sentry/components/core/link'; |
| 2 | +import { |
| 3 | + StepType, |
| 4 | + type DocsParams, |
| 5 | + type OnboardingConfig, |
| 6 | +} from 'sentry/components/onboarding/gettingStartedDoc/types'; |
| 7 | +import {verify} from 'sentry/gettingStartedDocs/python/python/logs'; |
| 8 | +import {alternativeProfiling} from 'sentry/gettingStartedDocs/python/python/profiling'; |
| 9 | +import { |
| 10 | + getPythonAiocontextvarsCodeBlocks, |
| 11 | + getPythonInstallCodeBlock, |
| 12 | +} from 'sentry/gettingStartedDocs/python/python/utils'; |
| 13 | +import {t, tct} from 'sentry/locale'; |
| 14 | + |
| 15 | +const getSdkSetupSnippet = (params: DocsParams) => ` |
| 16 | +import sentry_sdk |
| 17 | +
|
| 18 | +sentry_sdk.init( |
| 19 | + dsn="${params.dsn.public}", |
| 20 | + # Add data like request headers and IP for users, |
| 21 | + # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info |
| 22 | + send_default_pii=True,${ |
| 23 | + params.isLogsSelected |
| 24 | + ? ` |
| 25 | + # Enable sending logs to Sentry |
| 26 | + enable_logs=True,` |
| 27 | + : '' |
| 28 | + }${ |
| 29 | + params.isPerformanceSelected |
| 30 | + ? ` |
| 31 | + # Set traces_sample_rate to 1.0 to capture 100% |
| 32 | + # of transactions for tracing. |
| 33 | + traces_sample_rate=1.0,` |
| 34 | + : '' |
| 35 | + }${ |
| 36 | + params.isProfilingSelected && |
| 37 | + params.profilingOptions?.defaultProfilingMode !== 'continuous' |
| 38 | + ? ` |
| 39 | + # Set profiles_sample_rate to 1.0 to profile 100% |
| 40 | + # of sampled transactions. |
| 41 | + # We recommend adjusting this value in production. |
| 42 | + profiles_sample_rate=1.0,` |
| 43 | + : params.isProfilingSelected && |
| 44 | + params.profilingOptions?.defaultProfilingMode === 'continuous' |
| 45 | + ? ` |
| 46 | + # Set profile_session_sample_rate to 1.0 to profile 100% |
| 47 | + # of profile sessions. |
| 48 | + profile_session_sample_rate=1.0, |
| 49 | + # Set profile_lifecycle to "trace" to automatically |
| 50 | + # run the profiler on when there is an active transaction |
| 51 | + profile_lifecycle="trace",` |
| 52 | + : '' |
| 53 | + } |
| 54 | +) |
| 55 | +`; |
| 56 | + |
| 57 | +export const onboarding: OnboardingConfig = { |
| 58 | + introduction: () => |
| 59 | + tct('The Tornado integration adds support for the [link:Tornado Web Framework].', { |
| 60 | + link: <ExternalLink href="https://www.tornadoweb.org/en/stable/" />, |
| 61 | + }), |
| 62 | + install: () => [ |
| 63 | + { |
| 64 | + type: StepType.INSTALL, |
| 65 | + content: [ |
| 66 | + { |
| 67 | + type: 'text', |
| 68 | + text: tct( |
| 69 | + 'Install [code:sentry-sdk] from PyPI with the [code:tornado] extra:', |
| 70 | + { |
| 71 | + code: <code />, |
| 72 | + } |
| 73 | + ), |
| 74 | + }, |
| 75 | + getPythonInstallCodeBlock(), |
| 76 | + ...getPythonAiocontextvarsCodeBlocks(), |
| 77 | + ], |
| 78 | + }, |
| 79 | + ], |
| 80 | + configure: (params: DocsParams) => [ |
| 81 | + { |
| 82 | + type: StepType.CONFIGURE, |
| 83 | + content: [ |
| 84 | + { |
| 85 | + type: 'text', |
| 86 | + text: tct( |
| 87 | + 'If you have the [codeTornado:tornado] package in your dependencies, the Tornado integration will be enabled automatically when you initialize the Sentry SDK. Initialize the Sentry SDK before your app has been initialized:', |
| 88 | + { |
| 89 | + codeTornado: <code />, |
| 90 | + } |
| 91 | + ), |
| 92 | + }, |
| 93 | + { |
| 94 | + type: 'code', |
| 95 | + language: 'python', |
| 96 | + code: ` |
| 97 | +${getSdkSetupSnippet(params)} |
| 98 | +class MainHandler(tornado.web.RequestHandler): |
| 99 | + # ... |
| 100 | +`, |
| 101 | + }, |
| 102 | + alternativeProfiling(params), |
| 103 | + ], |
| 104 | + }, |
| 105 | + ], |
| 106 | + verify: (params: DocsParams) => [ |
| 107 | + { |
| 108 | + type: StepType.VERIFY, |
| 109 | + content: [ |
| 110 | + { |
| 111 | + type: 'text', |
| 112 | + text: t( |
| 113 | + 'You can easily verify your Sentry installation by creating a route that triggers an error:' |
| 114 | + ), |
| 115 | + }, |
| 116 | + { |
| 117 | + type: 'code', |
| 118 | + language: 'python', |
| 119 | + code: ` |
| 120 | +import asyncio |
| 121 | +import tornado |
| 122 | +${getSdkSetupSnippet(params)} |
| 123 | +class MainHandler(tornado.web.RequestHandler): |
| 124 | + def get(self): |
| 125 | + 1/0 # raises an error |
| 126 | + self.write("Hello, world") |
| 127 | +
|
| 128 | +def make_app(): |
| 129 | + return tornado.web.Application([ |
| 130 | + (r"/", MainHandler), |
| 131 | + ]) |
| 132 | +
|
| 133 | +async def main(): |
| 134 | + app = make_app() |
| 135 | + app.listen(8888) |
| 136 | + await asyncio.Event().wait() |
| 137 | +
|
| 138 | +asyncio.run(main()) |
| 139 | +`, |
| 140 | + }, |
| 141 | + verify(params), |
| 142 | + { |
| 143 | + type: 'text', |
| 144 | + text: [ |
| 145 | + tct( |
| 146 | + 'When you point your browser to [link:http://localhost:8888/] a transaction in the Performance section of Sentry will be created.', |
| 147 | + { |
| 148 | + link: <ExternalLink href="http://localhost:8888/" />, |
| 149 | + } |
| 150 | + ), |
| 151 | + t( |
| 152 | + 'Additionally, an error event will be sent to Sentry and will be connected to the transaction.' |
| 153 | + ), |
| 154 | + t('It takes a couple of moments for the data to appear in Sentry.'), |
| 155 | + ], |
| 156 | + }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + ], |
| 160 | + nextSteps: (params: DocsParams) => { |
| 161 | + const steps = [] as any[]; |
| 162 | + if (params.isLogsSelected) { |
| 163 | + steps.push({ |
| 164 | + id: 'logs', |
| 165 | + name: t('Logging Integrations'), |
| 166 | + description: t( |
| 167 | + 'Add logging integrations to automatically capture logs from your application.' |
| 168 | + ), |
| 169 | + link: 'https://docs.sentry.io/platforms/python/logs/#integrations', |
| 170 | + }); |
| 171 | + } |
| 172 | + return steps; |
| 173 | + }, |
| 174 | +}; |
| 175 | + |
0 commit comments