Go http.RoundTripper that emits open telemetry metrics. This helps you easily get metrics for all external APIs you interact with.

go-otelroundtripper

Build codecov Scrutinizer Code Quality Go Report Card GitHub contributors GitHub license PkgGoDev

This package provides an easy way to collect http related metrics (e.g Response times, Status Codes, number of in flight requests etc) for your HTTP API Clients. You can do this by using this round tripper when instantiating the http.CLient{}.

Why this package exists

I currently have to integrate with multiple APIs and I needed a simple way to export metrics for those external API's. Sometimes external API's have their own SDK and the only input is http.Client. In this scenario, I can create an HTTP client with a round tripper automatically exports metrics according to the open telemetry specification.

Installation

go-otelroundtripper is compatible with modern Go releases in module mode, with Go installed:

go get github.com/NdoleStudio/go-otelroundtripper

Alternatively the same can be achieved if you use import in a package:

import "github.com/NdoleStudio/go-otelroundtripper"

Usage

This is a sample code that instantiates an HTTP client which sends requests to https://example.com. You can see a runnable example here

client := http.Client{
    Transport: New(
		WithName("example.com")
        WithMeter(global.Meter("otel-round-tripper")),
        WithAttributes(
            semconv.ServiceNameKey.String("otel-round-tripper"),
        ),
    ),
}

resposne, err := client.Get("https://example.com")

Metrics Emitted

The following metrics will be emitted by this package. Note that * will be replaced by the prefix passed in WithName().

  • *.no_reqeusts http calls with nil http.Request
  • *.errors http requests which had an error response i.e err != nil
  • *.success http requests which were successfull. Meaning there were no transport errors
  • *.timeouts http requests which timed out
  • *.cancelled http requests with cancelled context
  • *.deadline_exceeded http requests with context dateline exceeded
  • *.total_duration total time it takes to execute the http request in milliseconds
  • *.in_flight concurrent http requests
  • *.attempts http requests attempted
  • *.failures http requests with http status code >= 400
  • *.redirects http requests with 300 <= http status code < 400

Testing

You can run the unit tests for this client from the root directory using the command below:

go test -v

License

This project is licensed under the MIT License - see the LICENSE file for details

Similar Resources

fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client.

fhttp The f stands for flex. fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client. T

Jan 1, 2023

Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Jan 17, 2022

Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Feb 1, 2022

Full-featured, plugin-driven, extensible HTTP client toolkit for Go

gentleman Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go. gentleman embr

Dec 23, 2022

An enhanced http client for Golang

An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev 🔗 This package provides you a http client package for your http requests. Y

Dec 23, 2022

An enhanced HTTP client for Go

An enhanced HTTP client for Go

Heimdall Description Installation Usage Making a simple GET request Creating a hystrix-like circuit breaker Creating a hystrix-like circuit breaker wi

Jan 9, 2023

Enriches the standard go http client with retry functionality.

httpRetry Enriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface. The advantage of this libra

Dec 10, 2022

Go (golang) http calls with retries and backoff

pester pester wraps Go's standard lib http client to provide several options to increase resiliency in your request. If you experience poor network co

Dec 28, 2022

http client for golang

http client for golang

Request HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd

Dec 18, 2022
httpreq is an http request library written with Golang to make requests and handle responses easily.

httpreq is an http request library written with Golang to make requests and handle responses easily. Install go get github.com/binalyze/http

Feb 10, 2022
Retry, Race, All, Some, etc strategies for http.Client calls

reqstrategy Package reqstrategy provides functions for coordinating http.Client calls. It wraps typical call strategies like making simultaneous reque

Apr 30, 2021
This is repository for Simple HTTP GET golang app that counts standard deviation from random.org integers

Simple Get Deviation App This is repository for Simple HTTP GET golang app that counts standard deviation from random.org integers IMPORTANT: Because

Jan 10, 2022
a simple wrapper around resty to report HTTP calls metrics to prometheus

restyprom a simple wrapper around resty to report HTTP calls metrics to prometheus If you're using resty and want to have metrics of your HTTP calls,

Sep 25, 2022
Cake is a lightweight HTTP client library for GO, inspired by Java Open-Feign.

Cake is a lightweight HTTP client library for GO, inspired by Java Open-Feign. Installation # With Go Modules, recommanded with go version > 1.16

Oct 6, 2022
Open-source HTTP-based Representational State Transfer Configuration Protocol (RESTCONF)

RESTCONF RESTCONF is a network management protocol based on HTTP [RFC7230], for configuring data defined in YANG version 1 [RFC6020] or YANG version 1

Dec 1, 2021
Easybind - Bind req arguments easily in Golang

easybind Bind req arguments easily in Golang. Support Tag pos, specified that wh

May 1, 2022
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

fasthttp Fast HTTP implementation for Go. Currently fasthttp is successfully used by VertaMedia in a production serving up to 200K rps from more than

Jan 2, 2023
Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

Jul 14, 2021
Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

Oct 7, 2022