Skip to content
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

docs: Improve docstrings for node otel integrations #14217

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/node/src/integrations/tracing/amqplib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,18 @@ const _amqplibIntegration = (() => {
};
}) satisfies IntegrationFn;

/**
* Adds Sentry tracing instrumentation for the [amqplib](https://www.npmjs.com/package/amqplib) library.
*
* For more information, see the [`amqplibIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/amqplib/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.amqplibIntegration()],
* });
* ```
*/
export const amqplibIntegration = defineIntegration(_amqplibIntegration);
35 changes: 35 additions & 0 deletions packages/node/src/integrations/tracing/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ const _connectIntegration = (() => {
};
}) satisfies IntegrationFn;

/**
* Adds Sentry tracing instrumentation for [Connect](https://github.com/senchalabs/connect/).
*
* If you also want to capture errors, you need to call `setupConnectErrorHandler(app)` after you initialize your connect app.
*
* For more information, see the [connect documentation](https://docs.sentry.io/platforms/javascript/guides/connect/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.connectIntegration()],
* })
* ```
*/
export const connectIntegration = defineIntegration(_connectIntegration);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -37,6 +53,25 @@ function connectErrorMiddleware(err: any, req: any, res: any, next: any): void {
next(err);
}

/**
* Add a Connect middleware to capture errors to Sentry.
*
* @param app The Connect app to attach the error handler to
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
* const connect = require("connect");
*
* const app = connect();
*
* Sentry.setupConnectErrorHandler(app);
*
* // Add you connect routes here
*
* app.listen(3000);
* ```
*/
export const setupConnectErrorHandler = (app: ConnectApp): void => {
app.use(connectErrorMiddleware);

Expand Down
13 changes: 11 additions & 2 deletions packages/node/src/integrations/tracing/dataloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ const _dataloaderIntegration = (() => {
}) satisfies IntegrationFn;

/**
* Dataloader integration
* Adds Sentry tracing instrumentation for the [dataloader](https://www.npmjs.com/package/dataloader) library.
*
* Capture tracing data for Dataloader.
* For more information, see the [`dataloaderIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/dataloader/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.dataloaderIntegration()],
* });
* ```
*/
export const dataloaderIntegration = defineIntegration(_dataloaderIntegration);
38 changes: 34 additions & 4 deletions packages/node/src/integrations/tracing/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ const _expressIntegration = (() => {
}) satisfies IntegrationFn;

/**
* Express integration
* Adds Sentry tracing instrumentation for [Express](https://expressjs.com/).
*
* Capture tracing data for express.
* In order to capture exceptions, you have to call `setupExpressErrorHandler(app)` before any other middleware and after all controllers.
* If you also want to capture errors, you need to call `setupExpressErrorHandler(app)` after you set up your Express server.
*
* For more information, see the [express documentation](https://docs.sentry.io/platforms/javascript/guides/express/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.expressIntegration()],
* })
* ```
*/
export const expressIntegration = defineIntegration(_expressIntegration);

Expand Down Expand Up @@ -134,8 +144,28 @@ export function expressErrorHandler(options?: ExpressHandlerOptions): ExpressMid
}

