xamarin.tsx 7.9 KB

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