Skip to content

Commit cda95aa

Browse files
authored
feat: Inline onboarding product options syntax (#13361)
* improve product options syntax * keep support for both product options syntax options +more readable mdx bundler errors * migrate Hono and Apple sdks common onboarding to the new syntax
1 parent dae84d0 commit cda95aa

File tree

5 files changed

+92
-18
lines changed

5 files changed

+92
-18
lines changed

docs/platforms/apple/common/index.mdx

+30-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ To capture all errors, initialize the SDK as soon as possible, such as in your `
8787

8888
<PlatformSection notSupported={["apple.tvos", "apple.watchos", "apple.visionos"]}>
8989

90-
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
90+
```swift {tabTitle:Swift}
9191
import Sentry
9292

9393
func application(_ application: UIApplication,
@@ -101,21 +101,25 @@ func application(_ application: UIApplication,
101101
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
102102
options.sendDefaultPii = true
103103

104+
// ___PRODUCT_OPTION_START___ performance
104105
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
105106
// We recommend adjusting this value in production.
106107
options.tracesSampleRate = 1
108+
// ___PRODUCT_OPTION_END___ performance
107109

110+
// ___PRODUCT_OPTION_START___ profiling
108111
options.configureProfiling = {
109112
$0.lifecycle = .trace
110113
$0.sessionSampleRate = 1
111114
}
115+
// ___PRODUCT_OPTION_END___ profiling
112116
}
113117

114118
return true
115119
}
116120
```
117121

118-
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15", "profiling": "16-20"}}
122+
```objc {tabTitle:Objective-C}
119123
@import Sentry;
120124

121125
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@@ -128,21 +132,25 @@ func application(_ application: UIApplication,
128132
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
129133
options.sendDefaultPii = YES
130134

135+
// ___PRODUCT_OPTION_START___ performance
131136
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
132137
// We recommend adjusting this value in production.
133138
options.tracesSampleRate = @1.f;
139+
// ___PRODUCT_OPTION_END___ performance
134140

141+
// ___PRODUCT_OPTION_START___ profiling
135142
options.configureProfiling = ^(SentryProfileOptions *profiling) {
136143
profiling.lifecycle = SentryProfileLifecycleTrace;
137144
profiling.sessionSampleRate = 1.f;
138145
};
146+
// ___PRODUCT_OPTION_END___ profiling
139147
}];
140148

141149
return YES;
142150
}
143151
```
144152

145-
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
153+
```swift {tabTitle:SwiftUI with App conformer}
146154
import Sentry
147155

