Skip to content

feat: OpenTelemetry tracing, API versioning, pagination & config enhancements#51

Open
GabrielTenma wants to merge 6 commits into
masterfrom
nightly
Open

feat: OpenTelemetry tracing, API versioning, pagination & config enhancements#51
GabrielTenma wants to merge 6 commits into
masterfrom
nightly

Conversation

@GabrielTenma

Copy link
Copy Markdown
Member

Summary

Implements OpenTelemetry tracing and API versioning middleware for stackyrd.

1. OpenTelemetry Tracing (pkg/tracer/)

  • tracer.go: OTLP HTTP exporter setup, resource attributes, sampler support
  • middleware.go: Echo middleware for per-request spans, traceparent propagation
  • Config: tracing.enabled, tracing.sample_rate, tracing.otlp_endpoint
  • Span attributes: HTTP method, URL, path, status, peer IP, user agent
  • Supports distributed tracing via W3C traceparent header

2. API Versioning (internal/middleware/versioning.go)

  • VersioningMiddleware: Reads Accept-Version header or ?version= query param
  • Sets X-API-Version response header
  • Sunset/Deprecation headers: Warning, Deprecation, Sunset, Link (rel="sunset")
  • VersionContext: Stores resolved version in echo context
  • SetupVersionRoutes: Registers version-specific route groups under /v{version}/

3. Config Updates (config/config.go)

  • TracingConfig: enabled, sample_rate, otlp_endpoint
  • PaginationConfig: type (offset/cursor), max_per_page
  • InfrastructureConfig: init_timeout (per-component health check timeout)
  • MetricsConfig.SampleRate: fractional metrics sampling

4. Server Integration (internal/server/server.go)

  • initTracing(): Initializes tracer, registers middleware
  • /health now returns init_timeout_seconds

Already Present (no new code)

  • RequestID middleware: Generates X-Request-ID when missing
  • Audit logging: Structured request/response logging with user_id

Config Example

tracing:
  enabled: true
  sample_rate: 0.1
  otlp_endpoint: "otel-collector:4318"

pagination:
  type: offset
  max_per_page: 100

infrastructure:
  init_timeout: 30

…buffer

Add ResetTerminal function in pkg/utils/system.go to emit the escape sequence
restoring the main screen buffer, cursor, and text attributes. Update ClearScreen
in both pkg/utils/system.go and scripts/build/build.go to call ResetTerminal
before performing platform-specific clears, and adjust the defer cleanup in
runTUIBuild to also restore the main buffer. Apply similar startup clearing in
scripts/docker/docker_build.go and scripts/plugin/pkg.go for consistent
terminal state handling across all tools.
Records request count, duration, and sizes using the route template
(c.Path()) for bounded label cardinality.
- New pkg/tracer/ — OTLP HTTP tracing with samplers, span creation, W3C traceparent propagation
- New internal/middleware/versioning.go — Accept-Version header parsing, version context, deprecation headers (Warning/Deprecation/Sunset), version route groups
- Add TracingConfig (enabled, sample_rate, otlp_endpoint) to config
- Wire tracer init in server.go with trace middleware
- Add tracing section to config.yaml
- Add PaginationConfig, InfrastructureConfig to config (from previous commit)
- Add MetricsConfig.SampleRate for sampled metrics

Already present in codebase (no new code needed):
- RequestID middleware — generates X-Request-ID when missing
- Audit logging middleware — structured request/response logging
- Rate limiting with per-endpoint config support
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.

1 participant