@deployagram/logger-client
v1.0.0
Published
HTTP client for the Deployagram Collector (living-http-logger), built on fetch. Node.js 22+.
Readme
@deployagram/logger-client
A client for the Deployagram Collector (living-http-logger), built on Node's fetch. It is the
Node.js equivalent of the Java DiagramLoggerClient.
npm install @deployagram/logger-clientimport { DiagramLoggerClient } from '@deployagram/logger-client';
const logger = new DiagramLoggerClient({ baseUrl: 'http://localhost:1152' });
await logger.log({
timestamp: new Date().toISOString(),
protocol: 'HTTP',
source: 'EmailClient',
target: 'Emailer',
message: 'POST /Emailer/email',
body: '{"email":"[email protected]"}',
});
const all = await logger.read(); // GET /log/read
const marked = await logger.read('marker'); // GET /log/read/{id}
await logger.markEnd('marker'); // POST /log/markEnd/{id}
await logger.flushToCloud('Emailer', 'run-1'); // POST /run/markTestRunEnd/{container}/{run}| Method | Collector endpoint |
|---|---|
| log(log) | POST /log |
| read() | GET /log/read |
| read(id) | GET /log/read/{id} |
| markEnd(id) | POST /log/markEnd/{id} |
| flushToCloud(container, run) | POST /run/markTestRunEnd/{container}/{run} |
| configureKafkaBroker(bootstrapServers) | PUT /kafka/configuration |
| configureSchemaRegistry(url) | PUT /schemaRegistry/configuration |
| kafkaConsumerRead(read) | POST /kafka/consumer |
| kafkaProducerRecord(record) | POST /kafka/producer |
Differences from the Java client:
- A non-2xx response throws
CollectorError, which hasstatusandresponseBody. The Java client ignores the status. - Every method returns a Promise.
- The configure calls need the Collector in runtime configuration mode. In static mode the Collector
answers
409, which throws, so a test never silently reads from the wrong broker. flushToCloudcallsmarkTestRunEnd, as the Java client does. On a Collector with a Central Logger configured, that also sends the run to the cloud.
Testing
npm testThe tests need no Collector. They stub the Collector's endpoints with
MSW (Mock Service Worker), declaring each route the way a WireMock stub is
declared, then check the method, path, body and error handling. Any request without a matching
stub fails the test. flushToCloud is not tested.
