Skip to content

Commit 57d19d1

Browse files
Merge pull request #39 from mapbox/otel_refresh
[otel] Update DevKit Server with OTEL implementation
2 parents bc810b4 + 159c293 commit 57d19d1

File tree

19 files changed

+6243
-201
lines changed

19 files changed

+6243
-201
lines changed

.env.example

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Mapbox MCP DevKit Server Configuration
2+
# Copy this file to .env and configure as needed
3+
4+
# =============================================================================
5+
# Required Configuration
6+
# =============================================================================
7+
8+
# Mapbox API Access Token (required)
9+
# Get your token at: https://account.mapbox.com/access-tokens
10+
MAPBOX_ACCESS_TOKEN=your-mapbox-token-here
11+
12+
# =============================================================================
13+
# Optional MCP Configuration
14+
# =============================================================================
15+
16+
# Disable console logging (recommended when using stdio transport)
17+
# Uncomment to enable:
18+
# MCP_DISABLE_LOGGING=true
19+
20+
# =============================================================================
21+
# OpenTelemetry Tracing (Optional)
22+
# =============================================================================
23+
24+
# Enable tracing by setting an OTLP endpoint
25+
# For local development with Jaeger:
26+
# 1. Start Jaeger: npm run tracing:jaeger:start
27+
# 2. Uncomment the line below
28+
# 3. View traces at: http://localhost:16686
29+
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
30+
31+
# Service identification
32+
OTEL_SERVICE_NAME=mapbox-mcp-devkit-server
33+
# OTEL_SERVICE_VERSION=0.4.5
34+
35+
# Resource attributes (customize as needed)
36+
OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5
37+
38+
# Optional: Console tracing for development (SSE transport only)
39+
# ⚠️ Do NOT enable with stdio transport - it breaks JSON-RPC communication
40+
# OTEL_EXPORTER_CONSOLE_ENABLED=true
41+
42+
# Optional: OTLP authentication headers (for production backends)
43+
# OTEL_EXPORTER_OTLP_HEADERS={"Authorization": "Bearer your-token"}
44+
45+
# Optional: Sampling (useful for high-volume production environments)
46+
# OTEL_TRACES_SAMPLER=traceidratio
47+
# OTEL_TRACES_SAMPLER_ARG=0.1
48+
49+
# =============================================================================
50+
# AWS X-Ray Configuration (Optional)
51+
# =============================================================================
52+
# Uncomment these settings if using AWS X-Ray instead of Jaeger
53+
54+
# AWS region (required for X-Ray)
55+
# AWS_REGION=us-east-1
56+
57+
# X-Ray specific resource attributes
58+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5,aws.region=us-east-1
59+
60+
# X-Ray trace headers (example format)
61+
# OTEL_EXPORTER_OTLP_HEADERS={"x-amzn-trace-id": "Root=1-5e2b3c4d-5f6a7b8c9d0e1f2a3b4c5d6e;Parent=7f8a9b0c1d2e3f4a;Sampled=1"}
62+
63+
# Note: AWS credentials should be configured separately via:
64+
# - IAM role (recommended for EC2/ECS/Lambda)
65+
# - AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
66+
# - AWS CLI profile (~/.aws/credentials)
67+
68+
# =============================================================================
69+
# Azure Monitor Configuration (Optional)
70+
# =============================================================================
71+
# Uncomment these settings if using Azure Monitor Application Insights
72+
73+
# Azure Monitor OTLP endpoint (replace with your ingestion endpoint)
74+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://<your-region>.livediagnostics.monitor.azure.com/v1/traces
75+
76+
# Azure Monitor authentication (use your connection string or AAD token)
77+
# OTEL_EXPORTER_OTLP_HEADERS={"x-ms-client-principal-id": "your-connection-string"}
78+
79+
# Azure-specific resource attributes
80+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5,cloud.provider=azure,cloud.region=eastus
81+
82+
# Note: Set up Azure Application Insights first
83+
# See: https://learn.microsoft.com/en-us/azure/azure-monitor/app/opentelemetry-enable
84+
85+
# =============================================================================
86+
# Google Cloud Trace Configuration (Optional)
87+
# =============================================================================
88+
# Uncomment these settings if using Google Cloud Trace
89+
90+
# GCP Trace OTLP endpoint
91+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://cloudtrace.googleapis.com/v2/projects/<project-id>/traces
92+
93+
# GCP-specific resource attributes
94+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5,cloud.provider=gcp,gcp.project.id=your-project-id
95+
96+
# Note: Ensure you have Application Default Credentials configured
97+
# gcloud auth application-default login
98+
# Or use a service account with Cloud Trace Agent role
99+
100+
# =============================================================================
101+
# Datadog Configuration (Optional)
102+
# =============================================================================
103+
# Uncomment these settings if using Datadog APM
104+
105+
# Datadog OTLP endpoint (use your Datadog site)
106+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://api.datadoghq.com/api/v2/traces
107+
108+
# Datadog API key authentication
109+
# OTEL_EXPORTER_OTLP_HEADERS={"dd-api-key": "your-datadog-api-key"}
110+
111+
# Datadog-specific resource attributes
112+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5,deployment.environment=production
113+
114+
# Note: Datadog also supports agent-based collection via localhost:4318
115+
# See: https://docs.datadoghq.com/tracing/trace_collection/opentelemetry/
116+
117+
# =============================================================================
118+
# New Relic Configuration (Optional)
119+
# =============================================================================
120+
# Uncomment these settings if using New Relic
121+
122+
# New Relic OTLP endpoint
123+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net:4318
124+
125+
# New Relic license key authentication
126+
# OTEL_EXPORTER_OTLP_HEADERS={"api-key": "your-new-relic-license-key"}
127+
128+
# New Relic-specific resource attributes
129+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5
130+
131+
# Note: Use your specific New Relic data center endpoint:
132+
# US: https://otlp.nr-data.net:4318
133+
# EU: https://otlp.eu01.nr-data.net:4318
134+
# See: https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/opentelemetry-setup/
135+
136+
# =============================================================================
137+
# Honeycomb Configuration (Optional)
138+
# =============================================================================
139+
# Uncomment these settings if using Honeycomb
140+
141+
# Honeycomb OTLP endpoint
142+
# OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io:443
143+
144+
# Honeycomb API key and dataset
145+
# OTEL_EXPORTER_OTLP_HEADERS={"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "mapbox-mcp-devkit-server"}
146+
147+
# Honeycomb-specific resource attributes
148+
# OTEL_RESOURCE_ATTRIBUTES=service.name=mapbox-mcp-devkit-server,service.version=0.4.5
149+
150+
# Note: Get your API key from: https://ui.honeycomb.io/account
151+
# See: https://docs.honeycomb.io/getting-data-in/opentelemetry-overview/
152+
153+
# =============================================================================
154+
# Custom API Endpoint (Optional)
155+
# =============================================================================
156+
# Override the default Mapbox API endpoint if needed
157+
# MAPBOX_API_ENDPOINT=https://api.mapbox.com/

CLAUDE.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,72 @@ This file provides Claude and developers with essential context, commands, and s
1717
- `npm run sync-manifest` — Sync version from package.json to manifest.json
1818
- `docker build -t mapbox-mcp-devkit .` — Build Docker image
1919
- `docker run mapbox/mcp-devkit-server ...` — Run server in Docker
20+
- `npm run tracing:jaeger:start` — Start Jaeger tracing backend (requires Docker)
21+
- `npm run tracing:jaeger:stop` — Stop Jaeger tracing backend
22+
- `npm run tracing:verify` — Show instructions for verifying tracing setup
23+
24+
## Observability & Tracing
25+
26+
This server includes OpenTelemetry (OTEL) instrumentation for distributed tracing. Tracing is **opt-in** and disabled by default.
27+
28+
### Quick Start with Jaeger
29+
30+
1. Start Jaeger backend (requires Docker):
31+
32+
```bash
33+
npm run tracing:jaeger:start
34+
```
35+
36+
2. Configure environment variables in `.env`:
37+
38+
```bash
39+
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
40+
OTEL_SERVICE_NAME=mapbox-mcp-devkit-server
41+
```
42+
43+
3. Run the server:
44+
45+
```bash
46+
npm run inspect:build
47+
```
48+
49+
4. View traces at http://localhost:16686
50+
51+
5. Stop Jaeger when done:
52+
```bash
53+
npm run tracing:jaeger:stop
54+
```
55+
56+
### Environment Variables
57+
58+
- `OTEL_EXPORTER_OTLP_ENDPOINT` — OTLP endpoint URL (e.g., `http://localhost:4318`). If not set, tracing is disabled.
59+
- `OTEL_EXPORTER_CONSOLE_ENABLED` — Set to `true` to log traces to console (avoid with stdio transport)
60+
- `OTEL_TRACING_ENABLED` — Set to `false` to explicitly disable tracing even if endpoint is configured
61+
- `OTEL_SERVICE_NAME` — Override service name (default: `mapbox-mcp-devkit-server`)
62+
- `OTEL_EXPORTER_OTLP_HEADERS` — JSON string of additional headers for OTLP exporter
63+
64+
### What Gets Traced
65+
66+
- Tool execution spans with timing and status
67+
- HTTP requests to Mapbox APIs (automatic instrumentation)
68+
- Configuration loading and initialization
69+
- Error details and stack traces
70+
71+
### Trace Attributes
72+
73+
Each tool execution span includes:
74+
75+
- `tool.name` — Tool identifier
76+
- `tool.input.size` — Input payload size
77+
- `operation.type` — Type of operation (e.g., `tool_execution`)
78+
- `session.id`, `user.id`, `account.id` — Context from MCP extra fields (if provided)
79+
80+
### Production Considerations
81+
82+
- Tracing has minimal overhead when enabled
83+
- Recommended for debugging complex tool chains and performance issues
84+
- Can be used with any OTLP-compatible backend (Jaeger, Honeycomb, DataDog, etc.)
85+
- For hosted endpoints, configure appropriate sampling rates
2086

