Giter VIP home page Giter VIP logo

otelsql's Introduction

otelsql

ci codecov Go Report Card Documentation

It is an OpenTelemetry instrumentation for Golang database/sql, a port from open-telemetry/opentelemetry-go-contrib#505.

It instruments traces and metrics.

Install

$ go get github.com/XSAM/otelsql

Usage

This project provides four different ways to instrument database/sql:

otelsql.Open, otelsql.OpenDB, otesql.Register and otelsql.WrapDriver.

And then use otelsql.RegisterDBStatsMetrics to instrument sql.DBStats with metrics.

db, err := otelsql.Open("mysql", mysqlDSN, otelsql.WithAttributes(
	semconv.DBSystemMySQL,
))
if err != nil {
	panic(err)
}
defer db.Close()

err = otelsql.RegisterDBStatsMetrics(db, otelsql.WithAttributes(
	semconv.DBSystemMySQL,
))
if err != nil {
	panic(err)
}

Check Option for more features like adding context propagation to SQL queries when enabling WithSQLCommenter.

See godoc and a docker-compose example for details.

Trace Instruments

It creates spans on corresponding methods.

Use SpanOptions to adjust creation of spans.

Metric Instruments

Name Description Units Instrument Type Value Type Attribute Key(s) Attribute Values
db.sql.latency The latency of calls in milliseconds ms Histogram float64 status ok, error
method method name, like sql.conn.query
db.sql.connection.max_open Maximum number of open connections to the database Asynchronous Gauge int64
db.sql.connection.open The number of established connections both in use and idle Asynchronous Gauge int64 status idle, inuse
db.sql.connection.wait The total number of connections waited for Asynchronous Counter int64
db.sql.connection.wait_duration The total time blocked waiting for a new connection ms Asynchronous Counter float64
db.sql.connection.closed_max_idle The total number of connections closed due to SetMaxIdleConns Asynchronous Counter int64
db.sql.connection.closed_max_idle_time The total number of connections closed due to SetConnMaxIdleTime Asynchronous Counter int64
db.sql.connection.closed_max_lifetime The total number of connections closed due to SetConnMaxLifetime Asynchronous Counter int64

Compatibility

This project is tested on the following systems.

OS Go Version Architecture
Ubuntu 1.19 amd64
Ubuntu 1.18 amd64
Ubuntu 1.19 386
Ubuntu 1.18 386
MacOS 1.19 amd64
MacOS 1.18 amd64
Windows 1.19 amd64
Windows 1.18 amd64
Windows 1.19 386
Windows 1.18 386

While this project should work for other systems, no compatibility guarantees are made for those systems currently.

The project follows the Release Policy to support major Go releases.

Why port this?

Based on this comment, OpenTelemetry SIG team like to see broader usage and community consensus on an approach before they commit to the level of support that would be required of a package in contrib. But it is painful for users without a stable version, and they have to use replacement in go.mod to use this instrumentation.

Therefore, I host this module independently for convenience and make improvements based on users' feedback.

Communication

I use GitHub discussions/issues for most communications. Feel free to contact me on CNCF slack.

otelsql's People

Contributors

xsam avatar dependabot[bot] avatar jbub avatar noseglid avatar mniak avatar ccpost avatar rajeshkarnena avatar rcrowe avatar wesleyvicthor avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.