xamarin.tsx 8.2 KB

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