https://github.com/beincom/bic-otel-tracing
https://github.com/beincom/bic-otel-tracing
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/beincom/bic-otel-tracing
- Owner: beincom
- Created: 2024-04-04T14:41:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T06:10:48.000Z (over 1 year ago)
- Last Synced: 2025-08-08T14:01:59.425Z (10 months ago)
- Language: TypeScript
- Size: 510 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Getting started
```
npm install @beincom/otel-tracing
# yarn add @beincom/otel-tracing
```
### Usage
```
# app.module.ts
@Module({
imports: [
TraceModule.forRootAsync({
useFactory: (configService: ConfigService) => {
const traceConfig: TraceConfig = {
collectorUrl: process.env.TRACE_COLLECTOR_URL,
serviceName: process.env.TRACE_SERVICE_NAME,
isDebug: process.env.TRACE_DEBUG === 'true',
isEnabled: process.env.TRACE_ENABLED === 'true',
concurrencyLimit: parseInt(
process.env.TRACE_CONCURRENCY_LIMIT || '10'
),
samplerRatio: parseInt(process.env.TRACE_SAMPLER_RATIO || '1'),
timeout: parseInt(process.env.TRACE_TIMEOUT || '30000'),
};
return new TraceService(traceConfig);
},
inject: [ConfigService],
}),
],
providers: [],
exports: [],
})
export class AppModule {}
# app.controller.ts
@Controller()
export class AppController {
public constructor(
@Inject(TRACE_SERVICE_TOKEN)
private readonly _traceService: ITraceService,
) {}
@CreateSpan({
spanName: 'index',
spanKind: SpanKind.INTERNAL,
hasAttribute: false, // default: true
shouldBindContext: true // default: false
})
@Get()
public async index(
@Body() body: any,
span?: Span
): Promise {
// Inject span to body to propagate
this._traceService.injectToPropagation(body, span);
return true;
}
}
```