Skip to main content

Introduction

The Secure MCP Gateway provides enterprise-grade observability through a plugin-based telemetry system. The architecture supports structured logging, distributed tracing, and metrics collection to give you complete visibility into gateway operations, security events, and performance characteristics.

Telemetry Architecture

Plugin-Based System

The gateway uses a flexible plugin architecture for telemetry providers:

Key Components

1. Telemetry Provider Interface

All providers implement the base TelemetryProvider interface:
Location: src/secure_mcp_gateway/plugins/telemetry/base.py

2. Telemetry Config Manager

Centralized singleton that manages the telemetry lifecycle:
Location: src/secure_mcp_gateway/plugins/telemetry/config_manager.py

3. Lazy Logger Pattern

To avoid circular imports during initialization, the gateway uses a lazy logger:
Location: src/secure_mcp_gateway/utils.py:63-92

Configuration

Telemetry Config Structure

Telemetry is configured in enkrypt_mcp_config.json:

Configuration Options

string
default:"opentelemetry"
Telemetry provider to use. Available: opentelemetry, stdout
boolean
default:"true"
Enable or disable telemetry. When disabled, uses no-op logger/tracer.
string
default:"http://localhost:4317"
OTLP endpoint URL for the OpenTelemetry Collector (gRPC or HTTP)
boolean
default:"true"
Use insecure connection (no TLS). Set to false for production with TLS.
string
default:"secure-mcp-gateway"
Service name for resource attributes in telemetry data
string
default:"enkryptai"
Job name for metrics scraping and resource attributes
string
default:"INFO"
Log level: DEBUG, INFO, WARNING, ERROR, CRITICAL

Available Providers

OpenTelemetry Provider

Production-ready provider with full observability stack:
  • Structured Logging: JSON logs with context via structlog
  • Distributed Tracing: Context propagation across service boundaries
  • Metrics: Prometheus-compatible metrics export
  • Export: OTLP gRPC/HTTP to OpenTelemetry Collector
  • Integration: Works with Jaeger, Loki, Prometheus, Grafana
Configuration:
See OpenTelemetry Setup for detailed configuration.

Stdout Provider

Simple provider for debugging and development:
  • Logs to stdout
  • No tracing or metrics
  • Minimal overhead
Configuration:

Observability Features

1. Structured Logging

All logs include contextual information:
See Logging for log formats and aggregation.

2. Distributed Tracing

Traces span across gateway operations:
See OpenTelemetry Setup for trace configuration.

3. Metrics Collection

Comprehensive metrics for monitoring: Operation Metrics:
  • enkrypt_tool_calls_total - Total tool invocations
  • enkrypt_tool_call_duration_seconds - Tool execution latency (histogram)
  • enkrypt_tool_call_success_total - Successful tool calls
  • enkrypt_tool_call_failure_total - Failed tool calls
Cache Metrics:
  • enkrypt_cache_hits_total - Cache hits
  • enkrypt_cache_misses_total - Cache misses
Security Metrics:
  • enkrypt_guardrail_violations_total - Total guardrail violations
  • enkrypt_input_guardrail_violations_total - Input violations
  • enkrypt_output_guardrail_violations_total - Output violations
  • enkrypt_pii_redactions_total - PII redaction events
  • enkrypt_tool_call_blocked_total - Blocked tool calls
Authentication Metrics:
  • enkrypt_auth_success_total - Successful authentications
  • enkrypt_auth_failure_total - Failed authentications
  • enkrypt_active_sessions - Current active sessions (gauge)
  • enkrypt_active_users - Current active users (gauge)
See Metrics for complete list and dashboards.

Observability Stack Deployment

The gateway includes a complete observability stack via Docker Compose:
Services Started: Access Points:

Telemetry Lifecycle

1. Initialization

Telemetry is initialized during gateway startup:
Location: src/secure_mcp_gateway/gateway.py:796

2. Connectivity Check

Before enabling telemetry, the provider checks endpoint reachability:
Location: src/secure_mcp_gateway/plugins/telemetry/opentelemetry_provider.py:152

3. No-Op Fallback

If telemetry is disabled or unreachable, the provider uses no-op implementations:
This ensures the gateway runs normally even without telemetry infrastructure. Location: src/secure_mcp_gateway/plugins/telemetry/opentelemetry_provider.py:486

Best Practices

Always include contextual information in logs:
This enables powerful filtering and analysis in Loki/Grafana.
Add meaningful attributes to traces:
This makes traces searchable and provides context.
  • DEBUG: Detailed diagnostic information
  • INFO: General operational events
  • WARNING: Unexpected but handled situations
  • ERROR: Error conditions that need attention
  • CRITICAL: Severe errors requiring immediate action
Set up alerts for:
  • High error rates (tool_call_failure_total)
  • Slow operations (tool_call_duration_seconds)
  • Security events (guardrail_violations_total)
  • Resource usage (active_sessions, cache_misses_total)
Configure secure connections:

Performance Considerations

Minimal Overhead

The OpenTelemetry provider is designed for production:
  • Batch Processing: Logs, traces, and metrics are batched before export
  • Async Export: Telemetry export doesn’t block gateway operations
  • Configurable Buffer: 1s timeout, 1024 batch size (configurable)
  • Periodic Metrics: Metrics exported every 5 seconds

Resource Usage

Typical resource consumption:
  • CPU: < 5% overhead for telemetry operations
  • Memory: ~50-100MB for OpenTelemetry SDK and buffers
  • Network: Depends on log volume and metric cardinality

Optimization Tips

  1. Adjust Log Level: Use INFO or WARNING in production, DEBUG only when troubleshooting
  2. Sample Traces: For high-volume deployments, use trace sampling in the collector
  3. Metric Cardinality: Avoid high-cardinality labels (e.g., user IDs in metric labels)
  4. Buffer Tuning: Adjust batch size and timeout in collector config

Troubleshooting

Telemetry Not Working

Check connectivity:
Check logs:
Verify configuration:

Logs Not Appearing in Loki

  1. Check Loki is running: curl http://localhost:3100/ready
  2. Verify collector exports to Loki: Check exporters.otlphttp/loki in collector config
  3. Check Grafana datasource: Navigate to Grafana → Connections → Loki

Metrics Not in Prometheus

  1. Check Prometheus scrape config: http://localhost:9090/config
  2. Verify collector metrics endpoint: curl http://localhost:8889/metrics
  3. Check scrape targets: http://localhost:9090/targets

Traces Not in Jaeger

  1. Check Jaeger is running: curl http://localhost:16686
  2. Verify collector exports to Jaeger: Check exporters.otlp in collector config
  3. Check Jaeger receives data: Navigate to Jaeger UI → Search

Next Steps

OpenTelemetry Setup

Configure OTLP export, distributed tracing, and collector setup

Metrics

Explore Prometheus metrics, Grafana dashboards, and alerting

Logging

Learn about log formats, levels, and aggregation with Loki

API Reference

Explore the REST API for programmatic monitoring