/**
* Setup an error handler for Express.
* Add an Express error handler to capture errors to Sentry.
*
* The error handler must be before any other middleware and after all controllers.
*
* @param app The Express instances
* @param options {ExpressHandlerOptions} Configuration options for the handler
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
* const express = require("express");
*
* const app = express();
*
* // Add your routes, etc.
*
* // Add this after all routes,
* // but before any and other error-handling middlewares are defined
* Sentry.setupExpressErrorHandler(app);
*
* app.listen(3000);
* ```
*/
export function setupExpressErrorHandler(
app: { use: (middleware: ExpressMiddleware) => unknown },
Expand Down
33 changes: 30 additions & 3 deletions packages/node/src/integrations/tracing/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,41 @@ const _fastifyIntegration = (() => {
}) satisfies IntegrationFn;

/**
* Express integration
* Adds Sentry tracing instrumentation for [Fastify](https://fastify.dev/).
*
* Capture tracing data for fastify.
* If you also want to capture errors, you need to call `setupFastifyErrorHandler(app)` after you set up your Fastify server.
*
* For more information, see the [fastify documentation](https://docs.sentry.io/platforms/javascript/guides/fastify/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.fastifyIntegration()],
* })
* ```
*/
export const fastifyIntegration = defineIntegration(_fastifyIntegration);

/**
* Setup an error handler for Fastify.
* Add an Fastify error handler to capture errors to Sentry.
*
* @param fastify The Fastify instance to which to add the error handler
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
* const Fastify = require("fastify");
*
* const app = Fastify();
*
* Sentry.setupFastifyErrorHandler(app);
*
* // Add your routes, etc.
*
* app.listen({ port: 3000 });
* ```
*/
export function setupFastifyErrorHandler(fastify: Fastify): void {
const plugin = Object.assign(
Expand Down
13 changes: 11 additions & 2 deletions packages/node/src/integrations/tracing/genericPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ const _genericPoolIntegration = (() => {
}) satisfies IntegrationFn;

/**
* GenericPool integration
* Adds Sentry tracing instrumentation for the [generic-pool](https://www.npmjs.com/package/generic-pool) library.
*
* Capture tracing data for GenericPool.
* For more information, see the [`genericPoolIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/genericpool/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.genericPoolIntegration()],
* });
* ```
*/
export const genericPoolIntegration = defineIntegration(_genericPoolIntegration);
14 changes: 12 additions & 2 deletions packages/node/src/integrations/tracing/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,19 @@ const _graphqlIntegration = ((options: GraphqlOptions = {}) => {
}) satisfies IntegrationFn;

/**
* GraphQL integration
* Adds Sentry tracing instrumentation for the [graphql](https://www.npmjs.com/package/graphql) library.
*
* Capture tracing data for GraphQL.
* For more information, see the [`graphqlIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/graphql/).
*
* @param {GraphqlOptions} options Configuration options for the GraphQL integration.
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.graphqlIntegration()],
* });
*/
export const graphqlIntegration = defineIntegration(_graphqlIntegration);

Expand Down
32 changes: 30 additions & 2 deletions packages/node/src/integrations/tracing/hapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ const _hapiIntegration = (() => {
}) satisfies IntegrationFn;

/**
* Hapi integration
* Adds Sentry tracing instrumentation for [Hapi](https://hapi.dev/).
*
* Capture tracing data for Hapi.
* If you also want to capture errors, you need to call `setupHapiErrorHandler(server)` after you set up your server.
*
* For more information, see the [hapi documentation](https://docs.sentry.io/platforms/javascript/guides/hapi/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.hapiIntegration()],
* })
* ```
*/
export const hapiIntegration = defineIntegration(_hapiIntegration);

Expand Down Expand Up @@ -81,6 +91,24 @@ export const hapiErrorPlugin = {

/**
* Add a Hapi plugin to capture errors to Sentry.
*
* @param server The Hapi server to attach the error handler to
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
* const Hapi = require('@hapi/hapi');
*
* const init = async () => {
* const server = Hapi.server();
*
* // all your routes here
*
* await Sentry.setupHapiErrorHandler(server);
*
* await server.start();
* };
* ```
*/
export async function setupHapiErrorHandler(server: Server): Promise<void> {
await server.register(hapiErrorPlugin);
Expand Down
12 changes: 10 additions & 2 deletions packages/node/src/integrations/tracing/kafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ const _kafkaIntegration = (() => {
}) satisfies IntegrationFn;

/**
* KafkaJs integration
* Adds Sentry tracing instrumentation for the [kafkajs](https://www.npmjs.com/package/kafkajs) library.
*
* Capture tracing data for KafkaJs.
* For more information, see the [`kafkaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/kafka/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.kafkaIntegration()],
* });
*/
export const kafkaIntegration = defineIntegration(_kafkaIntegration);
38 changes: 38 additions & 0 deletions packages/node/src/integrations/tracing/koa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,46 @@ const _koaIntegration = (() => {
};
}) satisfies IntegrationFn;

/**
* Adds Sentry tracing instrumentation for [Koa](https://koajs.com/).
*
* If you also want to capture errors, you need to call `setupKoaErrorHandler(app)` after you set up your Koa server.
*
* For more information, see the [koa documentation](https://docs.sentry.io/platforms/javascript/guides/koa/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.koaIntegration()],
* })
* ```
*/
export const koaIntegration = defineIntegration(_koaIntegration);

/**
* Add an Koa error handler to capture errors to Sentry.
*
* The error handler must be before any other middleware and after all controllers.
*
* @param app The Express instances
* @param options {ExpressHandlerOptions} Configuration options for the handler
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
* const Koa = require("koa");
*
* const app = new Koa();
*
* Sentry.setupKoaErrorHandler(app);
*
* // Add your routes, etc.
*
* app.listen(3000);
* ```
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) => Promise<void>) => void }): void => {
app.use(async (ctx, next) => {
Expand Down
12 changes: 10 additions & 2 deletions packages/node/src/integrations/tracing/lrumemoizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ const _lruMemoizerIntegration = (() => {
}) satisfies IntegrationFn;

/**
* LruMemoizer integration
* Adds Sentry tracing instrumentation for the [lru-memoizer](https://www.npmjs.com/package/lru-memoizer) library.
*
* Propagate traces through LruMemoizer.
* For more information, see the [`lruMemoizerIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/lrumemoizer/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.lruMemoizerIntegration()],
* });
*/
export const lruMemoizerIntegration = defineIntegration(_lruMemoizerIntegration);
13 changes: 11 additions & 2 deletions packages/node/src/integrations/tracing/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ const _mongoIntegration = (() => {
}) satisfies IntegrationFn;

/**
* MongoDB integration
* Adds Sentry tracing instrumentation for the [mongodb](https://www.npmjs.com/package/mongodb) library.
*
* Capture tracing data for MongoDB.
* For more information, see the [`mongoIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/mongo/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.mongoIntegration()],
* });
* ```
*/
export const mongoIntegration = defineIntegration(_mongoIntegration);
Loading
Loading