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

Overview

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

Releases(v0.0.1)
  • v0.0.1(Nov 20, 2021)

    Initial Release

    The following metrics will be emited:

    • *.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
    Source code(tar.gz)
    Source code(zip)
Owner
Ndole Studio
Ndole Studio
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

Binalyze 56 Feb 10, 2022
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

null 0 Jan 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

Sergiy Yavorsky 11 Apr 30, 2021
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,

Felipe Volpone 1 Mar 16, 2022
Easybind - Bind req arguments easily in Golang

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

wentx 3 May 1, 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

snown 4 Mar 4, 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

neoul 0 Dec 1, 2021
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

Aliaksandr Valialkin 18.2k Aug 7, 2022
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'

mattn 65 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

pzenteno 15 Jun 29, 2022
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

Flexagon 61 Jun 10, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Kris 0 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

Jonathan Gonzaga 0 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

Tom 961 Aug 7, 2022
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

Furkan Bozdag 41 Jul 14, 2022
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

Gojek 2.3k Aug 6, 2022
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

Alexander Gehres 20 May 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

Seth Ammons 593 Jul 31, 2022
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

Monaco.HappyHacking 207 Jul 28, 2022