unity.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. import {Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Alert} from 'sentry/components/alert';
  4. import ExternalLink from 'sentry/components/links/externalLink';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import {StoreCrashReportsConfig} from 'sentry/components/onboarding/gettingStartedDoc/storeCrashReportsConfig';
  7. import type {
  8. Docs,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {
  12. getCrashReportApiIntroduction,
  13. getCrashReportInstallDescription,
  14. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  15. import exampleSnippets from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsExampleSnippets';
  16. import {metricTagsExplanation} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  17. import {t, tct} from 'sentry/locale';
  18. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  19. const getVerifySnippet = () => `
  20. using Sentry; // On the top of the script
  21. SentrySdk.CaptureMessage("Test event");`;
  22. const getMetricsConfigureSnippet = () => `
  23. public override void Configure(SentryUnityOptions options)
  24. {
  25. options.ExperimentalMetrics = new ExperimentalMetricsOptions
  26. {
  27. EnableCodeLocations = true
  28. };
  29. }`;
  30. const onboarding: OnboardingConfig = {
  31. install: params => [
  32. {
  33. type: StepType.INSTALL,
  34. description: tct(
  35. "Install the package via the [link:Unity Package Manager] using a Git URL to Sentry's SDK repository:",
  36. {
  37. link: (
  38. <ExternalLink href="https://docs.unity3d.com/Manual/upm-ui-giturl.html" />
  39. ),
  40. }
  41. ),
  42. configurations: [
  43. {
  44. language: 'url',
  45. partialLoading: params.sourcePackageRegistries.isLoading,
  46. code: `https://github.com/getsentry/unity.git#${getPackageVersion(
  47. params,
  48. 'sentry.dotnet.unity',
  49. '1.5.0'
  50. )}`,
  51. },
  52. ],
  53. additionalInfo: (
  54. <AlertWithoutMarginBottom type="info">
  55. {tct(
  56. 'The Unity SDK now supports line numbers for IL2CPP. The feature is currently in beta, but you can enable it at [code:Tools -> Sentry -> Advanced -> IL2CPP] line numbers. To learn more check out our [link:docs].',
  57. {
  58. code: <code />,
  59. link: (
  60. <ExternalLink href="https://docs.sentry.io/platforms/unity/configuration/il2cpp/" />
  61. ),
  62. }
  63. )}
  64. </AlertWithoutMarginBottom>
  65. ),
  66. },
  67. ],
  68. configure: params => [
  69. {
  70. type: StepType.CONFIGURE,
  71. description: tct(
  72. "Access the Sentry configuration window by going to Unity's top menu: [code:Tools] > [code:Sentry] and enter the following DSN:",
  73. {code: <code />}
  74. ),
  75. configurations: [
  76. {
  77. language: 'url',
  78. code: params.dsn.public,
  79. },
  80. ],
  81. additionalInfo: (
  82. <Fragment>
  83. <p>{t("And that's it! Now Sentry can capture errors automatically.")}</p>
  84. {tct('If you like additional contexts you could enable [link:Screenshots].', {
  85. link: (
  86. <ExternalLink href="https://docs.sentry.io/platforms/unity/enriching-events/screenshots/" />
  87. ),
  88. })}
  89. </Fragment>
  90. ),
  91. },
  92. ],
  93. verify: params => [
  94. {
  95. type: StepType.VERIFY,
  96. description: t(
  97. 'Once it is configured with the DSN you can call the SDK from anywhere:'
  98. ),
  99. configurations: [
  100. {
  101. language: 'csharp',
  102. code: getVerifySnippet(),
  103. },
  104. ],
  105. },
  106. {
  107. title: t('Troubleshooting'),
  108. description: (
  109. <Fragment>
  110. <p>
  111. {t(
  112. "Confirm the URL doesn't have a trailing whitespace at the end. The Unity Package Manager will fail to find the package if a trailing whitespace is appended."
  113. )}
  114. </p>
  115. {tct(
  116. "If you're running into any kind of issue please check out our [troubleshootingLink:troubleshooting page] or [raiseAnIssueLink:raise an issue].",
  117. {
  118. troubleshootingLink: (
  119. <ExternalLink href="https://docs.sentry.io/platforms/unity/troubleshooting/" />
  120. ),
  121. raiseAnIssueLink: (
  122. <ExternalLink href="https://github.com/getsentry/sentry-unity/issues/new?assignees=&labels=Platform%3A+Unity%2CType%3A+Bug&template=bug.md" />
  123. ),
  124. }
  125. )}
  126. </Fragment>
  127. ),
  128. },
  129. {
  130. title: t('Further Settings'),
  131. description: (
  132. <StoreCrashReportsConfig
  133. organization={params.organization}
  134. projectSlug={params.projectSlug}
  135. />
  136. ),
  137. },
  138. ],
  139. };
  140. export const feedbackOnboarding: OnboardingConfig = {
  141. introduction: () => getCrashReportApiIntroduction(),
  142. install: () => [
  143. {
  144. type: StepType.INSTALL,
  145. description: getCrashReportInstallDescription(),
  146. configurations: [
  147. {
  148. code: [
  149. {
  150. label: 'C#',
  151. value: 'csharp',
  152. language: 'csharp',
  153. code: `var eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.");
  154. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User");`,
  155. },
  156. {
  157. label: 'F#',
  158. value: 'fsharp',
  159. language: 'fsharp',
  160. code: `let eventId = SentrySdk.CaptureMessage("An event that will receive user feedback.")
  161. SentrySdk.CaptureUserFeedback(eventId, "user@example.com", "It broke.", "The User")`,
  162. },
  163. ],
  164. },
  165. ],
  166. },
  167. ],
  168. configure: () => [],
  169. verify: () => [],
  170. nextSteps: () => [],
  171. };
  172. const metricsOnboarding: OnboardingConfig = {
  173. install: () => [
  174. {
  175. type: StepType.INSTALL,
  176. description: tct(
  177. 'You need a minimum version [codeVersion:2.0.0] of the Unity SDK installed.',
  178. {
  179. codeVersion: <code />,
  180. }
  181. ),
  182. },
  183. ],
  184. configure: () => [
  185. {
  186. type: StepType.CONFIGURE,
  187. description: t(
  188. 'Once the SDK is installed or updated, you can enable the experimental metrics feature and code locations being emitted in your RuntimeConfiguration.'
  189. ),
  190. configurations: [
  191. {
  192. language: 'csharp',
  193. code: getMetricsConfigureSnippet(),
  194. },
  195. ],
  196. },
  197. ],
  198. verify: () => [
  199. {
  200. type: StepType.VERIFY,
  201. description: tct(
  202. "Then you'll be able to add metrics as [code:counters], [code:sets], [code:distributions], [code:gauges], and [code:timings].",
  203. {
  204. code: <code />,
  205. }
  206. ),
  207. configurations: [
  208. {
  209. description: metricTagsExplanation,
  210. },
  211. {
  212. description: t('Try out these examples:'),
  213. code: [
  214. {
  215. label: 'Counter',
  216. value: 'counter',
  217. language: 'csharp',
  218. code: exampleSnippets.dotnet.counter,
  219. },
  220. {
  221. label: 'Distribution',
  222. value: 'distribution',
  223. language: 'csharp',
  224. code: exampleSnippets.dotnet.distribution,
  225. },
  226. {
  227. label: 'Set',
  228. value: 'set',
  229. language: 'csharp',
  230. code: exampleSnippets.dotnet.set,
  231. },
  232. {
  233. label: 'Gauge',
  234. value: 'gauge',
  235. language: 'csharp',
  236. code: exampleSnippets.dotnet.gauge,
  237. },
  238. ],
  239. },
  240. {
  241. description: t(
  242. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  243. ),
  244. },
  245. {
  246. description: tct(
  247. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  248. {
  249. docsLink: (
  250. <ExternalLink href="https://docs.sentry.io/platforms/unity/metrics/" />
  251. ),
  252. }
  253. ),
  254. },
  255. ],
  256. },
  257. ],
  258. };
  259. const docs: Docs = {
  260. onboarding,
  261. feedbackOnboardingCrashApi: feedbackOnboarding,
  262. crashReportOnboarding: feedbackOnboarding,
  263. customMetricsOnboarding: metricsOnboarding,
  264. };
  265. export default docs;
  266. const AlertWithoutMarginBottom = styled(Alert)`
  267. margin-bottom: 0;
  268. `;