-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add ability to shutdonw tracing gracefully #212
Conversation
1. **Logger Configuration**: - The `diag.setLogger` function now uses a `DiagConsoleLogger` with a log level set to `INFO`. This ensures that tracing logs are properly configured for debugging purposes. 2. **Tracer Provider Initialization**: - The `NodeTracerProvider` is now initialized with a `Resource` object that includes attributes such as `CONTAINER_NAME` and `DEPLOYMENT_ENVIRONMENT`. This provides context to the tracing system. - The `tracerProvider` is declared in module scope for access in the `stopTracing` function. 3. **Propagator Configuration**: - A `CompositePropagator` is used to combine multiple propagators (`W3CBaggagePropagator`, `W3CTraceContextPropagator`, and `B3Propagator`) for efficient propagation of tracing context across different systems. 4. **Span Processor Configuration**: - The `OTLPTraceExporter` is configured with options for exporting traces to a collector endpoint using gRPC. - A `BatchSpanProcessor` is registered with the tracer provider to handle batch processing of spans before exporting them. 5. **Instrumentation Registration**: - Various instrumentations (Express, Pino, HTTP, AWS, DNS) are registered with the tracer provider to instrument specific parts of the application. - Each instrumentation is configured with relevant hooks and settings to ensure accurate and efficient tracing. 6. **Graceful Shutdown**: - A new `stopTracing` function has been added to gracefully shut down the tracing system by shutting down the tracer provider and ensuring all pending spans are exported before cleanup. This commit enhances the OpenTelemetry tracing setup by improving logger configuration, tracer provider initialization, propagator combination, span processor configuration, instrumentation registration, and adding a graceful shutdown mechanism. These changes ensure robustness and efficiency in tracing operations within the application. chore: update k8s test branch
825d103
to
ecd6fc9
Compare
/code pr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖
The changes look solid overall, with good improvements to the tracing implementation. Here's my review:
Positives:
- Good addition of graceful shutdown functionality via
stopTracing()
- Improved code organisation with module-scoped
tracerProvider
- Better error handling in shutdown process
- Clear documentation with JSDoc comments
- Proper separation of exporter and span processor setup
Suggestions for improvement:
- In
stopTracing()
:
// Consider adding a timeout parameter
export async function stopTracing(timeoutMs = 5000) {
if (!tracerProvider) return;
try {
await Promise.race([
tracerProvider.shutdown(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Shutdown timeout')), timeoutMs)
)
]);
console.info('Tracing shutdown complete');
} catch (error) {
console.error('Tracing shutdown failed:', error);
}
}
- Fix indentation inconsistencies in the instrumentations setup:
registerInstrumentations({
tracerProvider: tracerProvider,
instrumentations: [
// Keep consistent indentation throughout
]
});
- Consider adding a simple status check method:
export function isTracingActive() {
return tracerProvider !== null;
}
The changes are well-structured and improve the codebase. Just ensure the indentation is consistent throughout the file.
> claude-3-5-sonnet-20241022 [pr | 1]
Thediag.setLogger
function now uses aDiagConsoleLogger
with a log level set toINFO
. This ensures that tracing logs are properly configured for debugging purposes.NodeTracerProvider
is now initialized with aResource
object that includes attributes such asCONTAINER_NAME
andDEPLOYMENT_ENVIRONMENT
. This provides context to the tracing system.tracerProvider
is declared in module scope for access in thestopTracing
function.CompositePropagator
is used to combine multiple propagators (W3CBaggagePropagator
,W3CTraceContextPropagator
, andB3Propagator
) for efficient propagation of tracing context across different systems.OTLPTraceExporter
is configured with options for exporting traces to a collector endpoint using gRPC.BatchSpanProcessor
is registered with the tracer provider to handle batch processing of spans before exporting them.stopTracing
function has been added to gracefully shut down the tracing system by shutting down the tracer provider and ensuring all pending spans are exported before cleanup.This commit enhances the OpenTelemetry tracing setup by improving logger configuration, tracer provider initialization, propagator combination, span processor configuration, instrumentation registration, and adding a graceful shutdown mechanism. These changes ensure robustness and efficiency in tracing operations within the application.