Skip to content

Commit

Permalink
Tracing Instrumentation (#368)
Browse files Browse the repository at this point in the history
* Instrument append and subscribe methods
  • Loading branch information
w1am authored May 10, 2024
1 parent d2b2874 commit 792842e
Show file tree
Hide file tree
Showing 27 changed files with 2,625 additions and 656 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:

- name: streams
path: ./src/streams

- name: opentelemetry
path: ./src/opentelemetry
env:
# Github only passes secrets to the main repo, so we need to skip some things if they are unavailable
SECRETS_AVAILABLE: ${{ secrets.eventstore_cloud_id != null }}
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This changelog is no longer maintained. The changelog information has been moved to the individual package directories.
This changelog is no longer maintained. The changelog information has been moved to the individual package directories.
203 changes: 8 additions & 195 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,194 +8,11 @@ EventStoreDB is the event-native database, where business events are immutably s

This monorepo contains the following packages:

| Subfolder | Package |
| -------------------------------------------- | --------------------------------------------------------------------------- |
| [`packages/db-client/`](packages/db-client/) | [`@eventstore/client`](https://www.npmjs.com/package/@eventstore/db-client) |
| [`packages/test/`](packages/test/) | Client internal tests |

## Installation

```shell script
# Yarn
$ yarn add @eventstore/db-client

# NPM
$ npm install --save @eventstore/db-client
```

## EventStoreDB Server Compatibility

This client is compatible with version `20.6.1` upwards.

Server setup instructions can be found under the installation section of the [Event Store Docs]. Follow the Docker setup for the simplest configuration.

## Documentation

Full documentation can be found in [Event Store GRPC Client Docs].

## Example

The following snippet showcases a simple example where we form a connection, then append and read events from the server.

###### Javascript example:

```javascript
const {
EventStoreDBClient,
jsonEvent,
FORWARDS,
START,
} = require('@eventstore/db-client');

const client = new EventStoreDBClient(
{
endpoint: 'localhost:2113',
},
{ insecure: true }
);

(async () => {
try {
const streamName = 'booking-transactions';

// define an event
const event = jsonEvent({
type: 'booking-initiated',
data: {
bookingId: 'booking-456',
userId: 'user-789',
event: 'Concert of The Rolling Stones',
timestamp: new Date().toISOString(),
},
metadata: {
createdByUserId: 'user-789',
sourceIp: '192.168.1.100',
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)',
}
});

// append the event
await client.appendToStream(streamName, [event]);

// read the event
const events = client.readStream(streamName, {
fromRevision: START,
direction: FORWARDS,
maxCount: 10,
});

for await (const { event } of events) {
console.log('Appended event: ', event);
}
} catch (error) {
console.error('An error occured: ', error);
} finally {
await client.dispose();
}
})();
```

###### Typescript example:

```typescript
import {
EventStoreDBClient,
jsonEvent,
FORWARDS,
START,
type JSONEventType,
} from "@eventstore/db-client";

// Create a client to connect to EventStoreDB
const client = EventStoreDBClient.connectionString`esdb://localhost:2113`;

// Define the events that can occur during a booking

type SeatReservedEvent = JSONEventType<
"seat-reserved",
{
reservationId: string;
movieId: string;
userId: string;
seatId: string;
}
>;

type SeatChangedEvent = JSONEventType<
"seat-changed",
{
reservationId: string;
newSeatId: string;
}
>;

type ReservationEvents = SeatReservedEvent | SeatChangedEvent;

// Write events to a stream that describe the history of our booking

const streamName = "booking-abc123";

const event = jsonEvent<SeatReservedEvent>({
type: "seat-reserved",
data: {
reservationId: "abc123",
movieId: "tt0368226",
userId: "nm0802995",
seatId: "4b",
},
});

const appendResult = await client.appendToStream<ReservationEvents>(
streamName,
event
);

// By reading the events in the stream, we can construct the current state of the booking

interface Reservation {
reservationId: string;
movieId: string;
userId: string;
seatId: string;
}

const events = client.readStream<ReservationEvents>(streamName, {
fromRevision: START,
direction: FORWARDS,
maxCount: 10,
});

const reservation: Partial<Reservation> = {};

for await (const { event } of events) {
switch (event?.type) {
case "seat-reserved": {
reservation.reservationId = event.data.reservationId;
reservation.movieId = event.data.movieId;
reservation.seatId = event.data.seatId;
reservation.userId = event.data.userId;
break;
}
case "seat-changed": {
reservation.seatId = event.data.newSeatId;
break;
}
}
}

// Do something with our reservation
console.log(reservation);
```


## Build from source

This project uses [Yarn] as a build tool. The following shell command lines should get you started:

```shell script
$ yarn
$ yarn build
```
| Subfolder | Package |
| ---------------------------------------------------- | --------------------------------------------------------------------------- |
| [`packages/db-client/`](packages/db-client/) | [`@eventstore/client`](https://www.npmjs.com/package/@eventstore/db-client) |
| [`packages/opentelemetry/`](packages/opentelemetry/) | Unpublished |
| [`packages/test/`](packages/test/) | Internal tests |

## Support

Expand All @@ -205,20 +22,16 @@ Information on support can be found on our website: [Event Store Support]

- [Discuss]
- [Discord (Event Store)][discord-event-store]
- [Discord (ddd-cqrs-es)][Discord-ddd-cqrs-es]
- [Discord (ddd-cqrs-es)][discord-ddd-cqrs-es]

## Contributing

Refer to our [Contribution Guidelines]

[event store support]: https://eventstore.com/support/
[event store docs]: https://developers.eventstore.com/latest.html
[contribution guidelines]: https://github.com/EventStore/EventStore-Client-NodeJS/blob/main/CONTRIBUTING.md
[discuss]: https://discuss.eventstore.com/
[discord-event-store]: https://discord.gg/Phn9pmCw3t
[Discord-ddd-cqrs-es]: https://discord.com/invite/sEZGSHNNbH
[event store grpc client docs]: https://developers.eventstore.com/clients/grpc
[event store discuss]: https://discuss.eventstore.com/
[yarn]: https://yarnpkg.com/
[license-badge]: https://img.shields.io/npm/l/@eventstore/db-client.svg
[license-badge-url]: https://github.com/EventStore/EventStore-Client-NodeJS/blob/master/LICENSE
[license-badge-url]: https://github.com/EventStore/EventStore-Client-NodeJS/blob/master/LICENSE
[Contribution Guidelines]: https://github.com/EventStore/EventStore-Client-NodeJS/blob/master/CONTRIBUTING.md
10 changes: 5 additions & 5 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"scripts": {
"build": "lerna run --stream build",
"build:ts": "lerna run --stream build:ts",
"build:watch": "lerna run --stream build:watch",
"build:watch": "lerna run build:watch --parallel",
"lint": "run-s -c lint:*",
"lint:prettier": "prettier --check \"packages/*/src/**/**/!(*.d).{ts,json}\"",
"lint:eslint": "eslint \"packages/*/src/**/*.ts\"",
"prettier:fix": "prettier --write \"packages/*/src/**/**/!(*.d).{ts,json}\"",
"clean": "lerna run --stream clean",
"prepublishOnly": "run-s clean build test",
"test": "lerna run --stream test --"
"test": "lerna run --stream test --",
"postinstall": "yarn build"
},
"author": "Event Store Limited",
"license": "Apache-2.0",
Expand All @@ -24,6 +25,7 @@
"@types/node": "^16.18.67",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-plugin-tsdoc": "^0.2.17",
"lerna": "^6.6.2",
Expand Down
Loading

0 comments on commit 792842e

Please sign in to comment.