Skip to content

Commit 7e1e805

Browse files
committed
Merge branch 'develop' into manual-develop-sync
2 parents b361dff + 6fb1ee1 commit 7e1e805

File tree

112 files changed

+16577
-8636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+16577
-8636
lines changed

.cursor/rules/adding-a-new-ai-integration.mdc

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ Multi-runtime considerations:
2525
- Edge (Cloudflare/Vercel): No OTel, processors only or manual wrapping
2626
```
2727

28+
**IMPORTANT - Runtime-Specific Placement:**
29+
30+
If an AI SDK only works in a specific runtime, the integration code should live exclusively in that runtime's package. Do NOT add it to `packages/core/` or attempt to make it work in other runtimes where it cannot function.
31+
32+
**Runtime-specific integration structures:**
33+
34+
**Node.js-only SDKs** → `packages/node/`
35+
36+
- Core logic: `packages/node/src/integrations/tracing/{provider}/index.ts`
37+
- OTel instrumentation: `packages/node/src/integrations/tracing/{provider}/instrumentation.ts`
38+
- Use when SDK only work with Node.js-specific APIs
39+
40+
**Cloudflare Workers-only SDKs** → `packages/cloudflare/`
41+
42+
- Single file: `packages/cloudflare/src/integrations/tracing/{provider}.ts`
43+
- Use when SDK only works with Cloudflare Workers APIs or Cloudflare AI
44+
45+
**Browser-only SDKs** → `packages/browser/`
46+
47+
- Core logic: `packages/browser/src/integrations/tracing/{provider}/index.ts`
48+
- Use when SDK requires browser-specific APIs (DOM, WebAPIs, etc.)
49+
50+
**For all runtime-specific SDKs:** DO NOT create `packages/core/src/tracing/{provider}/` - keep everything in the runtime package.
51+
52+
**Multi-runtime SDKs:** If the SDK works across multiple runtimes (Node.js, browser, edge), follow the standard pattern with shared core logic in `packages/core/` and runtime-specific wrappers/instrumentation in each package where needed.
53+
2854
---
2955

3056
## Span Hierarchy
@@ -139,6 +165,10 @@ OpenTelemetry Semantic Convention attribute names. **Always use these constants!
139165
- `GEN_AI_USAGE_INPUT_TOKENS_ATTRIBUTE` - Token counts
140166
- `GEN_AI_OPERATION_NAME_ATTRIBUTE` - 'chat', 'embeddings', etc.
141167

168+
**CRITICAL - Attribute Usage:**
169+
170+
Only use attributes explicitly listed in the [Sentry Gen AI Conventions](https://getsentry.github.io/sentry-conventions/attributes/gen_ai/). Do NOT create custom attributes or use undocumented ones. If you need a new attribute, it MUST be documented in the conventions first before implementation.
171+
142172
### `utils.ts`
143173

144174
- `setTokenUsageAttributes()` - Set token usage on span
@@ -213,6 +243,8 @@ OpenTelemetry Semantic Convention attribute names. **Always use these constants!
213243

214244
## Auto-Instrumentation (Out-of-the-Box Support)
215245

246+
**MANDATORY**
247+
216248
**RULE:** AI SDKs should be auto-enabled in Node.js runtime if possible.
217249

218250
✅ **Auto-enable if:**
@@ -269,12 +301,26 @@ export type { {Provider}Options } from './integrations/tracing/{provider}';
269301
export { {provider}Integration } from './integrations/tracing/{provider}';
270302
```
271303

272-
**4. Add E2E test** in `packages/node-integration-tests/suites/{provider}/`
304+
**4. Add E2E tests**
305+
306+
For Node.js integrations, add tests in `dev-packages/node-integration-tests/suites/tracing/{provider}/`:
273307

274308
- Verify spans created automatically (no manual setup)
275309
- Test `recordInputs` and `recordOutputs` options
276310
- Test integration can be disabled
277311

312+
For Cloudflare Workers integrations, add tests in `dev-packages/cloudflare-integration-tests/suites/tracing/{provider}`:
313+
314+
- Create a new worker test app with the AI SDK
315+
- Verify manual instrumentation creates spans correctly
316+
- Test in actual Cloudflare Workers runtime (use `wrangler dev` or `miniflare`)
317+
318+
For Browser integrations, add tests in `dev-packages/browser-integration-tests/suites/tracing/ai-providers/{provider}/`:
319+
320+
- Create a new test suite with Playwright
321+
- Verify manual instrumentation creates spans correctly in the browser
322+
- Test with actual browser runtime
323+
278324
---
279325

