-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathAbstractLogServiceClient.ts
More file actions
31 lines (31 loc) · 1.18 KB
/
AbstractLogServiceClient.ts
File metadata and controls
31 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Abstract log service client for dependency injection.
*
* To enable log service syncing in TracingService, implement this class in your application
* and register it with Tegg IoC. The implementation class MUST be named `LogServiceClient`
* (or use `@SingletonProto({ name: 'logServiceClient' })`) so the container can resolve it.
*
* @example
* ```typescript
* import { SingletonProto } from '@eggjs/core-decorator';
* import { AccessLevel } from '@eggjs/tegg-types';
* import { AbstractLogServiceClient } from '@eggjs/agent-tracing';
*
* // Class name must be LogServiceClient (registers as 'logServiceClient' in the IoC container)
* @SingletonProto({ accessLevel: AccessLevel.PUBLIC })
* export class LogServiceClient extends AbstractLogServiceClient {
* async send(log: string): Promise<void> {
* await fetch('https://log.example.com/api', {
* method: 'POST',
* headers: { 'content-type': 'application/json' },
* body: JSON.stringify({ log }),
* });
* }
* }
* ```
*
* If no implementation is registered, log service syncing is silently skipped.
*/
export abstract class AbstractLogServiceClient {
abstract send(log: string): Promise<void>;
}