All Projects → posener → client-timing

posener / client-timing

Licence: MIT license
An HTTP client for go-server-timing middleware. Enables automatic timing propagation through HTTP calls between servers.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to client-timing

STM32 TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an STM32F/L/H/G/WB/MP1-based board. These STM32F/L/H/G/WB/MP1 Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micr…
Stars: ✭ 27 (+17.39%)
Mutual labels:  timing
ycecream
Sweeter debugging and benchmarking Python programs.
Stars: ✭ 38 (+65.22%)
Mutual labels:  timing
clock
High-resolution clock functions: monotonic, realtime, cputime.
Stars: ✭ 52 (+126.09%)
Mutual labels:  timing
alfred-timing
⏳ Alfred workflow for Timing app
Stars: ✭ 21 (-8.7%)
Mutual labels:  timing
cdc
Repository gathering basic modules for CDC purpose
Stars: ✭ 30 (+30.43%)
Mutual labels:  timing
timing-provider
An implementation of the timing provider specification.
Stars: ✭ 14 (-39.13%)
Mutual labels:  timing
Unload
An advanced automatic speedrun load time remover for community verifiers.
Stars: ✭ 20 (-13.04%)
Mutual labels:  timing
kokkos-tools
Kokkos C++ Performance Portability Programming EcoSystem: Profiling and Debugging Tools
Stars: ✭ 52 (+126.09%)
Mutual labels:  timing
elapsedMillis
Arduino 'port' of the elapsedMillis library
Stars: ✭ 67 (+191.3%)
Mutual labels:  timing
about-time
A cool helper for tracking time and throughput of code blocks, with beautiful human friendly renditions.
Stars: ✭ 36 (+56.52%)
Mutual labels:  timing
minstant
Performant time measuring in Rust
Stars: ✭ 109 (+373.91%)
Mutual labels:  timing
ptScheduler
Pretty tiny Scheduler or ptScheduler is an Arduino library for writing non-blocking periodic tasks easily.
Stars: ✭ 14 (-39.13%)
Mutual labels:  timing
SAMD TimerInterrupt
This library enables you to use Interrupt from Hardware Timers on an SAMD-based board. These SAMD Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you …
Stars: ✭ 28 (+21.74%)
Mutual labels:  timing
HowLong
A simple command line application that lets you know how long your command has been running.
Stars: ✭ 17 (-26.09%)
Mutual labels:  timing
timing-object
An implementation of the timing object specification.
Stars: ✭ 25 (+8.7%)
Mutual labels:  timing
EasyProfiler
This repo, provides query profiler for .Net
Stars: ✭ 99 (+330.43%)
Mutual labels:  timing
guide.encode.moe
A guide for fansubbing
Stars: ✭ 123 (+434.78%)
Mutual labels:  timing

client-timing

Build Status codecov GoDoc Go Report Card

An HTTP client for go-server-timing middleware.

Features:

  • An HTTP Client or RoundTripper, fully compatible with Go's standard library.
  • Automatically time HTTP requests sent from an HTTP handler.
  • Collects all timing headers from upstream servers.
  • Customize timing headers according to the request, response and error of the HTTP round trip.

Install

go get -u github.com/posener/client-timing

Usage

  1. Add a *clienttiming.Timer to your server handler, or create it in the handler function itself.

  2. Wrap the http.Handler with servertiming.Middleware.

  3. In the handler function, having timer of type *clienttiming.Timer and req is the *http.Request:

    a. Create an *http.Client using timer.Client(req.Context())

    b. Or create an http.RoundTripper using timer.Transport(req.Context())

  4. Use option a or b directly or inject it to a library that accepts them, in your outgoing HTTP request from the handler.

  5. That is it! the timing header will appear in the response from the handler.

Example

Suppose we have an HTTP handler:

type handler struct {
	timer *clienttiming.Timer
}

Our usage of that handler will be:

func main() {
	h := &handler{
		timer: clienttiming.New(clienttiming.WithName("my-server")),
	}
	log.Fatal(http.ListenAndServe(":8080", servertiming.Middleware(h)))
}

Example for Client function:

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// Create an http client using the request context
	c := h.timer.Client(r.Context())

	// Perform HTTP requests, as many as you like
	resp, err := c.Get("https://golang.org/")

	...
}

Example for Transport function:

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// Instrument an http client with a timing transport
	c := &http.Client{
		Transport: h.timer.Transport(r.Context()),
	}

	// Perform HTTP requests, as many as you like
	resp, err := c.Get("https://golang.org/")

	...
}

Run the example

go run ./example/main.go

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].