280326
## Directory Structure
@@ -307,15 +353,17 @@ packages/
307353

308354
## Key Best Practices
309355

310-
1. **Respect `sendDefaultPii`** for recordInputs/recordOutputs
311-
2. **Use semantic attributes** from `gen-ai-attributes.ts` (never hardcode)
312-
3. **Set Sentry origin**: `SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.openai'` (use provider name: `openai`, `anthropic`, `vercelai`, etc. - only alphanumerics, `_`, and `.` allowed)
313-
4. **Truncate large data**: Use helper functions from `utils.ts`
314-
5. **Correct span operations**: `gen_ai.invoke_agent` for parent, `gen_ai.chat` for children
315-
6. **Streaming**: Use `startSpanManual()`, accumulate state, call `span.end()`
316-
7. **Token accumulation**: Direct on child spans, accumulate on parent from children
317-
8. **Performance**: Use `callWhenPatched()` for Pattern 1
318-
9. **LangChain**: Check `_INTERNAL_shouldSkipAiProviderWrapping()` in Pattern 2
356+
1. **Auto-instrumentation is mandatory** - All integrations MUST auto-detect and instrument automatically in Node.js runtime
357+
2. **Runtime-specific placement** - If SDK only works in one runtime, code lives only in that package
358+
3. **Respect `sendDefaultPii`** for recordInputs/recordOutputs
359+
4. **Use semantic attributes** from `gen-ai-attributes.ts` (never hardcode) - Only use attributes from [Sentry Gen AI Conventions](https://getsentry.github.io/sentry-conventions/attributes/gen_ai/)
360+
5. **Set Sentry origin**: `SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'auto.ai.openai'` (use provider name: `openai`, `anthropic`, `vercelai`, etc. - only alphanumerics, `_`, and `.` allowed)
361+
6. **Truncate large data**: Use helper functions from `utils.ts`
362+
7. **Correct span operations**: `gen_ai.invoke_agent` for parent, `gen_ai.chat` for children
363+
8. **Streaming**: Use `startSpanManual()`, accumulate state, call `span.end()`
364+
9. **Token accumulation**: Direct on child spans, accumulate on parent from children
365+
10. **Performance**: Use `callWhenPatched()` for Pattern 1
366+
11. **LangChain**: Check `_INTERNAL_shouldSkipAiProviderWrapping()` in Pattern 2
319367

320368
---
321369

@@ -329,16 +377,20 @@ packages/
329377

330378
## Auto-Instrumentation Checklist
331379

332-
- [ ] Added to `getAutoPerformanceIntegrations()` in correct order
333-
- [ ] Added to `getOpenTelemetryInstrumentationToPreload()`
334-
- [ ] Exported from `packages/node/src/index.ts`
335-
- [ ] **If browser-compatible:** Exported from `packages/browser/src/index.ts`
336-
- [ ] Added E2E test in `packages/node-integration-tests/suites/{provider}/`
337-
- [ ] E2E test verifies auto-instrumentation
380+
- [ ] If runtime-specific, placed code only in that runtime's package
381+
- [ ] Added to `getAutoPerformanceIntegrations()` in correct order (Node.js)
382+
- [ ] Added to `getOpenTelemetryInstrumentationToPreload()` (Node.js with OTel)
383+
- [ ] Exported from appropriate package index (`packages/node/src/index.ts`, `packages/cloudflare/src/index.ts`, etc.)
384+
- [ ] Added E2E tests:
385+
- [ ] Node.js: `dev-packages/node-integration-tests/suites/tracing/{provider}/`
386+
- [ ] Cloudflare: `dev-packages/cloudflare-integration-tests/suites/tracing/{provider}/`
387+
- [ ] Browser: `dev-packages/browser-integration-tests/suites/tracing/ai-providers/{provider}/`
388+
- [ ] E2E test verifies auto-instrumentation (no manual setup required)
389+
- [ ] Only used attributes from [Sentry Gen AI Conventions](https://getsentry.github.io/sentry-conventions/attributes/gen_ai/)
338390
- [ ] JSDoc says "enabled by default" or "not enabled by default"
339391
- [ ] Documented how to disable (if auto-enabled)
340392
- [ ] Documented limitations clearly
341-
- [ ] Verified OTel only patches when package imported
393+
- [ ] Verified OTel only patches when package imported (Node.js)
342394

343395
---
344396

.cursor/rules/sdk_development.mdc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ You are working on the Sentry JavaScript SDK, a critical production SDK used by
3434

3535
- `yarn lint` - Run ESLint and Prettier checks
3636
- `yarn fix` - Auto-fix linting and formatting issues
37+
- `yarn format:check` - Check file formatting only
38+
- `yarn format` - Auto-fix formatting issues
3739
- `yarn lint:es-compatibility` - Check ES compatibility
3840

3941
## Git Flow Branching Strategy

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ trim_trailing_whitespace = true
88
insert_final_newline = true
99

1010
[*.md]
11-
trim_trailing_whitespace = false
11+
trim_trailing_whitespace = false

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ jobs:
339339
id: install_dependencies
340340

341341
- name: Check file formatting
342-
run: yarn lint:prettier
342+
run: yarn format:check
343343

344344
job_circular_dep_check:
345345
name: Circular Dependency Check
@@ -987,7 +987,7 @@ jobs:
987987
with:
988988
node-version-file: 'dev-packages/e2e-tests/test-applications/${{ matrix.test-application }}/package.json'
989989
- name: Set up Bun
990-
if: matrix.test-application == 'node-exports-test-app'
990+
if: contains(fromJSON('["node-exports-test-app","nextjs-16-bun"]'), matrix.test-application)
991991
uses: oven-sh/setup-bun@v2
992992
- name: Set up AWS SAM
993993
if: matrix.test-application == 'aws-serverless'

.oxfmtrc.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"arrowParens": "avoid",
4+
"printWidth": 120,
5+
"proseWrap": "always",
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"experimentalSortPackageJson": false,
9+
"ignorePatterns": [
10+
"packages/browser/test/loader.js",
11+
"packages/replay-worker/examples/worker.min.js",
12+
"dev-packages/browser-integration-tests/fixtures",
13+
"**/test.ts-snapshots/**",
14+
"/.nx/cache",
15+
"/.nx/workspace-data",
16+
"dev-packages/**/*.html",
17+
"dev-packages/**/*.hbs",
18+
"packages/ember/**/*.hbs",
19+
"packages/ember/**/*.html"
20+
],
21+
"overrides": [
22+
{
23+
"files": ["*.md", "*.mdc"],
24+
"options": {
25+
"proseWrap": "preserve"
26+
}
27+
}
28+
]
29+
}

.prettierignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// See http://go.microsoft.com/fwlink/?LinkId=827846
33
// for the documentation about the extensions.json format
44
"recommendations": [
5-
"esbenp.prettier-vscode",
5+
"oxc.oxc-vscode",
66
"dbaeumer.vscode-eslint",
77
"augustocdias.tasks-shell-input",
88
"denoland.vscode-deno"

.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
},
1212
"typescript.tsdk": "./node_modules/typescript/lib",
1313
"[markdown]": {
14-
"editor.defaultFormatter": "esbenp.prettier-vscode"
14+
"editor.defaultFormatter": "oxc.oxc-vscode"
1515
},
1616
"[css]": {
17-
"editor.defaultFormatter": "esbenp.prettier-vscode"
17+
"editor.defaultFormatter": "oxc.oxc-vscode"
1818
},
1919
"yaml.schemas": {
2020
"https://json.schemastore.org/github-workflow.json": ".github/workflows/**.yml"
@@ -25,8 +25,8 @@
2525
}
2626
],
2727
"deno.enablePaths": ["packages/deno/test"],
28-
"editor.defaultFormatter": "esbenp.prettier-vscode",
28+
"editor.defaultFormatter": "oxc.oxc-vscode",
2929
"[typescript]": {
30-
"editor.defaultFormatter": "esbenp.prettier-vscode"
30+
"editor.defaultFormatter": "oxc.oxc-vscode"
3131
}
3232
}

CLAUDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ You are working on the Sentry JavaScript SDK, a critical production SDK used by
3131

3232
### Linting and Formatting
3333

34-
- `yarn lint` - Run ESLint and Prettier checks
34+
- `yarn lint` - Run ESLint and Oxfmt checks
3535
- `yarn fix` - Auto-fix linting and formatting issues
36+
- `yarn format:check` - Check file formatting only
37+
- `yarn format` - Auto-fix formatting issues
3638
- `yarn lint:es-compatibility` - Check ES compatibility
3739

3840
## Git Flow Branching Strategy

dev-packages/bundler-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": "vitest run"
1313
},
1414
"dependencies": {
15-
"@rollup/plugin-node-resolve": "^15.2.3",
15+
"@rollup/plugin-node-resolve": "^16.0.3",
1616
"@sentry/browser": "10.39.0",
1717
"rollup": "^4.0.0",
1818
"vite": "^5.0.0",

0 commit comments

Comments
 (0)