-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add Bun SDK #9029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Bun SDK #9029
Changes from 4 commits
b604bd0
780674b
76fe549
0b1c553
4dcdcdd
9897a99
26fac75
5105f2b
461e43a
16aaeb1
58f896d
6403465
c5e5af3
0a5c38e
ca01f18
5459964
3a660d4
6913894
65fa8c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
}, | ||
extends: ['../../.eslintrc.js'], | ||
rules: { | ||
'@sentry-internal/sdk/no-optional-chaining': 'off', | ||
'@sentry-internal/sdk/no-nullish-coalescing': 'off', | ||
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off', | ||
'@sentry-internal/sdk/no-class-field-initializers': 'off', | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<p align="center"> | ||
<a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank"> | ||
<img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84"> | ||
</a> | ||
</p> | ||
|
||
# Official Sentry SDK for Bun | ||
|
||
[](https://www.npmjs.com/package/@sentry/bun) | ||
[](https://www.npmjs.com/package/@sentry/bun) | ||
[](https://www.npmjs.com/package/@sentry/bun) | ||
|
||
## Links | ||
|
||
- [Official SDK Docs](https://docs.sentry.io/quickstart/) | ||
- [TypeDoc](http://getsentry.github.io/sentry-javascript/) | ||
|
||
## Usage | ||
|
||
To use this SDK, call `init(options)` as early as possible in the main entry module. This will initialize the SDK and | ||
hook into the environment. Note that you can turn off almost all side effects using the respective options. | ||
AbhiPrasad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
// ES5 Syntax | ||
const Sentry = require('@sentry/bun'); | ||
// ES6 Syntax | ||
import * as Sentry from '@sentry/bun'; | ||
|
||
Sentry.init({ | ||
dsn: '__DSN__', | ||
// ... | ||
}); | ||
``` | ||
|
||
To set context information or send manual events, use the exported functions of `@sentry/bun`. Note that these | ||
functions will not perform any action before you have called `init()`: | ||
|
||
```javascript | ||
// Set user information, as well as tags and further extras | ||
Sentry.configureScope(scope => { | ||
scope.setExtra('battery', 0.7); | ||
scope.setTag('user_mode', 'admin'); | ||
scope.setUser({ id: '4711' }); | ||
// scope.clear(); | ||
}); | ||
|
||
// Add a breadcrumb for future events | ||
Sentry.addBreadcrumb({ | ||
message: 'My Breadcrumb', | ||
// ... | ||
}); | ||
|
||
// Capture exceptions, messages or manual events | ||
Sentry.captureMessage('Hello, world!'); | ||
Sentry.captureException(new Error('Good bye')); | ||
Sentry.captureEvent({ | ||
message: 'Manual', | ||
stacktrace: [ | ||
// ... | ||
], | ||
}); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../jest/jest.config.js'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"name": "@sentry/bun", | ||
"version": "7.69.0", | ||
"description": "Official Sentry SDK for bun", | ||
"repository": "git://github.com/getsentry/sentry-javascript.git", | ||
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/bun", | ||
"author": "Sentry", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"main": "build/cjs/index.js", | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"module": "build/esm/index.js", | ||
"types": "build/types/index.d.ts", | ||
"typesVersions": { | ||
"<4.9": { | ||
"build/npm/types/index.d.ts": [ | ||
"build/npm/types-ts3.8/index.d.ts" | ||
] | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine (no action required) but just to note: With this PR we will not yet publish the Bun SDK because it's not configured in |
||
"dependencies": { | ||
"@sentry/core": "7.69.0", | ||
"@sentry/node": "7.69.0", | ||
"@sentry/opentelemetry-node": "7.69.0", | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@sentry/types": "7.69.0", | ||
"@sentry/utils": "7.69.0" | ||
}, | ||
"devDependencies": { | ||
"bun-types": "latest" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how we can say what versions of Bun we support 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't bother too much, let's lock in once we know 😬 |
||
}, | ||
"scripts": { | ||
"build": "run-p build:transpile build:types", | ||
"build:dev": "yarn build", | ||
"build:transpile": "rollup -c rollup.npm.config.js", | ||
"build:types": "run-s build:types:core build:types:downlevel", | ||
"build:types:core": "tsc -p tsconfig.types.json", | ||
"build:types:downlevel": "yarn downlevel-dts build/types build/types-ts3.8 --to ts3.8", | ||
"build:watch": "run-p build:transpile:watch build:types:watch", | ||
"build:dev:watch": "yarn build:watch", | ||
"build:transpile:watch": "rollup -c rollup.npm.config.js --watch", | ||
"build:types:watch": "tsc -p tsconfig.types.json --watch", | ||
"build:tarball": "ts-node ../../scripts/prepack.ts && npm pack ./build", | ||
"circularDepCheck": "madge --circular src/index.ts", | ||
"clean": "rimraf build coverage sentry-node-*.tgz", | ||
"fix": "run-s fix:eslint fix:prettier", | ||
"fix:eslint": "eslint . --format stylish --fix", | ||
"fix:prettier": "prettier --write \"{src,test,scripts}/**/**.ts\"", | ||
"lint": "run-s lint:prettier lint:eslint", | ||
"lint:eslint": "eslint . --format stylish", | ||
"lint:prettier": "prettier --check \"{src,test,scripts}/**/**.ts\"", | ||
"install:bun": "node ./scripts/install-bun.js", | ||
"test": "run-s install:bun test:bun", | ||
"test:bun": "bun test", | ||
"test:watch": "bun test --watch", | ||
"yalc:publish": "ts-node ../../scripts/prepack.ts && yalc publish build --push" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
}, | ||
"sideEffects": false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; | ||
|
||
const config = makeNPMConfigVariants(makeBaseNPMConfig()); | ||
|
||
// remove cjs from config array config[0].output.format == cjs | ||
export default [config[1]]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const { exec } = require('child_process'); | ||
const https = require('https'); | ||
|
||
// Define the URL of the Bash script for bun installation | ||
const installScriptUrl = 'https://bun.sh/install'; | ||
|
||
// Check if bun is installed | ||
exec('bun -version', error => { | ||
if (error) { | ||
console.error('bun is not installed. Installing...'); | ||
// Download and execute the installation script | ||
https | ||
.get(installScriptUrl, res => { | ||
if (res.statusCode !== 200) { | ||
console.error(`Failed to download the installation script (HTTP ${res.statusCode})`); | ||
process.exit(1); | ||
} | ||
|
||
res.setEncoding('utf8'); | ||
let scriptData = ''; | ||
|
||
res.on('data', chunk => { | ||
scriptData += chunk; | ||
}); | ||
|
||
res.on('end', () => { | ||
// Execute the downloaded script | ||
exec(scriptData, installError => { | ||
Check failureCode scanning / CodeQL Uncontrolled command line
This command line depends on a [user-provided value](1).
|
||
if (installError) { | ||
console.error('Failed to install bun:', installError); | ||
process.exit(1); | ||
} | ||
console.log('bun has been successfully installed.'); | ||
}); | ||
}); | ||
}) | ||
.on('error', e => { | ||
console.error('Failed to download the installation script:', e); | ||
process.exit(1); | ||
}); | ||
} else { | ||
// Bun is installed | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { ServerRuntimeClientOptions } from '@sentry/core'; | ||
import { SDK_VERSION, ServerRuntimeClient } from '@sentry/core'; | ||
import * as os from 'os'; | ||
import { TextEncoder } from 'util'; | ||
|
||
import type { BunClientOptions } from './types'; | ||
|
||
/** | ||
* The Sentry Node SDK Client. | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @see BunClientOptions for documentation on configuration options. | ||
* @see SentryClient for usage documentation. | ||
*/ | ||
export class BunClient extends ServerRuntimeClient<BunClientOptions> { | ||
/** | ||
* Creates a new Node SDK instance. | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param options Configuration options for this SDK. | ||
*/ | ||
public constructor(options: BunClientOptions) { | ||
options._metadata = options._metadata || {}; | ||
options._metadata.sdk = options._metadata.sdk || { | ||
name: 'sentry.javascript.bun', | ||
packages: [ | ||
{ | ||
name: 'npm:@sentry/bun', | ||
version: SDK_VERSION, | ||
}, | ||
], | ||
version: SDK_VERSION, | ||
}; | ||
|
||
// Until node supports global TextEncoder in all versions we support, we are forced to pass it from util | ||
options.transportOptions = { | ||
textEncoder: new TextEncoder(), | ||
...options.transportOptions, | ||
}; | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const clientOptions: ServerRuntimeClientOptions = { | ||
...options, | ||
platform: 'bun', | ||
runtime: { name: 'bun', version: Bun.version }, | ||
serverName: options.serverName || global.process.env.SENTRY_NAME || os.hostname(), | ||
}; | ||
|
||
super(clientOptions); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
export type { | ||
Breadcrumb, | ||
BreadcrumbHint, | ||
PolymorphicRequest, | ||
Request, | ||
SdkInfo, | ||
Event, | ||
EventHint, | ||
Exception, | ||
Session, | ||
// eslint-disable-next-line deprecation/deprecation | ||
Severity, | ||
SeverityLevel, | ||
Span, | ||
StackFrame, | ||
Stacktrace, | ||
Thread, | ||
Transaction, | ||
User, | ||
} from '@sentry/types'; | ||
export type { AddRequestDataToEventOptions } from '@sentry/utils'; | ||
|
||
export type { TransactionNamingScheme } from '@sentry/node'; | ||
export type { BunOptions } from './types'; | ||
|
||
export { | ||
addGlobalEventProcessor, | ||
addBreadcrumb, | ||
captureException, | ||
captureEvent, | ||
captureMessage, | ||
close, | ||
configureScope, | ||
createTransport, | ||
extractTraceparentData, | ||
flush, | ||
getActiveTransaction, | ||
getHubFromCarrier, | ||
getCurrentHub, | ||
Hub, | ||
lastEventId, | ||
makeMain, | ||
runWithAsyncContext, | ||
Scope, | ||
startTransaction, | ||
SDK_VERSION, | ||
setContext, | ||
setExtra, | ||
setExtras, | ||
setTag, | ||
setTags, | ||
setUser, | ||
spanStatusfromHttpCode, | ||
trace, | ||
withScope, | ||
captureCheckIn, | ||
setMeasurement, | ||
getActiveSpan, | ||
startSpan, | ||
// eslint-disable-next-line deprecation/deprecation | ||
startActiveSpan, | ||
HazAT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
startInactiveSpan, | ||
startSpanManual, | ||
} from '@sentry/core'; | ||
export type { SpanStatusType } from '@sentry/core'; | ||
export { autoDiscoverNodePerformanceMonitoringIntegrations } from '@sentry/node'; | ||
|
||
export { BunClient } from './client'; | ||
export { defaultIntegrations, init } from './sdk'; | ||
|
||
import { Integrations as CoreIntegrations } from '@sentry/core'; | ||
import { Integrations as NodeIntegrations } from '@sentry/node'; | ||
|
||
const INTEGRATIONS = { | ||
...CoreIntegrations, | ||
...NodeIntegrations, | ||
}; | ||
|
||
export { INTEGRATIONS as Integrations }; |
Uh oh!
There was an error while loading. Please reload this page.