3.6.2 • Published 7 months ago

apitoolkit-express v3.6.2

Weekly downloads
-
License
-
Repository
-
Last release
7 months ago

APIToolkit Express Middleware is a middleware that can be used to monitor HTTP requests. It is provides additional functionalities on top of the open telemetry instrumentation which creates a custom span for each request capturing details about the request including request and response bodies.

Installation

Run the following command to install the express js package from your projects root:

npm install --save apitoolkit-express @opentelemetry/api @opentelemetry/auto-instrumentations-node

Setup Open Telemetry

Setting up open telemetry allows you to send traces, metrics and logs to the APIToolkit platform.

export OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.apitoolkit.io:4317"
export OTEL_SERVICE_NAME="my-service" # Specifies the name of the service.
export OTEL_RESOURCE_ATTRIBUTES=at-project-key="<YOUR_API_KEY>" # Adds your API KEY to the resource.
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" #Specifies the protocol to use for the OpenTelemetry exporter.
export NODE_OPTIONS="--require @opentelemetry/auto-instrumentations-node/register"

node server.js # starting your express server

HTTP Requests Monitoring

You can monitor http requests using APIToolkit's express middleware, this allows you to monitor all your http requests. including headers, response time, response status code, request body, response body, etc.

import * as express from "express";
import { APIToolkit } from "./index";
import axios from "axios";

const app = express();
const apitoolkitClient = APIToolkit.NewClient({
  serviceName: "my-service",
  serviceVersion: "1.0.0",
  tags: ["env:dev"],
  monitorAxios: axios, // optional, if you want to monitor axios requests
});

// add the middleware to for request monitoring
app.use(apitoolkitClient.middleware);

app.get("/", async (req, res) => {
  const r = await axios.get("https://jsonplaceholder.typicode.com/todos/1");
  res.json(r.data);
});

// automatically report unhandled errors along with the request data
app.use(apitoolkitClient.errorMiddleware);

app.listen(3000, () => {
  console.log("Example app listening on port 3000!");
});

Quick overview of the configuration parameters

An object with the following optional fields can be passed to the middleware to configure it:

OptionDescription
debugSet to true to enable debug mode.
serviceNameA defined string name of your application.
tagsA list of defined tags for your services (used for grouping and filtering data on the dashboard).
serviceVersionA defined string version of your application (used for further debugging on the dashboard).
redactHeadersA list of HTTP header keys to redact.
redactResponseBodyA list of JSONPaths from the response body to redact.
redactRequestBodyA list of JSONPaths from the request body to redact.
captureRequestBodyDefault false, set to true if you want to capture the request body.
captureResponseBodyDefault false, set to true if you want to capture the response body.

!IMPORTANT

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.) and complete integration guide, please read this SDK documentation.

3.6.2

7 months ago

3.6.1

7 months ago

3.6.0

7 months ago

3.5.3

7 months ago

3.5.1

7 months ago

3.5.0

7 months ago

3.0.8

9 months ago

3.1.3

9 months ago

3.1.2

9 months ago

3.1.0

9 months ago

3.1.5

8 months ago

3.1.4

9 months ago

3.0.7

9 months ago

3.0.6

9 months ago

2.0.3

10 months ago

2.0.5

10 months ago

3.0.3

9 months ago

3.0.2

9 months ago

3.0.1

10 months ago

3.0.5

9 months ago

2.4.6

11 months ago

2.4.5

12 months ago

2.4.4

12 months ago

2.4.0

1 year ago

2.4.3

12 months ago

2.3.1

1 year ago

2.3.0

1 year ago

2.2.5

1 year ago

2.2.6

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.4

1 year ago

2.2.1

1 year ago

2.1.1

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.5.4

1 year ago

1.4.4

2 years ago

1.4.3

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.0.7

2 years ago

1.3.3

2 years ago

1.1.5

2 years ago

1.0.6

2 years ago

1.3.2

2 years ago

1.1.4

2 years ago

1.0.5

2 years ago

1.3.1

2 years ago

1.1.3

2 years ago

1.0.4

2 years ago

1.3.0

2 years ago

1.1.2

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.0.3

2 years ago