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

Update Quickstart and recipes #116

Merged
merged 3 commits into from
Sep 15, 2023
Merged
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
77 changes: 60 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Autometrics provides a wrapper function and decorator to instrument functions, c

## Example

```typescript
```ts
import { autometrics } from "@autometrics/autometrics";

const createUserWithMetrics = autometrics(async function createUser(payload: User) {
Expand All @@ -42,21 +42,23 @@ createUserWithMetrics();

![AutometricsTS demo](./assets/autometrics-ts-demo.gif)

## Quickstart
## Quickstart with Node.js and Prometheus

(See the [recipes](#recipes) below for other setup scenarios.)

1. **Install the library**

```bash
npm install @autometrics/autometrics
```sh
npm install @autometrics/autometrics @autometrics/exporter-prometheus
# or
yarn add @autometrics/autometrics
yarn add @autometrics/autometrics @autometrics/exporter-prometheus
# or
pnpm add @autometrics/autometrics
pnpm add @autometrics/autometrics @autometrics/exporter-prometheus
```

2. **Instrument your code using the `autometrics` wrapper or `Autometrics` decorator**

```typescript
```ts
import { autometrics } from "@autometrics/autometrics";

const createUserWithMetrics = autometrics(async function createUser(payload: User) {
Expand All @@ -66,7 +68,7 @@ const createUserWithMetrics = autometrics(async function createUser(payload: Use
createUserWithMetrics();
```

```typescript
```ts
import { Autometrics } from "@autometrics/autometrics";

class User {
Expand All @@ -77,6 +79,17 @@ class User {
}
```

3. **Call `init()` to set up a Prometheus scrape endpoint**

This endpoint will serve to export the metrics from your application and allows
them to be scraped by Prometheus.

```ts
import { init } from "@autometrics/exporter-prometheus";

init(); // starts the webserver with the `/metrics` endpoint on port 9464
```

3. **Run Prometheus locally to validate and preview the data**

You can use the open source Autometrics CLI to run automatically configured Prometheus locally to see the metrics that will be registered by the change. See the [Autometrics CLI docs](https://docs.autometrics.dev/local-development#getting-started-with-am) for more information.
Expand Down Expand Up @@ -133,15 +146,15 @@ Add the language service plugin to the `tsconfig.json` file:

## Recipes

Below are two recipes for using Autometrics in a server-side setup and a
client-side setup. If you would like to see examples with specific frameworks,
please have a look at the [examples/](examples/) directory.
Below are different recipes for using Autometrics with a server-side setup and
edge/client-side setups. If you would like to see examples with specific
frameworks, please have a look at the [examples/](examples/) directory.

### Server-side example with Prometheus

#### Installation

```shell
```sh
npm install @autometrics/autometrics @autometrics/exporter-prometheus
# or
yarn add @autometrics/autometrics @autometrics/exporter-prometheus
Expand All @@ -153,11 +166,41 @@ pnpm add @autometrics/autometrics @autometrics/exporter-prometheus

1. Anywhere in your source code:

```typescript
```ts
import { autometrics } from "@autometrics/autometrics";
import { init } from "@autometrics/exporter-prometheus";

init(); // starts the webserver with the `/metrics` endpoint on port 4964
init(); // starts the webserver with the `/metrics` endpoint on port 9464

async function createUserRaw(payload: User) {
// ...
}

const createUser = autometrics(createUserRaw);
// ^ instrumented function
```

### Recipe: Edge/Client-side example with a Prometheus Push Gateway

#### Installation

```sh
npm install @autometrics/autometrics @autometrics/exporter-prometheus-push-gateway
# or
yarn add @autometrics/autometrics @autometrics/exporter-prometheus-push-gateway
# or
pnpm add @autometrics/autometrics @autometrics/exporter-prometheus-push-gateway
```

#### Usage

1. Anywhere in your source code:

```ts
import { autometrics } from "@autometrics/autometrics";
import { init } from "@autometrics/exporter-prometheus-push-gateway";

init({ url: "https://<your-push-gateway>" });

async function createUserRaw(payload: User) {
// ...
Expand All @@ -167,11 +210,11 @@ const createUser = autometrics(createUserRaw);
// ^ instrumented function
```

### Recipe: Client-side example with the OpenTelemetry Collector
### Recipe: Edge/Client-side example with the OpenTelemetry Collector

#### Installation

```shell
```sh
npm install @autometrics/autometrics @autometrics/exporter-otlp-http
# or
yarn add @autometrics/autometrics @autometrics/exporter-otlp-http
Expand All @@ -183,7 +226,7 @@ pnpm add @autometrics/autometrics @autometrics/exporter-otlp-http

1. Anywhere in your source code:

```typescript
```ts
import { autometrics } from "@autometrics/autometrics";
import { init } from "@autometrics/exporter-otlp-http";

Expand Down