XSAM/otelsql
XSAM/otelsql has 424 GitHub stars and 64 forks. Star changes are not measured yet. Last checked 2026-11-14 04:23 UTC. Last push 2026-11-09.
측정된 스타 증가
- in 24h
- 기록 수집 중
- in 7 days
- 기록 수집 중
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
소개
OpenTelemetry instrumentation for database/sql
데이터README.md
Originalotelsql
It is an OpenTelemetry instrumentation for Golang database/sql, a port from https://github.com/open-telemetry/opentelemetry-go-contrib/pull/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)
}
reg, err := otelsql.RegisterDBStatsMetrics(db, otelsql.WithAttributes(
semconv.DBSystemMySQL,
))
if err != nil {
panic(err)
}
defer func() {
_ = db.Close()
_ = reg.Unregister()
}()
Check Option for more features like adding context propagation to SQL queries when enabling WithSQLCommenter.
See godoc for details.
Blog
Getting started with otelsql, the OpenTelemetry instrumentation for Go SQL, is a blog post that explains how to use otelsql in miutes.
Examples
This project provides two docker-compose examples to show how to use it.
- The stdout example is a simple example to show how to use it with a MySQL database. It prints the trace data to stdout and serves metrics data via prometheus client.
- The otel-collector example is a more complex example to show how to use it with a MySQL database and an OpenTelemetry Collector. It sends the trace data and metrics data to an OpenTelemetry Collector. Then, it shows data visually on Jaeger and Prometheus servers.
Trace Instruments
It creates spans on corresponding methods.
Use SpanOptions to adjust creation of spans.
Metric Instruments
- db.client.operation.duration: Duration of database client operations
- Unit: seconds
- Attributes:
db.operation.name(method name),error.type(if error occurs)
Connection Statistics Metrics (from Go's sql.DBStats)
- db.sql.connection.max_open: Maximum number of open connections to the database
- db.sql.connection.open: The number of established connections
- Attributes:
status(idle, inuse)
- Attributes:
- db.sql.connection.wait: The total number of connections waited for
- db.sql.connection.wait_duration: The total time blocked waiting for a new connection (ms)
- db.sql.connection.closed_max_idle: The total number of connections closed due to SetMaxIdleConns
- db.sql.connection.closed_max_idle_time: The total number of connections closed due to SetConnMaxIdleTime
- db.sql.connection.closed_max_lifetime: The total number of connections closed due to SetConnMaxLifetime
Error Type Attribution
When errors occur during database operations, the error.type attribute is automatically populated with the type of the error. This provides more detailed information for debugging and monitoring:
For standard driver errors: Special handling for common driver errors:
database/sql/driver.ErrBadConndatabase/sql/driver.ErrSkipdatabase/sql/driver.ErrRemoveArgument
For custom errors: The fully qualified type name is used (e.g.,
github.com/your/package.CustomError).For built-in errors: The type name is used (e.g.,
*errors.errorStringfor errors created witherrors.New()).
Compatibility
This project is tested on the following systems.
| OS | Go Version | Architecture |
|---|---|---|
| Ubuntu | 1.27 | amd64 |
| Ubuntu | 1.26 | amd64 |
| Ubuntu | 1.27 | 386 |
| Ubuntu | 1.26 | 386 |
| MacOS | 1.27 | amd64 |
| MacOS | 1.26 | amd64 |
| Windows | 1.27 | amd64 |
| Windows | 1.26 | amd64 |
| Windows | 1.27 | 386 |
| Windows | 1.26 | 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.
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,715 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,894 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,491 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,522 스타