Skip to content

feat: enhance logging across services - #3

Open
henryjandrews wants to merge 3 commits into
mainfrom
henryjandrews/demo-enhancements
Open

henryjandrews wants to merge 3 commits into
mainfrom
henryjandrews/demo-enhancements

Conversation

@henryjandrews

Copy link
Copy Markdown
Collaborator

Changes

Enhanced logging across payment, catalog, and recommendation services

Merge Requirements

For new features contributions, please make sure you have completed the following
essential items:

  • CHANGELOG.md updated to document new feature additions
  • Appropriate documentation updates in the docs
  • Appropriate Helm chart updates in the helm-charts

Maintainers will not merge until the above have been completed. If you're unsure
which docs need to be changed ping the
@open-telemetry/demo-approvers.

gjanco
gjanco previously approved these changes Sep 18, 2025

@gjanco gjanco left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a rename suggestion, but not required.

Comment thread src/recommendation/recommendation_server.py
@henryjandrews
henryjandrews marked this pull request as draft September 18, 2025 22:04
@gjanco
gjanco force-pushed the henryjandrews/demo-enhancements branch from f197126 to 52e2b55 Compare December 16, 2025 02:55
gjanco
gjanco previously approved these changes Dec 16, 2025
@henryjandrews
henryjandrews marked this pull request as ready for review December 16, 2025 16:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances logging capabilities across the payment, catalog, and recommendation services by adding comprehensive observability with OpenTelemetry trace context, system metrics, and detailed error reporting. The changes introduce structured logging with performance monitoring, memory leak detection, and cache behavior tracking.

Key Changes

  • Added trace context propagation and system metrics collection to all three services
  • Implemented detailed cache monitoring and memory leak detection in the recommendation service
  • Enhanced error logging with contextual information including transaction details and system state

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/recommendation/recommendation_server.py Added comprehensive logging with trace context, system metrics, cache operations monitoring, and memory leak detection
src/recommendation/logger.py Enhanced JSON formatter to include OpenTelemetry trace context in all log records
src/product-catalog/main.go Added trace context and system metrics helpers; enhanced error and success logging with detailed context
src/payment/logger.js Added trace context to logger mixin for consistent tracing across log entries
src/payment/charge.js Implemented cache leak simulation, enhanced error logging with system metrics, and detailed transaction context
src/flagd/demo.flagd.json Added new feature flag paymentCacheLeak for testing cache overflow scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'cache_cleanup_error': True,
'error_type': type(cleanup_error).__name__,
'error_message': str(cleanup_error),
'error_stack': str(cleanup_error.__traceback__) if hasattr(cleanup_error, '__traceback__') else 'unavailable',

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting traceback objects to strings using str() produces uninformative output like '<traceback object at 0x...>'. Use traceback.format_exc() or traceback.format_tb() to generate meaningful stack traces that include file names, line numbers, and code context.

Copilot uses AI. Check for mistakes.
'request_id': f"req_{self.request_count}",
'error_type': type(e).__name__,
'error_message': str(e),
'error_stack': str(e.__traceback__) if hasattr(e, '__traceback__') else 'unavailable',

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting traceback objects to strings using str() produces uninformative output like '<traceback object at 0x...>'. Use traceback.format_exc() or traceback.format_tb() to generate meaningful stack traces that include file names, line numbers, and code context.

Copilot uses AI. Check for mistakes.
Comment on lines +232 to +233
'page_faults_major': getattr(process.memory_full_info() if hasattr(process, 'memory_full_info') else memory_info, 'pfaults', 0),
'page_faults_minor': getattr(process.memory_full_info() if hasattr(process, 'memory_full_info') else memory_info, 'pageins', 0)

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The process.memory_full_info() method is called twice per invocation when available, potentially causing performance overhead. Call it once, store the result in a variable, and reuse it for both page fault metrics.

Copilot uses AI. Check for mistakes.
Comment on lines +230 to +231
'context_switches_voluntary': getattr(process, 'num_ctx_switches', lambda: (0, 0))().voluntary,
'context_switches_involuntary': getattr(process, 'num_ctx_switches', lambda: (0, 0))().involuntary,

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The num_ctx_switches() method is called twice per invocation, potentially causing performance overhead. Call it once, store the result in a variable, and reuse it for both voluntary and involuntary context switch counts.

Copilot uses AI. Check for mistakes.
"go.opentelemetry.io/contrib/bridges/otelslog"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/contrib/instrumentation/runtime"
otelruntime "go.opentelemetry.io/contrib/instrumentation/runtime"

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias otelruntime is used to avoid collision with the standard runtime package imported on line 17. However, consider using a more descriptive alias like otelruntimemetrics or otelruntimeinstrumentation to better clarify its purpose as an OpenTelemetry instrumentation package rather than just "runtime".

Copilot uses AI. Check for mistakes.
Comment on lines +419 to +421
slog.String("database.connection_status", "timeout"),
slog.String("database.last_successful_query", "unknown"),
slog.Int("database.active_connections", 0),

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These database-related log fields are misleading since the product catalog reads from JSON files (as seen in readProductFiles()), not a database. Either remove these database references or clearly prefix them with a namespace indicating they are simulated/mock values for the feature flag scenario.

Copilot uses AI. Check for mistakes.
slog.String("database.connection_status", "timeout"),
slog.String("database.last_successful_query", "unknown"),
slog.Int("database.active_connections", 0),
slog.String("error.stack_trace", "ProductCatalogService.GetProduct() -> DatabaseConnection.timeout"),

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stack trace references "DatabaseConnection.timeout" but the product catalog reads from JSON files, not a database. This creates a misleading error trail. Either remove the database reference or clearly indicate this is simulated for demonstration purposes.

Copilot uses AI. Check for mistakes.
Comment on lines +424 to +425
slog.Float64("database_timeout_duration_ms", float64(operationDuration.Nanoseconds())/1000000),
slog.String("performance.database_latency", "timeout"),

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These database timeout metrics are misleading since the product catalog reads from JSON files, not a database. The field names suggest database operations that don't actually exist in this service.

Copilot uses AI. Check for mistakes.
Comment thread src/payment/charge.js
hrTime: hrTime[0] * 1000000000 + hrTime[1] // nanoseconds since process start
},
performance: {
eventLoopDelay: Math.round(Math.random() * 10), // Simulated event loop delay in ms

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Math.random() to simulate event loop delay provides meaningless metrics. Consider using actual event loop monitoring libraries like perf_hooks.monitorEventLoopDelay() or remove this metric entirely if real measurement isn't feasible.

Copilot uses AI. Check for mistakes.
Comment thread src/payment/charge.js
tokenType: 'loyalty_access_token'
},
performance: {
duration: Math.floor(Math.random() * 500) + 100, // Simulate processing time

Copilot AI Dec 16, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Math.random() to simulate processing duration provides meaningless metrics that don't reflect actual performance. Either measure the actual operation duration or remove this field from the logs.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants