net/http
Keep ownership in your application root and pass the client to handlers explicitly:
*repost.Error to your own service response policy. Do not return the event payload or SDK error metadata to an untrusted caller. For queue consumers, use DeliveryState and the idempotency key to decide whether to acknowledge, retry, or reconcile.
Graceful shutdown
Stop accepting work and wait for handlers or workers before closing the client:- Mark the service unready and stop accepting new requests or jobs.
- Ask the HTTP server or worker pool to drain with a bounded context.
- Call
client.Close(). - Shut down telemetry providers owned by the application.
Close rejects new sends, cancels admitted sends, waits for their reservations to settle, drains the active observer callback, and releases owned connections. It is safe to call more than once.
Closing the client before the HTTP server drains cancels sends that active handlers still own. That may be the correct choice when the shutdown deadline expires, but it should be an explicit fallback rather than the normal order.
Request cancellation and tracing
Passingr.Context() connects three lifecycles:
- Client disconnects and server deadlines can cancel the send.
- The runtime stops retry waits and socket work when cancellation is observed.
- The OpenTelemetry bridge uses the active inbound span as the parent of
repost.send.
Serverless functions
Create the client in package scope or another initialization path that the platform reuses across invocations. Do not create and close it inside every invocation. Pass the invocation context to the generated method so platform deadlines still apply. Some serverless platforms provide no reliable process-shutdown hook. In that case, reuse the client for the lifetime of the warm process and let process termination release it. When the platform does provide a shutdown hook, callClose there.
Each operating-system process owns its own client. If a server forks or starts several worker processes, construct the client after the process boundary rather than sharing sockets created before it.
Continue
Observability
Connect inbound spans and own telemetry-provider shutdown.
Configuration
Set process-wide deadlines, connection limits, and admission budgets.
Compatibility & security
Review runtime, platform, dependency, and credential boundaries.