xamarin.tsx 8.0 KB

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