Skip to content

Commit 0b0a2e0

Browse files
authored
Vendor Agnostic OpenTelemetry Observability Support #735 and #727 phoenix (#733)
* Phoenix poc Signed-off-by: Mihai Criveti <[email protected]> * Phoenix PoC Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * Observability Signed-off-by: Mihai Criveti <[email protected]> * README Signed-off-by: Mihai Criveti <[email protected]> * Simplify docs Signed-off-by: Mihai Criveti <[email protected]> * Simplify tests Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Mihai Criveti <[email protected]>
1 parent 7cac6f8 commit 0b0a2e0

25 files changed

+2176
-677
lines changed

.env.example

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,45 @@ VALID_SLUG_SEPARATOR_REGEXP= r"^(-{1,2}|[_.])$"
347347
# Plugins Settings
348348
#####################################
349349
PLUGINS_ENABLED=false
350+
351+
#####################################
352+
# Observability (OpenTelemetry)
353+
#####################################
354+
355+
# Master switch for observability (true/false)
356+
OTEL_ENABLE_OBSERVABILITY=true
357+
358+
# Service identification
359+
OTEL_SERVICE_NAME=mcp-gateway
360+
OTEL_SERVICE_VERSION=0.5.0
361+
OTEL_DEPLOYMENT_ENVIRONMENT=development
362+
363+
# Exporter type: otlp, jaeger, zipkin, console, none
364+
OTEL_TRACES_EXPORTER=otlp
365+
366+
# OTLP Configuration (for Phoenix, Tempo, DataDog, etc.)
367+
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
368+
OTEL_EXPORTER_OTLP_PROTOCOL=grpc
369+
# Headers for authentication (format: key=value,key2=value2)
370+
#OTEL_EXPORTER_OTLP_HEADERS=api-key=secret
371+
OTEL_EXPORTER_OTLP_INSECURE=true
372+
373+
# Jaeger Configuration (alternative to OTLP)
374+
#OTEL_EXPORTER_JAEGER_ENDPOINT=http://localhost:14268/api/traces
375+
#OTEL_EXPORTER_JAEGER_USER=
376+
#OTEL_EXPORTER_JAEGER_PASSWORD=
377+
378+
# Zipkin Configuration (alternative to OTLP)
379+
#OTEL_EXPORTER_ZIPKIN_ENDPOINT=http://localhost:9411/api/v2/spans
380+
381+
# Sampling Configuration
382+
OTEL_TRACES_SAMPLER=parentbased_traceidratio
383+
OTEL_TRACES_SAMPLER_ARG=0.1
384+
385+
# Resource Attributes (comma-separated key=value pairs)
386+
#OTEL_RESOURCE_ATTRIBUTES=tenant.id=acme,region=us-east-1
387+
388+
# Performance Tuning
389+
OTEL_BSP_MAX_QUEUE_SIZE=2048
390+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE=512
391+
OTEL_BSP_SCHEDULE_DELAY=5000

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ make doctest test htmlcov smoketest lint-web flake8 bandit interrogate pylint ve
234234

235235
# Rules
236236
- When using git commit always add a -s to sign commits
237+
- Don't include effor estimates, or 'phases'
237238

238239
# TO test individual files, ensure you're activated the env first, ex:
239240
. /home/cmihai/.venv/mcpgateway/bin/activate && pytest --cov-report=annotate tests/unit/mcpgateway/test_translate.py

Containerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ WORKDIR /app
2121
COPY . /app
2222

2323
# Create virtual environment, upgrade pip and install dependencies using uv for speed
24+
# Including observability packages for OpenTelemetry support
2425
RUN python3 -m venv /app/.venv && \
2526
/app/.venv/bin/python3 -m pip install --upgrade pip setuptools pdm uv && \
26-
/app/.venv/bin/python3 -m uv pip install ".[redis,postgres,alembic]"
27+
/app/.venv/bin/python3 -m uv pip install ".[redis,postgres,alembic,observability]"
2728

2829
# update the user permissions
2930
RUN chown -R 1001:0 /app && \

Containerfile.lite

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ COPY pyproject.toml /app/
6161
# Create and populate virtual environment
6262
# - Upgrade pip, setuptools, wheel, pdm, uv
6363
# - Install project dependencies and package
64+
# - Include observability packages for OpenTelemetry support
6465
# - Remove build tools but keep runtime dist-info
6566
# - Remove build caches and build artifacts
6667
# ----------------------------------------------------------------------------
6768
RUN set -euo pipefail \
6869
&& python3 -m venv /app/.venv \
6970
&& /app/.venv/bin/pip install --no-cache-dir --upgrade pip setuptools wheel pdm uv \
70-
&& /app/.venv/bin/uv pip install ".[redis,postgres]" \
71+
&& /app/.venv/bin/uv pip install ".[redis,postgres,observability]" \
7172
&& /app/.venv/bin/pip uninstall --yes uv pip setuptools wheel pdm \
7273
&& rm -rf /root/.cache /var/cache/dnf \
7374
&& find /app/.venv -name "*.dist-info" -type d \

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ It currently supports:
128128
* Virtualization of legacy APIs as MCP-compliant tools and servers
129129
* Transport over HTTP, JSON-RPC, WebSocket, SSE (with configurable keepalive), stdio and streamable-HTTP
130130
* An Admin UI for real-time management and configuration
131-
* Built-in auth, observability, retries, and rate-limiting
131+
* Built-in auth, retries, and rate-limiting
132+
* **OpenTelemetry observability** with Phoenix, Jaeger, Zipkin, and other OTLP backends
132133
* Scalable deployments via Docker or PyPI, Redis-backed caching, and multi-cluster federation
133134

