Reviewer · API
Decouple API contracts
Define API and extension-point contracts using stable, locally-owned or public types — never couple them to internal implementation details, unstable third-party SDK internals, or another layer's wire/encoding format. Each contract should be the single source of truth for its data shape, typed and versioned on its own terms.
Define API and extension-point contracts using stable, locally-owned or public types — never couple them to internal implementation details, unstable third-party SDK internals, or another layer’s wire/encoding format. Each contract should be the single source of truth for its data shape, typed and versioned on its own terms.
Concretely:
- Don’t expose a vendor SDK’s internal pipeline types (e.g. an in-process metrics SDK’s
metricdata) as part of a contract meant for both in-process and out-of-process consumers; prefer the actual wire protocol types (e.g. OTLP) so every provider gets the same, stable representation and the daemon performs any conversion once instead of pushing it onto every implementer. - Don’t let extension/API points depend on daemon-internal packages (e.g.
daemon/...); restrict their types to the point’s own package or genuinely public API types, since extension points are themselves an API surface and leak abstraction otherwise. - Don’t reuse another API’s JSON/wire encoding as a shortcut (e.g. passing raw JSON-encoded HTTP API structs through a new gRPC-based extension point) just to avoid re-declaring fields; define explicit, properly typed fields for the new contract even if it duplicates some data, or provide a dedicated point that explicitly proxies the old API.
- Prefer typed, generated contracts over ad hoc raw transport passthrough (e.g. wrap a new capability in the framework’s typed service abstraction instead of exposing the raw gRPC service directly), so the contract stays the dependency, not the transport.
Example of what to avoid vs. prefer:
// Avoid: contract tied to an SDK-internal, mutable representation
type Client interface {
UploadMetrics(ctx context.Context, rm *metricdata.ResourceMetrics) error
}
// Prefer: contract tied to the stable wire protocol
type Client interface {
ExportMetrics(ctx context.Context, req *collectormetricspb.ExportMetricsServiceRequest) (*collectormetricspb.ExportMetricsServiceResponse, error)
}
Before merging a new API or extension point, check: does this contract require importing internal daemon packages, an SDK’s internal types, or another API’s encoding? If so, redesign it to own its types explicitly.