This document describes the Winston logging and OpenTelemetry instrumentation implementation for the New Relic MCP server test suite only. This logging and telemetry is not included in the production MCP server code.
- Structured logging with JSON format
- New Relic-compatible log format
- Environment-specific configurations (test, development, production)
- File and console transports
- Child logger support for component-specific logging
- Helper functions for structured logging (logRequest, logResponse, logError, logMetric)
- WASM SIMD-accelerated tracing
- Resource detection with service metadata
- OTLP trace exporter configuration
- Winston instrumentation integration
- Helper functions for tool execution tracing
- Span attribute and event management
- Test tracer for unit testing
- Custom Winston transport for New Relic Logs API
- Automatic log forwarding to New Relic
- APM integration when agent is available
- Trace context correlation
- Batch processing with configurable intervals
- Regional endpoint support (US/EU)
- Log capture fixture for testing
- Span capture fixture for telemetry testing
- Custom test runner with integrated logging
- Helper utilities for async testing
- Automatic test instrumentation
- Performance measurement per test
- Test execution logging
- OpenTelemetry span creation for tests
- Error tracking and reporting
- Log entry verification helpers
- Span attribute verification
- Trace context validation
- Performance metrics validation
- New Relic attribute verification
The logging and telemetry is integrated into the test suite for:
- Test execution monitoring
- Performance measurement of test runs
- Debugging test failures
- Tracking test coverage and execution patterns
Note: Production tools (NRQL, APM, etc.) do not include any logging or telemetry.
import { logger, createChildLogger } from '../utils/logging/winston-logger';
// Create component-specific logger
const componentLogger = createChildLogger(logger, 'MyComponent');
// Log with structured data
componentLogger.info('Operation completed', {
duration: 125,
resultCount: 10,
metadata: { key: 'value' }
});import { withToolSpan, addSpanAttributes } from '../utils/instrumentation/otel-setup';
// In test files, use the fixtures for tracing
test('should execute with tracing', async ({ withSpan }) => {
await withSpan('test.operation', async () => {
// Test code here
const result = await someOperation();
expect(result).toBeDefined();
});
});import { test } from '../fixtures/logging.fixture';
test('should log operations', async ({ logger, logCapture, withSpan }) => {
await withSpan('test.operation', async () => {
// Perform operation
await someOperation();
});
// Verify logs
expect(logCapture.hasLog('info', 'Operation completed')).toBe(true);
// Verify performance metrics
const logs = logCapture.findByMessage('completed');
expect(logs[0].metadata?.duration).toBeDefined();
});LOG_LEVEL: Set log level (debug, info, warn, error)NODE_ENV: Environment (test, development, production)SUPPRESS_LOGS: Suppress console logs when true
OTEL_ENABLED: Enable OpenTelemetry instrumentationOTEL_SERVICE_NAME: Service name for tracesOTEL_EXPORTER_OTLP_ENDPOINT: OTLP exporter endpointOTEL_EXPORTER_OTLP_HEADERS: OTLP exporter headers (JSON)
NEW_RELIC_ENABLED: Enable New Relic integrationNEW_RELIC_LICENSE_KEY: New Relic license keyNEW_RELIC_API_KEY: New Relic API keyNEW_RELIC_ACCOUNT_ID: New Relic account IDNEW_RELIC_REGION: Region (US or EU)NEW_RELIC_APP_NAME: Application nameNEW_RELIC_ENTITY_GUID: Entity GUID for correlation
Run tests with logging enabled:
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run integration tests only
npm test test/integration/logging-telemetry.test.tsThe logging and telemetry implementation has minimal performance impact:
- Async log processing doesn't block main execution
- Batch processing reduces network overhead
- Conditional logging based on environment
- Efficient span creation with resource pooling
- Test environment optimizations
-
Production Configuration
- Configure OTLP endpoint for production
- Set up New Relic APM agent
- Configure log retention policies
-
Monitoring Dashboard
- Create New Relic dashboards for metrics
- Set up alerts for errors and performance
- Configure distributed tracing views
-
Additional Instrumentation
- Add custom metrics for business logic
- Implement request/response logging middleware
- Add database query instrumentation
-
Performance Optimization
- Implement log sampling for high-volume operations
- Configure span sampling rates
- Optimize batch sizes for log forwarding
- Check
NEW_RELIC_ENABLEDis set totrue - Verify
NEW_RELIC_LICENSE_KEYis valid - Check network connectivity to New Relic endpoints
- Review batch size and flush interval settings
- Verify
OTEL_ENABLEDis set totrue - Check
OTEL_EXPORTER_OTLP_ENDPOINTis correct - Review authentication headers if required
- Check for network/firewall issues
- Reduce log buffer size
- Decrease batch processing interval
- Implement log rotation for file transports
- Configure appropriate log levels
The logging and telemetry implementation provides comprehensive observability for the New Relic MCP server. With structured logging, distributed tracing, and New Relic integration, the system is well-equipped for production monitoring and debugging.