148156
@main
@@ -156,14 +164,18 @@ struct SwiftUIApp: App {
156164
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
157165
options.sendDefaultPii = true
158166

167+
// ___PRODUCT_OPTION_START___ performance
159168
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
160169
// We recommend adjusting this value in production.
161170
options.tracesSampleRate = 1
171+
// ___PRODUCT_OPTION_END___ performance
162172

173+
// ___PRODUCT_OPTION_START___ profiling
163174
options.configureProfiling = {
164175
$0.lifecycle = .trace
165176
$0.sessionSampleRate = 1
166177
}
178+
// ___PRODUCT_OPTION_END___ profiling
167179
}
168180
}
169181
}
@@ -172,7 +184,7 @@ struct SwiftUIApp: App {
172184

173185
<PlatformSection notSupported={["apple.ios", "apple.macos"]}>
174186

175-
```swift {tabTitle:Swift} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
187+
```swift {tabTitle:Swift}
176188
import Sentry
177189

178190
func application(_ application: UIApplication,
@@ -186,21 +198,25 @@ func application(_ application: UIApplication,
186198
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
187199
options.sendDefaultPii = true
188200

201+
// ___PRODUCT_OPTION_START___ performance
189202
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
190203
// We recommend adjusting this value in production.
191204
options.tracesSampleRate = 1
205+
// ___PRODUCT_OPTION_END___ performance
192206

207+
// ___PRODUCT_OPTION_START___ profiling
193208
options.configureProfiling = {
194209
$0.lifecycle = .trace
195210
$0.sessionSampleRate = 1
196211
}
212+
// ___PRODUCT_OPTION_END___ profiling
197213
}
198214

199215
return true
200216
}
201217
```
202218

203-
```objc {tabTitle:Objective-C} {"onboardingOptions": {"performance": "12-15", "profiling": "16-20"}}
219+
```objc {tabTitle:Objective-C}
204220
@import Sentry;
205221

206222
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@@ -213,21 +229,25 @@ func application(_ application: UIApplication,
213229
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
214230
options.sendDefaultPii = YES
215231

232+
// ___PRODUCT_OPTION_START___ performance
216233
// Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
217234
// We recommend adjusting this value in production.
218235
options.tracesSampleRate = @1.f;
236+
// ___PRODUCT_OPTION_END___ performance
219237

238+
// ___PRODUCT_OPTION_START___ profiling
220239
options.configureProfiling = ^(SentryProfileOptions *profiling) {
221240
profiling.lifecycle = SentryProfileLifecycleTrace;
222241
profiling.sessionSampleRate = 1.f;
223242
};
243+
// ___PRODUCT_OPTION_END___ profiling
224244
}];
225245

226246
return YES;
227247
}
228248
```
229249

230-
```swift {tabTitle:SwiftUI with App conformer} {"onboardingOptions": {"performance": "13-16", "profiling": "17-21"}}
250+
```swift {tabTitle:SwiftUI with App conformer}
231251
import Sentry
232252

233253
@main
@@ -241,14 +261,18 @@ struct SwiftUIApp: App {
241261
// For more information, visit: https://docs.sentry.io/platforms/apple/data-management/data-collected/
242262
options.sendDefaultPii = true
243263

264+
// ___PRODUCT_OPTION_START___ performance
244265
// Set tracesSampleRate to 1 to capture 100% of transactions for performance monitoring.
245266
// We recommend adjusting this value in production.
246267
options.tracesSampleRate = 1
268+
// ___PRODUCT_OPTION_END___ performance
247269

270+
// ___PRODUCT_OPTION_START___ profiling
248271
options.configureProfiling = {
249272
$0.lifecycle = .trace
250273
$0.sessionSampleRate = 1
251274
}
275+
// ___PRODUCT_OPTION_END___ profiling
252276
}
253277
}
254278
}

docs/platforms/javascript/guides/hono/index.mdx

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ compatibility_flags = ["nodejs_als"]
6262
Next, wrap your handler with the `withSentry` function. This will initialize the SDK and hook into the
6363
environment. Note that you can turn off almost all side effects using the respective options.
6464

65-
```typescript {filename:index.ts} {"onboardingOptions": {"performance": "14-18"}}
65+
```typescript {filename:index.ts}
6666
import { Hono } from "hono";
6767
import * as Sentry from "@sentry/cloudflare";
6868

@@ -76,11 +76,13 @@ app.get("/", () => {
7676
export default Sentry.withSentry(
7777
(env) => ({
7878
dsn: "___PUBLIC_DSN___",
79+
// ___PRODUCT_OPTION_START___ performance
7980

8081
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
8182
// Learn more at
8283
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
8384
tracesSampleRate: 1.0,
85+
// ___PRODUCT_OPTION_END___ performance
8486
}),
8587
app
8688
);
@@ -123,18 +125,20 @@ Next, add the `sentryPagesPlugin` as
123125
We recommend adding a `functions/_middleware.js` for the middleware setup so that Sentry is initialized for your entire
124126
app.
125127

126-
```javascript {filename:functions/_middleware.js} {"onboardingOptions": {"performance": "7-11"}}
128+
```javascript {filename:functions/_middleware.js}
127129
import * as Sentry from "@sentry/cloudflare";
128130

129131
export const onRequest = [
130132
// Make sure Sentry is the first middleware
131133
Sentry.sentryPagesPlugin((context) => ({
132134
dsn: "___PUBLIC_DSN___",
135+
// ___PRODUCT_OPTION_START___ performance
133136

134137
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
135138
// Learn more at
136139
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
137140
tracesSampleRate: 1.0,
141+
// ___PRODUCT_OPTION_END___ performance
138142
})),
139143
// Add more middlewares here
140144
];

src/components/docPage/type.scss

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@
203203
[data-onboarding-option].hidden {
204204
display: none;
205205
}
206+
// force hide markers (___PRODUCT_OPTION_START___ and ___PRODUCT_OPTION_END___)
207+
[data-onboarding-option-hidden] {
208+
display: none;
209+
}
206210
[data-onboarding-option].animate-line {
207211
animation:
208212
slideLeft 0.2s ease-out forwards,

src/mdx.ts

+4
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ export async function getFileBySlug(slug: string) {
456456

457457
return options;
458458
},
459+
}).catch(e => {
460+
// eslint-disable-next-line no-console
461+
console.error('Error occurred during MDX compilation:', e.errors);
462+
throw e;
459463
});
460464

461465
const {code, frontmatter} = result;

src/rehype-onboarding-lines.js

+48-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @typedef {import('hast').Element} Element
33
* @typedef {import('hast').Root} Root
44
*/
5-
5+
import {toString} from 'hast-util-to-string';
66
import rangeParser from 'parse-numeric-range';
77
import {visit} from 'unist-util-visit';
88

@@ -25,6 +25,52 @@ export default function rehypeOnboardingLines() {
2525
visit(tree, {type: 'element', tagName: 'code'}, visitor);
2626
};
2727
}
28+
29+
/**
30+
* @param {Element} node
31+
*/
32+
function visitor(node) {
33+
// ignore no code-highlight <code> tags as in in inline code resulting from a `markdown`
34+
if (!node.properties.className?.includes('code-highlight')) {
35+
return;
36+
}
37+
38+
const meta = /** @type {string} */ (
39+
node?.data?.meta || node?.properties?.metastring || ''
40+
);
41+
42+
if (meta.includes('onboardingOptions')) {
43+
handle_metadata_options(node, meta);
44+
return;
45+
}
46+
handle_inline_options(node);
47+
}
48+
49+
function handle_inline_options(node) {
50+
/* @type {string | undefined} */
51+
let currentOption;
52+
53+
// product options syntax
54+
// ___PRODUCT_OPTION_START___ performance
55+
// some lines here
56+
// ___PRODUCT_OPTION_END___ performance
57+
const PRODUCT_OPTION_START = '___PRODUCT_OPTION_START___';
58+
const PRODUCT_OPTION_END = '___PRODUCT_OPTION_END___';
59+
node.children?.forEach(line => {
60+
const lineStr = toString(line);
61+
if (lineStr.includes(PRODUCT_OPTION_START)) {
62+
currentOption = lineStr.split(PRODUCT_OPTION_START)[1].trim();
63+
line.properties['data-onboarding-option-hidden'] = '1';
64+
} else if (lineStr.includes(PRODUCT_OPTION_END)) {
65+
line.properties['data-onboarding-option-hidden'] = '1';
66+
currentOption = undefined;
67+
}
68+
if (currentOption) {
69+
line.properties['data-onboarding-option'] = currentOption;
70+
}
71+
});
72+
}
73+
2874
/**
2975
* Parse the line numbers from the metastring
3076
* @param {string} meta
@@ -85,15 +131,7 @@ const getOptionForLine = meta => {
85131
/**
86132
* @param {Element} node
87133
*/
88-
function visitor(node) {
89-
const meta = /** @type {string} */ (
90-
node?.data?.meta || node?.properties?.metastring || ''
91-
);
92-
93-
if (!meta.includes('onboardingOptions')) {
94-
return;
95-
}
96-
134+
function handle_metadata_options(node, meta) {
97135
const optionForLine = getOptionForLine(meta);
98136

99137
node.children.forEach((line, index) => {

0 commit comments

Comments
 (0)