MCPcopy Index your code
hub / github.com/NdoleStudio/go-otelroundtripper

github.com/NdoleStudio/go-otelroundtripper @v0.0.15

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.15 ↗ · + Follow
42 symbols 152 edges 6 files 9 documented · 21% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.MeterProvider()Meter("otel-round-tripper")),
        WithAttributes(
            semconv.ServiceNameKey.String("otel-round-tripper"),
        ),
    ),
}

response, 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_request 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

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 21
Method 16
Struct 3
FuncType 1
Interface 1

Languages

Go100%

Modules by API surface

round_tripper.go20 symbols
option.go8 symbols
round_tripper_test.go6 symbols
option_test.go4 symbols
example_test.go2 symbols
config.go2 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add go-otelroundtripper \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page