otelcontext

command module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: MIT Imports: 61 Imported by: 0

README

OtelContext

OtelContext

Turn traces, logs, and metrics into one clear view of your services.

Self-hosted OpenTelemetry collection, incident triage, and service mapping in one Go binary.

Latest release CI status Security status MIT license

Traces, logs, and metrics flowing through OtelContext into a connected service map

OtelContext helps you answer the question that starts most incidents: what is broken, and what does it affect? Send it standard OpenTelemetry data and it connects service relationships, errors, latency, logs, and traces in a map built for investigation.

It starts with SQLite and no external services. When you need more, the main telemetry database can use PostgreSQL, MySQL, or SQL Server.

[!IMPORTANT] OtelContext is pre-1.0. Read the changelog before upgrading.

What you get

  • A live service map that shows dependencies, health, latency, and active anomalies.
  • Incident context in one place with related traces, logs, metrics, and impact analysis.
  • Seven MCP tools for investigating your system from an AI client or coding agent.
  • Standard OTLP input over gRPC and HTTP, so existing SDKs and Collectors can send data directly.
  • A simple first run with one binary and a local SQLite database.
  • Self-hosted data with retention controls, health probes, and Prometheus metrics.

Quick start

1. Install a release

Download the archive for your platform from GitHub Releases, or install the latest release with Go:

go install github.com/RandomCodeSpace/otelcontext@latest

2. Start OtelContext

otelcontext

That is enough for a local trial. OtelContext creates OtelContext.db, listens for OTLP gRPC on 4317, and serves the UI and HTTP endpoints on 8080.

Open http://localhost:8080.

Authentication is off by default so the browser UI works immediately. Keep this first run on your machine. Before exposing it to a network, follow Secure a deployment.

3. Send telemetry

Point an OpenTelemetry SDK or Collector at either endpoint:

Protocol Endpoint
OTLP gRPC localhost:4317
OTLP HTTP http://localhost:8080/v1/traces, /v1/logs, or /v1/metrics

To confirm the connection without setting up an application, send one sample error log:

curl -fsS http://localhost:8080/v1/logs \
  -H "Content-Type: application/json" \
  -d "{
    \"resourceLogs\": [{
      \"resource\": {\"attributes\": [{
        \"key\": \"service.name\",
        \"value\": {\"stringValue\": \"readme-demo\"}
      }]},
      \"scopeLogs\": [{\"logRecords\": [{
        \"timeUnixNano\": \"$(date +%s)000000000\",
        \"severityNumber\": 17,
        \"severityText\": \"ERROR\",
        \"body\": {\"stringValue\": \"OtelContext is receiving data\"}
      }]}]
    }]
  }"

ERROR is used because the default storage threshold keeps WARN and ERROR logs.

OpenTelemetry Collector example

Save this as part of your Collector configuration. Replace otelcontext with the host or service name running OtelContext.

receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318

processors:
  batch: {}

exporters:
  otlp/otelcontext:
    endpoint: otelcontext:4317
    tls:
      insecure: true

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/otelcontext]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/otelcontext]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/otelcontext]

For an authenticated deployment, add an authorization bearer header and, if needed, x-tenant-id under the exporter.

Investigate with MCP

Connect an MCP client to http://localhost:8080/mcp to investigate the same telemetry from an agent. The tools can:

  • Build an anomaly timeline.
  • Show the service map and service health.
  • Analyze likely root causes and downstream impact.
  • Reconstruct a trace graph.
  • Search logs with bounded results.

Trace-based answers say whether the supporting exemplar is complete, partial, or no longer retained. OtelContext does not present a partial trace as the whole story.

Upgrade without guessing

The same binary can check and upgrade its database before it starts any receiver or background work:

./otelcontext migrate status
./otelcontext migrate up

If the database came from an older release that predates migration tracking, identify it once before upgrading:

./otelcontext migrate baseline --from v0.3.1
# or: --from v0.4.0-beta.2
./otelcontext migrate up

