unity.tsx 7.3 KB

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