xamarin.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  4. import type {
  5. Docs,
  6. DocsParams,
  7. OnboardingConfig,
  8. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  9. import {
  10. getCrashReportGenericInstallStep,
  11. getCrashReportModalConfigDescription,
  12. getCrashReportModalIntroduction,
  13. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  14. import {csharpFeedbackOnboarding} from 'sentry/gettingStartedDocs/dotnet/dotnet';
  15. import {t, tct} from 'sentry/locale';
  16. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  17. type Params = DocsParams;
  18. const getInstallSnippetXamarin = (params: Params) => `
  19. Install-Package Sentry.Xamarin -Version ${getPackageVersion(
  20. params,
  21. 'sentry.dotnet.xamarin',
  22. '1.5.2'
  23. )}`;
  24. const getInstallSnippetXamarinForms = (params: Params) => `
  25. Install-Package Sentry.Xamarin.Forms -Version ${getPackageVersion(
  26. params,
  27. 'sentry.dotnet.xamarin-forms',
  28. '1.5.2'
  29. )}`;
  30. const getConfigureSnippetAndroid = (params: Params) => `
  31. public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
  32. {
  33. protected override void OnCreate(Bundle savedInstanceState)
  34. {
  35. SentryXamarin.Init(options =>
  36. {
  37. // Tells which project in Sentry to send events to:
  38. options.Dsn = "${params.dsn}";
  39. // When configuring for the first time, to see what the SDK is doing:
  40. options.Debug = true;
  41. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  42. // We recommend adjusting this value in production.
  43. options.TracesSampleRate = 1.0;
  44. // If you installed Sentry.Xamarin.Forms:
  45. options.AddXamarinFormsIntegration();
  46. });`;
  47. const getConfigureSnippetIOS = (params: Params) => `
  48. public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
  49. {
  50. public override bool FinishedLaunching(UIApplication app, NSDictionary options)
  51. {
  52. SentryXamarin.Init(options =>
  53. {
  54. options.Dsn = "${params.dsn}";
  55. // When configuring for the first time, to see what the SDK is doing:
  56. options.Debug = true;
  57. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  58. // We recommend adjusting this value in production.
  59. options.TracesSampleRate = 1.0;
  60. options.AddXamarinFormsIntegration();
  61. });`;
  62. const getConfigureSnippetUWP = (params: Params) => `
  63. sealed partial class App : Application
  64. {
  65. protected override void OnLaunched(LaunchActivatedEventArgs e)
  66. {
  67. SentryXamarin.Init(options =>
  68. {
  69. options.Dsn = "${params.dsn}";
  70. // When configuring for the first time, to see what the SDK is doing:
  71. options.Debug = true;
  72. // Set TracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  73. // We recommend adjusting this value in production.
  74. options.TracesSampleRate = 1.0;
  75. options.AddXamarinFormsIntegration();
  76. });`;
  77. const getPerformanceInstrumentationSnippet = () => `
  78. // Transaction can be started by providing, at minimum, the name and the operation
  79. var transaction = SentrySdk.StartTransaction(
  80. "test-transaction-name",
  81. "test-transaction-operation"
  82. );
  83. // Transactions can have child spans (and those spans can have child spans as well)
  84. var span = transaction.StartChild("test-child-operation");
  85. // ...
  86. // (Perform the operation represented by the span/transaction)
  87. // ...
  88. span.Finish(); // Mark the span as finished
  89. transaction.Finish(); // Mark the transaction as finished and send it to Sentry`;
  90. const onboarding: OnboardingConfig = {
  91. install: params => [
  92. {
  93. type: StepType.INSTALL,
  94. description: tct('Install the [strong:NuGet] package:', {
  95. strong: <strong />,
  96. }),
  97. configurations: [
  98. {
  99. partialLoading: params.sourcePackageRegistries.isLoading,
  100. code: [
  101. {
  102. language: 'shell',
  103. label: 'Xamarin.Forms',
  104. value: 'xamarinForms',
  105. code: getInstallSnippetXamarinForms(params),
  106. },
  107. {
  108. language: 'shell',
  109. label: 'Xamarin',
  110. value: 'xamarin',
  111. code: getInstallSnippetXamarin(params),
  112. },
  113. ],
  114. },
  115. ],
  116. },
  117. ],
  118. configure: params => [
  119. {
  120. type: StepType.CONFIGURE,
  121. description: tct(
  122. 'Initialize the SDK as early as possible, like in the constructor of the [appCode:App], and Add [sentryXamarinFormsIntegrationCode:SentryXamarinFormsIntegration] as a new Integration to [sentryXamarinOptionsCode:SentryXamarinOptions] if you are going to run your app with Xamarin Forms:',
  123. {
  124. appCode: <code />,
  125. sentryXamarinFormsIntegrationCode: <code />,
  126. sentryXamarinOptionsCode: <code />,
  127. }
  128. ),
  129. configurations: [
  130. {
  131. description: <h5>{t('Android')}</h5>,
  132. configurations: [
  133. {
  134. description: tct('Initialize the SDK on your [code:MainActivity].', {
  135. code: <code />,
  136. }),
  137. language: `csharp`,
  138. code: getConfigureSnippetAndroid(params),
  139. },
  140. ],
  141. },
  142. {
  143. description: <h5>{t('iOS')}</h5>,
  144. configurations: [
  145. {
  146. description: tct('Initialize the SDK on your [code:AppDelegate.cs].', {
  147. code: <code />,
  148. }),
  149. language: `csharp`,
  150. code: getConfigureSnippetIOS(params),
  151. },
  152. ],
  153. },
  154. {
  155. description: <h5>{t('UWP')}</h5>,
  156. configurations: [
  157. {
  158. description: (
  159. <Fragment>
  160. <p>
  161. {tct('Initialize the SDK on [code:App.xaml.cs].', {
  162. code: <code />,
  163. })}
  164. </p>
  165. {t("NOTE: It's recommended to not setup the CacheDirectory for UWP.")}
  166. </Fragment>
  167. ),
  168. language: `csharp`,
  169. code: getConfigureSnippetUWP(params),
  170. },
  171. ],
  172. },
  173. ],
  174. },
  175. ],
  176. verify: () => [
  177. {
  178. type: StepType.VERIFY,
  179. description: t('To verify your set up, you can capture a message with the SDK:'),
  180. configurations: [
  181. {
  182. language: 'csharp',
  183. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  184. },
  185. ],
  186. additionalInfo: t(
  187. 'You might need to open the app again for the crash report to be sent to the server.'
  188. ),
  189. },
  190. {
  191. title: t('Performance Monitoring'),
  192. description: t(
  193. 'You can measure the performance of your code by capturing transactions and spans.'
  194. ),
  195. configurations: [
  196. {
  197. language: 'csharp',
  198. code: getPerformanceInstrumentationSnippet(),
  199. },
  200. ],
  201. additionalInfo: tct(
  202. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  203. {
  204. link: (
  205. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/tracing/instrumentation/" />
  206. ),
  207. }
  208. ),
  209. },
  210. {
  211. title: t('Documentation'),
  212. description: tct(
  213. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete Xamarin Forms docs].",
  214. {
  215. link: (
  216. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/xamarin/" />
  217. ),
  218. }
  219. ),
  220. },
  221. {
  222. title: t('Limitations'),
  223. description: t(
  224. 'There are no line numbers on stack traces for UWP and in release builds for Android and iOS.'
  225. ),
  226. },
  227. {
  228. title: t('Samples'),
  229. description: tct(
  230. 'You can find an example of a Xamarin Forms app with Sentry integrated [link:on this GitHub repository].',
  231. {
  232. link: (
  233. <ExternalLink href="https://github.com/getsentry/sentry-xamarin/tree/main/Samples" />
  234. ),
  235. }
  236. ),
  237. },
  238. ],
  239. };
  240. const crashReportOnboarding: OnboardingConfig = {
  241. introduction: () => getCrashReportModalIntroduction(),
  242. install: (params: Params) => getCrashReportGenericInstallStep(params),
  243. configure: () => [
  244. {
  245. type: StepType.CONFIGURE,
  246. description: getCrashReportModalConfigDescription({
  247. link: 'https://docs.sentry.io/platforms/dotnet/guides/xamarin/user-feedback/configuration/#crash-report-modal',
  248. }),
  249. },
  250. ],
  251. verify: () => [],
  252. nextSteps: () => [],
  253. };
  254. const docs: Docs = {
  255. onboarding,
  256. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  257. crashReportOnboarding,
  258. };
  259. export default docs;