The baseline command validates the database first; it does not repair or guess. Create a complete OtelContext backup before upgrading, and keep the previous signed binary until migrate status reports result=ready. Versioned production checks are available for SQLite and unpartitioned PostgreSQL 16. MySQL, SQL Server, and PostgreSQL daily partitioning keep their existing preview AutoMigrate path.

For a one-host Linux deployment, use the shipped systemd unit and environment example and follow the install, upgrade, and rollback runbook. Direct execution remains supported for local use.

Back up and restore

After stopping OtelContext cleanly, use the same binary and environment as the service:

otelcontext backup create --out /absolute/path/to/backups

The published bundle keeps the main database, any mode-required aggregate database, the dead-letter queue, generated TLS identity, and a hashed manifest together. Restore into new database and sidecar paths; the command will not overwrite the source or an existing target:

otelcontext backup restore --bundle /absolute/path/to/backups/otelcontext-backup-...

Restore starts the same candidate briefly, waits for /ready, and shuts it down again. Keep the old binary, configuration, data, and bundle until the restored deployment passes your checks. The backup and restore runbook covers database-specific tools, fresh-target setup, validation, and rollback.

Secure a deployment

With no authentication or TLS settings configured, production mode starts without either:

APP_ENV=production ./otelcontext

Authentication is optional. Enable it when the deployment boundary requires a credential:

  • API_KEY for a shared operator credential.
  • AUTH_TRUST_EXTERNAL=true when a trusted reverse proxy owns authentication and tenant identity.

Authenticated example:

export API_KEY="$(openssl rand -hex 32)"
./otelcontext

Clients then send Authorization: Bearer <key>. Authentication and TLS are independently optional at runtime; configure each one when the deployment boundary requires it.

The browser UI does not currently store an API key. For an authenticated browser deployment, put OtelContext behind a same-origin proxy that authenticates the user and injects the credential for REST, MCP, and WebSocket traffic.

See the operations guide for database, TLS, retention, proxy, and health-check setup.

Common configuration

OtelContext reads environment variables and an optional .env file in its working directory.

Setting Default Use it for
HTTP_PORT 8080 UI, REST, OTLP HTTP, MCP, WebSockets, and probes
GRPC_PORT 4317 OTLP gRPC
DB_DRIVER sqlite sqlite, postgres, mysql, or sqlserver
DB_DSN OtelContext.db Database connection string
API_KEY empty Shared bearer authentication
DEFAULT_TENANT default Scope used when no trusted tenant is supplied
HOT_RETENTION_DAYS 7 Main retention horizon
STORE_MIN_SEVERITY WARN Lowest log severity stored in the main database
AGGREGATE_MODE legacy legacy, aggregate-shadow, or aggregate

Start with .env.example. The default legacy mode is the right choice for a first run. Aggregate modes are for measured high-volume deployments; review the aggregate gate report before enabling them.

Build from source

Use the Go version in go.mod:

git clone https://github.com/RandomCodeSpace/otelcontext.git
cd otelcontext

CGO_ENABLED=0 go build -o otelcontext .

The client-rendered UI is committed as plain HTML, CSS, and JavaScript and is embedded automatically. There is no Node.js install or frontend build step.

Run the core checks with:

go build ./...
go vet ./...
go test -race -timeout 180s ./...

License

