Registry / devops / sentry-api

sentry-api

JSON →
library0.2.0jsnpmunverified

The `sentry-api` package provides a Node.js client for interacting with the Sentry API specifically for administrative tasks, such as managing projects, creating releases, and uploading source maps. This library is distinct from Sentry's official event reporting SDKs which focus on error ingestion. The current stable version is 0.2.0. It is explicitly in "maintenance mode," meaning it will receive bug fixes and version updates but no new feature development. This makes it suitable for existing integrations but potentially not ideal for leveraging the latest Sentry API features. Its primary differentiation is enabling programmatic control over Sentry platform data rather than just error reporting.

npm install sentry-api
INSTALL
IMPORT
SIG · SENTRY-API
S
sentry-api
devopsjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Client
const { Client } = require('sentry-api');
import { Client } from 'sentry-api';
This library is exclusively CommonJS and does not provide ESM exports. The `Client` class is a named export from the main module. Attempting to use ESM `import` will result in module loading errors.
SentryAPI module object
const SentryAPI = require('sentry-api'); const client = new SentryAPI.Client(...);
const client = new require('sentry-api').Client(...);
You can import the entire module object and then access the `Client` property. Avoid nesting `require` directly within the `new` call for readability and common practice.
Default Export (None)
/* No default export exists for this package. */
const Sentry = require('sentry-api').default;
The `sentry-api` package does not expose a default export. The primary class `Client` must be accessed as a named property from the CommonJS module object.

Demonstrates how to initialize the Sentry API client, create a new release (or use an existing one), and upload source map files for a specific project and version using DSN and authentication tokens. Includes error handling and cleanup of temporary files.

const fs = require('fs'); const Promise = require('promise'); // npm i promise, if not on a Node.js version with global Promise const { Client: SentryClient } = require('sentry-api'); // Your Sentry DSN or authentication token // Use process.env for sensitive credentials in a real application const SENTRY_DSN = process.env.SENTRY_DSN ?? 'https://dummy@sentry.io/12345'; // Replace with a valid Sentry DSN const SENTRY_TOKEN = process.env.SENTRY_TOKEN ?? 'your-sentry-auth-token'; // Replace with a valid Sentry API token // Initialize the Sentry API client // You can omit DSN if using token authentication with hosted Sentry const sentry = new SentryClient(SENTRY_DSN, { token: SENTRY_TOKEN }); const organization = 'my-organization-slug'; // Replace with your Sentry organization slug const project = 'my-project-slug'; // Replace with your Sentry project slug const version = `my-app-v1.0.0-${Date.now()}`; // Generate a unique version for demonstration // Create dummy files for upload demonstration const dummyFilePath = 'app.min.js'; fs.writeFileSync(dummyFilePath, 'console.log("hello world");'); const dummyMapPath = 'app.min.js.map'; fs.writeFileSync(dummyMapPath, '{}'); // Empty map file console.log(`Attempting to manage Sentry release for org: ${organization}, project: ${project}, version: ${version}`); // Check if a release already exists, otherwise create a new one, then upload files. sentry.releases.get(organization, project, version) .then(function(release) { console.log(`Release ${version} already exists!`); return release; // Proceed with existing release }) .catch(function(err) { // If the release doesn't exist (e.g., 404 error), create it if (err.statusCode === 404) { console.log(`Release ${version} not found. Creating a new one...`); return sentry.releases.create(organization, project, { version: version, ref: version, dateStarted: new Date().toISOString(), }) .then(function(release) { console.log('Created release:', release.version); return release; }); } throw err; // Re-throw other errors }) .then(function(release) { const filesToUpload = [dummyFilePath, dummyMapPath]; // Add files (e.g., source maps) to the release const uploads = filesToUpload.map(function(file) { return sentry.releases.createFile(organization, project, release.version, { name: file, file: fs.createReadStream(file) }).then(function(newFile) { console.log('Uploaded file:', newFile.name); }); }); return Promise.all(uploads); }) .then(function() { console.log('Uploaded all files for the release.'); console.log('Cleaning up dummy files...'); fs.unlinkSync(dummyFilePath); fs.unlinkSync(dummyMapPath); console.log('Dummy files cleaned up.'); console.log('Quickstart example completed successfully.'); }) .catch(function(error) { console.error('Error in Sentry release management:', error.message || error); if (error.statusCode) { console.error('Status Code:', error.statusCode); console.error('Response Body:', error.responseBody); } // Ensure cleanup even on error if (fs.existsSync(dummyFilePath)) fs.unlinkSync(dummyFilePath); if (fs.existsSync(dummyMapPath)) fs.unlinkSync(dummyMapPath); });
Debug
Known issues
gotchaThe `sentry-api` library is explicitly in "maintenance mode," meaning it will not receive new feature development. Users should not expect support for new Sentry API endpoints or functionalities released after the library's last active development phase.
fix
For access to newer Sentry API features, consider directly using Sentry's REST API or an actively maintained client if one becomes available. The official Sentry CLI (`sentry` npm package) offers programmatic interaction and is actively maintained.
affects: >=0.2.0
breakingAs an older library (last updated around 2015-2016), `sentry-api` may not be fully compatible with current versions of Node.js or might rely on deprecated Node.js features. Future Node.js releases could introduce breaking changes to underlying APIs this library uses.
fix
Thoroughly test `sentry-api` in your specific Node.js environment. For critical projects, consider vendoring and patching the library, or migrating to direct Sentry API calls or a more modern alternative like the Sentry CLI's programmatic API.
affects: >=0.2.0
gotchaThe library primarily supports CommonJS module loading (`require`). Attempting to `import` it directly in an ES Module context will result in errors unless a compatibility layer (e.g., `esm` or specific build tool configurations) is used.
fix
Always use `const { Client } = require('sentry-api');` in CommonJS files. For ESM projects, you might need to use dynamic `import('sentry-api').then(...)` or configure your build tool (e.g., Webpack, Rollup) to transpile or handle CommonJS modules.
affects: >=0.2.0
Errors
Common errors & fixes
TypeError: Sentry.releases is undefined
The `Client` instance was not correctly initialized, or the DSN/token provided was invalid, preventing the API endpoint objects (like `releases`, `projects`) from being attached.
fix
Ensure `new Client(...)` is called with a valid DSN or authentication token, and that the returned Sentry client instance is used correctly. Check console for any initialization errors.
(node:xyz) UnhandledPromiseRejectionWarning: StatusCodeError: 401 Unauthorized
The Sentry API token provided is missing or invalid, or does not have the necessary permissions for the requested operation.
fix
Verify your Sentry API token's validity and ensure it has the required scopes (e.g., `project:releases`, `org:read`, `org:write`) for the operations you are performing. Pass the token via the `token` option in the client constructor.
(node:xyz) UnhandledPromiseRejectionWarning: StatusCodeError: 404 Not Found (when accessing Sentry resources)
The specified organization slug, project slug, or release version does not exist, or the authenticated API token lacks permissions to access it.
fix
Double-check the accuracy of the organization slug, project slug, and release version. Confirm that the API token has the necessary permissions to `read` or `write` to the specified Sentry resources.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
promiserequiredUsed for promise-based API calls, explicitly required in the examples for older Node.js environments. While modern Node.js has a global Promise, the library's examples demonstrate a reliance on this module.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
sentry-api — npm install sentry-api · libregistry