Skip to content

chore: extract observability data types into pkg/observability (Phase 2 prep)#44

Merged
Viridian-Inc merged 1 commit into
mainfrom
chore/observability-types-package
May 2, 2026
Merged

chore: extract observability data types into pkg/observability (Phase 2 prep)#44
Viridian-Inc merged 1 commit into
mainfrom
chore/observability-types-package

Conversation

@Viridian-Inc
Copy link
Copy Markdown
Owner

Summary

Phase 2 of the package split (#37) needs a home for the cross-cutting observability primitives shared between the AWS gateway, the reverse proxy, the admin API, and the dataplane: `RequestEntry`, `RequestLog`, `RequestStats`, `RequestBroadcaster`, `TraceContext`, `TraceStore`, `GenerateTraceID`/`GenerateSpanID`. This PR carves them into `pkg/observability/` and leaves Go type aliases in `pkg/gateway/`, so the 77 external importers — including ~50 service tests asserting on `gateway.RequestEntry` field shapes — keep compiling unchanged.

Moved:

  • `pkg/observability/request_log.go` — `RequestEntry`, `RequestLog`, `RequestFilter`, `RequestStats`, `RequestBroadcaster`, plus a new `NextRequestID()` helper replacing the package-level `requestIDCounter` the middleware was incrementing inline.
  • `pkg/observability/trace.go` — verbatim move from `pkg/gateway/tracing.go`.
  • `pkg/observability/traceid/` — moved from `pkg/gateway/traceid/` (sole importer was the trace file above).

Stays in `pkg/gateway/`:

`pkg/gateway/tracing.go` becomes ~25 lines of aliases. `pkg/gateway/logging.go` loses ~200 lines of moved data-type definitions but keeps every middleware.

Closes #43.

Behavior change

None. Aliases preserve type identity, JSON tags, method sets, and interface satisfaction. The wire format on `/api/requests/` and `/api/traces/` is byte-identical.

Test plan

  • `go build ./...`
  • `go test -short ./pkg/... ./services/... ./sdk/... ./cmd/...` — all green except the same pre-existing `pkg/platform/store` testcontainers/Docker failure that's been reproducing on every PR in this branch (Docker not running on this machine; reproduces on `origin/main` baseline)
  • `go vet ./pkg/observability/... ./pkg/gateway/... ./pkg/admin/... ./pkg/dataplane/... ./sdk/... ./cmd/...`
  • Spot-checked the `services/*` test ecosystem — all 50+ that import `gateway.RequestEntry` continue to pass without any test edits.

What this unblocks

Phase 2 of the package split: extracting `pkg/gateway/proxy.go` + `pkg/gateway/certs.go` into `pkg/edge` (or `pkg/revproxy`). With this PR landed, the proxy can import `pkg/observability` directly without depending on `pkg/gateway` — the precondition that was blocking the split.

🤖 Generated with Claude Code

… 2 prep)

Carve the cross-cutting request-log, stats, and tracing primitives out of
pkg/gateway/ into a new pkg/observability package. Leave Go type aliases in
pkg/gateway so the 77 external importers — including ~50 service tests
asserting on gateway.RequestEntry field shapes — keep compiling unchanged.

Moved:
- pkg/observability/request_log.go: RequestEntry, RequestLog, RequestFilter,
  RequestStats, RequestBroadcaster, plus a new NextRequestID() helper that
  replaces the package-level requestIDCounter the middleware was
  incrementing inline.
- pkg/observability/trace.go: TraceContext, TraceSummary, TimelineSpan,
  TraceStore + helpers, GenerateTraceID/GenerateSpanID. Verbatim from
  pkg/gateway/tracing.go.
- pkg/observability/traceid/: moved from pkg/gateway/traceid/ (sole
  importer was the trace file above; no external users).

Stays in pkg/gateway:
- LoggingMiddleware + LoggingMiddlewareWithOpts and the request parsers
  (detectServiceFromRequest, extractCallerID, serviceFromAuth, etc.).
- responseRecorder, body-capture const, mem/goroutine sampling.
- SetServicePrefixes from PR #36.

pkg/gateway/tracing.go becomes ~25 lines of aliases. pkg/gateway/logging.go
loses ~200 lines of moved data-type definitions but keeps all middleware.

Zero behavior change — aliases preserve type identity, JSON tags, and
method sets. Verified all packages green except the same pre-existing
pkg/platform/store testcontainers/Docker failure that's been failing on
every PR in this branch.

Unblocks Phase 2 (extract reverse proxy from pkg/gateway/ into pkg/edge):
the proxy can now import pkg/observability directly without depending on
pkg/gateway.

Closes #43

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Viridian-Inc Viridian-Inc merged commit 3cb9579 into main May 2, 2026
5 checks passed
@Viridian-Inc Viridian-Inc deleted the chore/observability-types-package branch May 2, 2026 09:30
Viridian-Inc added a commit that referenced this pull request May 2, 2026
…#46)

Closes the original Phase 2 from #37. With observability primitives now in
pkg/observability (#44), the L7 reverse proxy and its TLS-cert helper can
finally leave pkg/gateway without circular imports.

Moved verbatim into pkg/edge:
- proxy.go: ProxyRoute, ProxyServer, ServicePorts, BuildRoutes,
  BuildRoutesWithPorts, NewProxyServer{,WithOpts}, StartProxy{,WithOpts},
  ProxyOpts, plus all internal handlers (logProxyRequest,
  proxyToWithOpts, addCORSHeaders, rewriteResponseBody,
  isWebSocketUpgrade, proxyWebSocket, statusRecorder).
- certs.go: CertPair, EnsureCerts, all OS trust helpers, file/PEM I/O.
- proxy_test.go and certs_test.go.

Internal references to RequestLog / RequestStats / RequestBroadcaster /
RequestEntry / GenerateTraceID updated to import from pkg/observability
directly (no longer go through gateway aliases).

pkg/gateway/proxy.go and pkg/gateway/certs.go shrink to type aliases +
forwarder functions so external callers (cmd/gateway/main.go and any
historical importers) continue to compile.

cmd/gateway/main.go migrated to import pkg/edge directly — edge is the
canonical home now. The gateway aliases stay in place for safety.

Test sweep green except the same pre-existing pkg/platform/store
testcontainers/Docker failure that's been failing on every PR in this
branch (Docker not running on this machine; reproduces on origin/main).

Closes #45

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Phase 2 prep: extract observability data types into pkg/observability

1 participant