xamarin.tsx 7.4 KB

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