OtelContext is available under the MIT License.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
aggregate
Package aggregate implements the aggregate-first accounting engine: every accepted telemetry point is reduced into a small number of series deltas before sampling, so aggregate counts describe traffic rather than the sampling rate.
Package aggregate implements the aggregate-first accounting engine: every accepted telemetry point is reduced into a small number of series deltas before sampling, so aggregate counts describe traffic rather than the sampling rate.
ai
api
api/views
Package views provides explicit JSON view models for the HTTP API.
Package views provides explicit JSON view models for the HTTP API.
authn
Package authn holds the transport-independent authentication primitives shared by the HTTP, WebSocket, and gRPC surfaces: the tenant key store and the authenticated principal that travels on a request context.
Package authn holds the transport-independent authentication primitives shared by the HTTP, WebSocket, and gRPC surfaces: the tenant key store and the authenticated principal that travels on a request context.
backup
Package backup owns OtelContext's offline, manifest-bound backup bundle.
Package backup owns OtelContext's offline, manifest-bound backup bundle.
graph
Package graph provides an in-memory service dependency graph rebuilt periodically from recent span data.
Package graph provides an in-memory service dependency graph rebuilt periodically from recent span data.
graphrag
Package graphrag provides a layered in-memory graph for real-time observability retrieval — error chains, root cause analysis, impact analysis.
Package graphrag provides a layered in-memory graph for real-time observability retrieval — error chains, root cause analysis, impact analysis.
httpconst
Package httpconst centralises HTTP header names and content-type strings shared by the API, MCP, and OTLP-HTTP handlers so the same literal isn't duplicated across packages.
Package httpconst centralises HTTP header names and content-type strings shared by the API, MCP, and OTLP-HTTP handlers so the same literal isn't duplicated across packages.
latency
Package latency defines the shared provenance vocabulary for percentile values.
Package latency defines the shared provenance vocabulary for percentile values.
mcp
Package mcp implements the HTTP Streamable MCP (Model Context Protocol) server over JSON-RPC 2.0 with SSE streaming, allowing any AI agent (Claude, GPT, Cursor, etc.) to discover and call OtelContext tools natively.
Package mcp implements the HTTP Streamable MCP (Model Context Protocol) server over JSON-RPC 2.0 with SSE streaming, allowing any AI agent (Claude, GPT, Cursor, etc.) to discover and call OtelContext tools natively.
membudget
Package membudget detects the memory budget available to the process — (in order) cgroup v2, cgroup v1, then host RAM from /proc/meminfo — so consumers can scale their allocations against the actual quota instead of hardcoding sizes.
Package membudget detects the memory budget available to the process — (in order) cgroup v2, cgroup v1, then host RAM from /proc/meminfo — so consumers can scale their allocations against the actual quota instead of hardcoding sizes.
migrate
Package migrate owns OtelContext's ordered main-database schema contract.
Package migrate owns OtelContext's ordered main-database schema contract.
tls
Package tlsbootstrap provides zero-friction self-signed certificate generation for development and internal deployments.
Package tlsbootstrap provides zero-friction self-signed certificate generation for development and internal deployments.
topology
Package topology owns the mode-selected service-topology read contract.
Package topology owns the mode-selected service-topology read contract.
tsdb
Package tsdb provides an in-memory ring buffer for per-metric sliding windows with pre-computed aggregates.
Package tsdb provides an in-memory ring buffer for per-metric sliding windows with pre-computed aggregates.
ui
test
authservice command
browser
Package browser contains the browser-tagged black-box UI smoke test.
Package browser contains the browser-tagged black-box UI smoke test.
gate/gatecore
Package gatecore holds the pure logic of the seven-day aggregate release gate (#202): configuration, parsers, threshold evaluation, the projection fit, the result schema, and the Markdown renderer.
Package gatecore holds the pure logic of the seven-day aggregate release gate (#202): configuration, parsers, threshold evaluation, the projection fit, the result schema, and the Markdown renderer.
orderservice command
paymentservice command
readproof
Package readproof holds the untagged half of the read-latency proof (issue #289, decision #281): the result schema, exact ordered percentiles, threshold evaluation and the JSON writer.
Package readproof holds the untagged half of the read-latency proof (issue #289, decision #281): the result schema, exact ordered percentiles, threshold evaluation and the JSON writer.
releasecandidate command
Command releasecandidate verifies signed draft release assets and assembles the release-candidate-v1.json evidence index consumed by the release workflow.
Command releasecandidate verifies signed draft release assets and assembles the release-candidate-v1.json evidence index consumed by the release workflow.
shippingservice command
userservice command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL