Skip to content

Commit

Permalink
a bit of refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amirsalarsafaei committed Dec 25, 2024
1 parent 41bbf36 commit ce110ca
Show file tree
Hide file tree
Showing 9 changed files with 432 additions and 333 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,11 @@ jobs:
with:
go-version: '1.23'

- name: Test
run: go test ./...
- name: Test with Coverage
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: amirsalarsafaei/sqlc-pgx-monitoring
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# sqlc-pgx-monitoring

![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)
[![codecov](https://codecov.io/gh/vgarvardt/sqlc-pgx-monitoring/branch/main/graph/badge.svg)](https://codecov.io/gh/vgarvardt/sqlc-pgx-monitoring)

`sqlc-pgx-monitoring` is a Go package that offers powerful query time monitoring and logging capabilities for applications using the popular `pgx` and `sqlc` libraries in Golang. If you want to gain insights into the performance of your PostgreSQL database queries and ensure the reliability of your application, this package is a valuable addition to your toolset.

## Features

- **Complete OpenTelemetry Support**: Built-in integration with OpenTelemetry for comprehensive observability, including metrics, traces, and spans for all database operations. Traces every database interaction including:
- Individual queries
- Batch operations
- Prepared statements
- Connection lifecycle
- COPY FROM operations

- **Modern Structured Logging**: Native support for Go's `slog` package, providing structured, leveled logging that's easy to parse and analyze.

- **Query Time Monitoring**: Keep a close eye on the execution times of your SQL queries to identify and optimize slow or resource-intensive database operations. It uses name declared in sqlc queries in the label for distinguishing queries from each other.

- **Detailed Logging**: Record detailed logs of executed queries, including name, parameters, timings, and outcomes, which can be invaluable for debugging and performance analysis.
Expand All @@ -17,7 +27,7 @@
To get started with `sqlc-pgx-monitoring`, you can simply use `go get`:

```shell
go get github.com/amirsalarsafaei/sqlc-pgx-monitoring@latest
go get github.com/amirsalarsafaei/sqlc-pgx-monitoring@v1.4.0
```

## Usage
Expand All @@ -34,15 +44,13 @@ To begin using `sqlc-pgx-monitoring` in your Go project, follow these basic step
### pgx.Conn
```go
connConfig.Tracer = dbtracer.NewDBTracer(
logrus.New(),
prometheus.DefaultRegisterer,
"database_name",
)
```
### pgxpool.Pool
```go
poolConfig.ConnConfig.Tracer = dbtracer.NewDBTracer(
logrus.New(),
prometheus.DefaultRegisterer,
"database_name",
)
```

Expand Down
Loading

0 comments on commit ce110ca

Please sign in to comment.