xamarin.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.public}";
  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 tracing.
  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.public}";
  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 tracing.
  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.public}";
  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 tracing.
  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 [code:App], and Add [code:SentryXamarinFormsIntegration] as a new Integration to [code:SentryXamarinOptions] if you are going to run your app with Xamarin Forms:',
  123. {
  124. code: <code />,
  125. }
  126. ),
  127. configurations: [
  128. {
  129. description: <h5>{t('Android')}</h5>,
  130. configurations: [
  131. {
  132. description: tct('Initialize the SDK on your [code:MainActivity].', {
  133. code: <code />,
  134. }),
  135. language: `csharp`,
  136. code: getConfigureSnippetAndroid(params),
  137. },
  138. ],
  139. },
  140. {
  141. description: <h5>{t('iOS')}</h5>,
  142. configurations: [
  143. {
  144. description: tct('Initialize the SDK on your [code:AppDelegate.cs].', {
  145. code: <code />,
  146. }),
  147. language: `csharp`,
  148. code: getConfigureSnippetIOS(params),
  149. },
  150. ],
  151. },
  152. {
  153. description: <h5>{t('UWP')}</h5>,
  154. configurations: [
  155. {
  156. description: (
  157. <Fragment>
  158. <p>
  159. {tct('Initialize the SDK on [code:App.xaml.cs].', {
  160. code: <code />,
  161. })}
  162. </p>
  163. {t("NOTE: It's recommended to not setup the CacheDirectory for UWP.")}
  164. </Fragment>
  165. ),
  166. language: `csharp`,
  167. code: getConfigureSnippetUWP(params),
  168. },
  169. ],
  170. },
  171. ],
  172. },
  173. ],
  174. verify: () => [
  175. {
  176. type: StepType.VERIFY,
  177. description: t('To verify your set up, you can capture a message with the SDK:'),
  178. configurations: [
  179. {
  180. language: 'csharp',
  181. code: 'SentrySdk.CaptureMessage("Hello Sentry");',
  182. },
  183. ],
  184. additionalInfo: t(
  185. 'You might need to open the app again for the crash report to be sent to the server.'
  186. ),
  187. },
  188. {
  189. title: t('Tracing'),
  190. description: t(
  191. 'You can measure the performance of your code by capturing transactions and spans.'
  192. ),
  193. configurations: [
  194. {
  195. language: 'csharp',
  196. code: getPerformanceInstrumentationSnippet(),
  197. },
  198. ],
  199. additionalInfo: tct(
  200. 'Check out [link:the documentation] to learn more about the API and automatic instrumentations.',
  201. {
  202. link: (
  203. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/tracing/instrumentation/" />
  204. ),
  205. }
  206. ),
  207. },
  208. {
  209. title: t('Documentation'),
  210. description: tct(
  211. "Once you've verified the package is initialized properly and sent a test event, consider visiting our [link:complete Xamarin Forms docs].",
  212. {
  213. link: (
  214. <ExternalLink href="https://docs.sentry.io/platforms/dotnet/guides/xamarin/" />
  215. ),
  216. }
  217. ),
  218. },
  219. {
  220. title: t('Limitations'),
  221. description: t(
  222. 'There are no line numbers on stack traces for UWP and in release builds for Android and iOS.'
  223. ),
  224. },
  225. {
  226. title: t('Samples'),
  227. description: tct(
  228. 'You can find an example of a Xamarin Forms app with Sentry integrated [link:on this GitHub repository].',
  229. {
  230. link: (
  231. <ExternalLink href="https://github.com/getsentry/sentry-xamarin/tree/main/Samples" />
  232. ),
  233. }
  234. ),
  235. },
  236. ],
  237. };
  238. const crashReportOnboarding: OnboardingConfig = {
  239. introduction: () => getCrashReportModalIntroduction(),
  240. install: (params: Params) => getCrashReportGenericInstallStep(params),
  241. configure: () => [
  242. {
  243. type: StepType.CONFIGURE,
  244. description: getCrashReportModalConfigDescription({
  245. link: 'https://docs.sentry.io/platforms/dotnet/guides/xamarin/user-feedback/configuration/#crash-report-modal',
  246. }),
  247. },
  248. ],
  249. verify: () => [],
  250. nextSteps: () => [],
  251. };
  252. const docs: Docs = {
  253. onboarding,
  254. feedbackOnboardingCrashApi: csharpFeedbackOnboarding,
  255. crashReportOnboarding,
  256. };
  257. export default docs;