2187
## Core Files & Structure
2288

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ https://github.com/user-attachments/assets/8b1b8ef2-9fba-4951-bc9a-beaed4f6aff6
2727
- [Coordinate Conversion tool](#coordinate-conversion-tool)
2828
- [Bounding Box tool](#bounding-box-tool)
2929
- [Resources](#resources)
30+
- [Observability & Tracing](#observability--tracing)
3031
- [Development](#development)
3132
- [Testing](#testing)
3233
- [Tool Snapshot Tests](#tool-snapshot-tests)
@@ -481,6 +482,66 @@ This server exposes static reference documentation as MCP Resources. While these
481482

482483
**Note:** Resources provide static reference data that doesn't change frequently, while tools provide dynamic, user-specific data (like listing your styles or tokens) and perform actions (like creating styles or tokens).
483484

485+
## Observability & Tracing
486+
487+
This server includes comprehensive distributed tracing using OpenTelemetry (OTEL) for production-ready observability.
488+
489+
### Features
490+
491+
- **Opt-in Configuration**: Tracing is disabled by default, enabling it requires only setting an OTLP endpoint
492+
- **Tool Execution Tracing**: Automatic instrumentation of all tool executions with timing, success/failure status, and error details
493+
- **HTTP Request Instrumentation**: Complete request/response tracing for Mapbox API calls with CloudFront correlation IDs
494+
- **Configuration Tracing**: Startup configuration loading with error tracking
495+
- **Security**: Input/output sizes logged but content is protected
496+
- **Low Overhead**: <1% CPU impact, ~10MB memory for trace buffers
497+
498+
### Quick Start with Jaeger
499+
500+
```bash
501+
# 1. Start Jaeger (Docker required)
502+
npm run tracing:jaeger:start
503+
504+
# 2. Configure environment
505+
cp .env.example .env
506+
# Edit .env to add MAPBOX_ACCESS_TOKEN
507+
# OTEL_EXPORTER_OTLP_ENDPOINT is already set to http://localhost:4318
508+
509+
# 3. Run the server
510+
npm run inspect:build
511+
512+
# 4. View traces at http://localhost:16686
513+
514+
# 5. Stop Jaeger when done
515+
npm run tracing:jaeger:stop
516+
```
517+
518+
### Supported Backends
519+
520+
The server supports **any OTLP-compatible backend** including:
521+
522+
- **Development**: Jaeger (local Docker)
523+
- **Cloud Providers**: AWS X-Ray, Azure Monitor, Google Cloud Trace
524+
- **SaaS Platforms**: Datadog, New Relic, Honeycomb
525+
526+
See `.env.example` for configuration examples for each platform.
527+
528+
### Documentation
529+
530+
- **[Complete Tracing Guide](./docs/tracing.md)** - Detailed configuration, features, and integration examples
531+
- **[Verification Guide](./docs/tracing-verification.md)** - Step-by-step verification and troubleshooting
532+
533+
### Environment Variables
534+
535+
```bash
536+
# Enable tracing (required)
537+
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
538+
539+
# Optional configuration
540+
OTEL_SERVICE_NAME=mapbox-mcp-devkit-server
541+
OTEL_TRACES_SAMPLER=traceidratio
542+
OTEL_TRACES_SAMPLER_ARG=0.1 # Sample 10% for high-volume
543+
```
544+
484545
## Development
485546

486547
### Testing

0 commit comments

Comments
 (0)