134135
![MCP Gateway Architecture](https://ibm.github.io/mcp-context-forge/images/mcpgateway.svg)
@@ -195,6 +196,35 @@ For a list of upcoming features, check out the [ContextForge MCP Gateway Roadmap
195196

196197
</details>
197198

199+
<details>
200+
<summary><strong>🔍 OpenTelemetry Observability</strong></summary>
201+
202+
* **Vendor-agnostic tracing** with OpenTelemetry (OTLP) protocol support
203+
* **Multiple backend support**: Phoenix (LLM-focused), Jaeger, Zipkin, Tempo, DataDog, New Relic
204+
* **Distributed tracing** across federated gateways and services
205+
* **Automatic instrumentation** of tools, prompts, resources, and gateway operations
206+
* **LLM-specific metrics**: Token usage, costs, model performance
207+
* **Zero-overhead when disabled** with graceful degradation
208+
* **Easy configuration** via environment variables
209+
210+
Quick start with Phoenix (LLM observability):
211+
```bash
212+
# Start Phoenix
213+
docker run -p 6006:6006 -p 4317:4317 arizephoenix/phoenix:latest
214+
215+
# Configure gateway
216+
export OTEL_ENABLE_OBSERVABILITY=true
217+
export OTEL_TRACES_EXPORTER=otlp
218+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
219+
220+
# Run gateway - traces automatically sent to Phoenix
221+
mcpgateway
222+
```
223+
224+
See [Observability Documentation](https://ibm.github.io/mcp-context-forge/manage/observability/) for detailed setup with other backends.
225+
226+
</details>
227+
198228
---
199229

200230
## Quick Start - PyPI
@@ -1083,6 +1113,65 @@ LOG_FILE=gateway.log
10831113
- File logging is **disabled by default** (no files created)
10841114
- Set `LOG_TO_FILE=true` to enable optional file logging with JSON format
10851115

1116+
### Observability (OpenTelemetry)
1117+
1118+
MCP Gateway includes **vendor-agnostic OpenTelemetry support** for distributed tracing. Works with Phoenix, Jaeger, Zipkin, Tempo, DataDog, New Relic, and any OTLP-compatible backend.
1119+
1120+
| Setting | Description | Default | Options |
1121+
| ------------------------------- | ---------------------------------------------- | --------------------- | ------------------------------------------ |
1122+
| `OTEL_ENABLE_OBSERVABILITY` | Master switch for observability | `true` | `true`, `false` |
1123+
| `OTEL_SERVICE_NAME` | Service identifier in traces | `mcp-gateway` | string |
1124+
| `OTEL_SERVICE_VERSION` | Service version in traces | `0.5.0` | string |
1125+
| `OTEL_DEPLOYMENT_ENVIRONMENT` | Environment tag (dev/staging/prod) | `development` | string |
1126+
| `OTEL_TRACES_EXPORTER` | Trace exporter backend | `otlp` | `otlp`, `jaeger`, `zipkin`, `console`, `none` |
1127+
| `OTEL_RESOURCE_ATTRIBUTES` | Custom resource attributes | (empty) | `key=value,key2=value2` |
1128+
1129+
**OTLP Configuration** (for Phoenix, Tempo, DataDog, etc.):
1130+
1131+
| Setting | Description | Default | Options |
1132+
| ------------------------------- | ---------------------------------------------- | --------------------- | ------------------------------------------ |
1133+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint | (none) | `http://localhost:4317` |
1134+
| `OTEL_EXPORTER_OTLP_PROTOCOL` | OTLP protocol | `grpc` | `grpc`, `http/protobuf` |
1135+
| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers | (empty) | `api-key=secret,x-auth=token` |
1136+
| `OTEL_EXPORTER_OTLP_INSECURE` | Skip TLS verification | `true` | `true`, `false` |
1137+
1138+
**Alternative Backends** (optional):
1139+
1140+
| Setting | Description | Default | Options |
1141+
| ------------------------------- | ---------------------------------------------- | --------------------- | ------------------------------------------ |
1142+
| `OTEL_EXPORTER_JAEGER_ENDPOINT` | Jaeger collector endpoint | `http://localhost:14268/api/traces` | URL |
1143+
| `OTEL_EXPORTER_ZIPKIN_ENDPOINT` | Zipkin collector endpoint | `http://localhost:9411/api/v2/spans` | URL |
1144+
1145+
**Performance Tuning**:
1146+
1147+
| Setting | Description | Default | Options |
1148+
| ------------------------------- | ---------------------------------------------- | --------------------- | ------------------------------------------ |
1149+
| `OTEL_TRACES_SAMPLER` | Sampling strategy | `parentbased_traceidratio` | `always_on`, `always_off`, `traceidratio` |
1150+
| `OTEL_TRACES_SAMPLER_ARG` | Sample rate (0.0-1.0) | `0.1` | float (0.1 = 10% sampling) |
1151+
| `OTEL_BSP_MAX_QUEUE_SIZE` | Max queued spans | `2048` | int > 0 |
1152+
| `OTEL_BSP_MAX_EXPORT_BATCH_SIZE`| Max batch size for export | `512` | int > 0 |
1153+
| `OTEL_BSP_SCHEDULE_DELAY` | Export interval (ms) | `5000` | int > 0 |
1154+
1155+
**Quick Start with Phoenix**:
1156+
```bash
1157+
# Start Phoenix for LLM observability
1158+
docker run -p 6006:6006 -p 4317:4317 arizephoenix/phoenix:latest
1159+
1160+
# Configure gateway
1161+
export OTEL_ENABLE_OBSERVABILITY=true
1162+
export OTEL_TRACES_EXPORTER=otlp
1163+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
1164+
1165+
# Run gateway - traces automatically sent to Phoenix
1166+
mcpgateway
1167+
```
1168+
1169+
> 🔍 **What Gets Traced**: Tool invocations, prompt rendering, resource fetching, gateway federation, health checks, plugin execution (if enabled)
1170+
>
1171+
> 🚀 **Zero Overhead**: When `OTEL_ENABLE_OBSERVABILITY=false`, all tracing is disabled with no performance impact
1172+
>
1173+
> 📊 **View Traces**: Phoenix UI at `http://localhost:6006`, Jaeger at `http://localhost:16686`, or your configured backend
1174+
10861175
### Transport
10871176

10881177
| Setting | Description | Default | Options |

docker-compose.phoenix-simple.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Simplified Phoenix Observability Stack for MCP Gateway
2-
#
2+
#
33
# Usage:
44
# Start Phoenix: docker-compose -f docker-compose.phoenix-simple.yml up -d
55
# Stop Phoenix: docker-compose -f docker-compose.phoenix-simple.yml down
@@ -34,4 +34,4 @@ services:
3434

3535
volumes:
3636
phoenix-data:
37-
driver: local
37+
driver: local

docker-compose.with-phoenix.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ services:
4444

4545
volumes:
4646
phoenix-data:
47-
driver: local
47+
driver: local

docs/docs/architecture/security-features.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,33 +253,33 @@ MCP Gateway implements a comprehensive, multi-layered security approach with "de
253253

254254
### 🚀 Upcoming Security Enhancements
255255

256-
**Release 0.5.0 (August 2025)**
256+
**Release 0.5.0 - August 2025**
257257
- Enhanced authentication mechanisms
258258
- Configuration validation framework
259259
- Comprehensive audit logging
260260
- Security headers implementation
261261

262-
**Release 0.6.0 (August 2025)**
262+
**Release 0.6.0 - August 2025**
263263
- Database-backed authentication
264264
- Multi-layer caching security
265265
- Circuit breakers implementation
266266

267-
**Release 0.7.0 (September 2025)**
267+
**Release 0.7.0 - September 2025**
268268
- Full RBAC implementation
269269
- Multi-tenancy support
270270
- Correlation ID tracking
271271

272-
**Release 0.8.0 (September 2025)**
272+
**Release 0.8.0 - September 2025**
273273
- Policy-as-Code engine
274274
- Advanced guardrails
275275
- DDoS protection
276276

277-
**Release 0.9.0 (September 2025)**
277+
**Release 0.9.0 - September 2025**
278278
- Marketplace security
279279
- Protocol negotiation
280280
- Advanced connectivity
281281

282-
**Release 1.0.0 (October 2025)**
282+
**Release 1.0.0 - October 2025**
283283
- Security audit completion
284284
- Production hardening
285285
- GA security certification

docs/docs/manage/observability.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Observability
2+
3+
MCP Gateway includes production-grade OpenTelemetry instrumentation for distributed tracing, enabling you to monitor performance, debug issues, and understand request flows.
4+
5+
## Documentation
6+
7+
- **[Observability Overview](observability/observability.md)** - Complete guide to configuring and using observability
8+
- **[Phoenix Integration](observability/phoenix.md)** - AI/LLM-focused observability with Arize Phoenix
9+
10+
## Quick Start
11+
12+
```bash
13+
# Enable observability (enabled by default)
14+
export OTEL_ENABLE_OBSERVABILITY=true
15+
export OTEL_TRACES_EXPORTER=otlp
16+
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
17+
18+
# Start Phoenix for AI/LLM observability
19+
docker run -p 6006:6006 -p 4317:4317 arizephoenix/phoenix:latest
20+
21+
# Run MCP Gateway
22+
mcpgateway
23+
```
24+
25+
View traces at http://localhost:6006

docs/docs/manage/observability/.pages

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
nav:
2-
- Phoenix: phoenix-deployment.md
2+
- Overview: observability.md
3+
- Phoenix Integration: phoenix.md

0 commit comments

Comments
 (0)