Skip to content

Commit

Permalink
Move to go.nhat.io (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Sep 15, 2022
1 parent 12245cb commit a588e64
Show file tree
Hide file tree
Showing 92 changed files with 863 additions and 435 deletions.
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
---
name: "CodeQL"

on:
Expand Down
18 changes: 13 additions & 5 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
---
name: lint

on:
push:
tags:
- v*
branches:
- master

env:
GO_VERSION: 1.18
GOLANGCI_LINT_VERSION: v1.48.0

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
lint-go:
name: lint
strategy:
fail-fast: false
Expand All @@ -31,12 +29,22 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- id: vars
run: |
make gha-vars
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.module }}

lint-gherkin:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: gherkin-lint
uses: nhatthm/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr-tidy.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: pr-tidy

on:
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: pr

on:
Expand All @@ -7,7 +8,6 @@ env:
GO111MODULE: "on"
GO_VERSION: 1.18
GO_LATEST_VERSION: "1.19.x"
GOLANGCI_LINT_VERSION: v1.48.0

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
if: ${{ env.IS_DEPENDABOT_PR == 'true' }}
run: .github/scripts/pr_precondition.sh

lint:
lint-go:
name: lint
strategy:
fail-fast: false
Expand All @@ -66,12 +66,24 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- id: vars
run: |
make gha-vars
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
version: ${{ steps.vars.outputs.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.module }}

lint-gherkin:
name: lint
runs-on: ubuntu-latest
needs: precondition
if: ${{ needs.precondition.outputs.passed == 'true' }}
steps:
- uses: actions/checkout@v3

- name: gherkin-lint
uses: nhatthm/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: release

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-compatibility-libpq.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: compatibility-test-libpq

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-compatibility-mssql.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: compatibility-test-mssql

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-compatibility-mysql.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: compatibility-test-mysql

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-compatibility-pgx.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: compatibility-test-pgx

on:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-unit.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: unit-test

on:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/update-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: 'update-registry'

on:
push:
branches:
- master
tags:
- v*
workflow_dispatch:

jobs:
notify:
runs-on: ubuntu-latest
strategy:
matrix:
registry: [ go.nhat.io, go-staging.nhat.io ]
steps:
- uses: actions/checkout@v3

- id: vars
run: |
make gha-vars
- name: notify ${{ matrix.registry }}
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build
repo: nhatthm/${{ matrix.registry }}
token: ${{ secrets.REGISTRY_TOKEN }}
inputs: '{"modules": "${{ steps.vars.outputs.MODULE_NAME }}"}'
ref: 'master'
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
MODULE_NAME=otelsql

VENDOR_DIR = vendor

GOLANGCI_LINT_VERSION ?= v1.48.0
GOLANGCI_LINT_VERSION ?= v1.49.0

GO ?= go
GOLANGCI_LINT ?= golangci-lint
GOLANGCI_LINT ?= $(shell go env GOPATH)/bin/golangci-lint-$(GOLANGCI_LINT_VERSION)
GHERKIN_LINT ?= gherkin-lint

TEST_FLAGS = -race
Expand All @@ -26,11 +28,11 @@ $(VENDOR_DIR):
@$(GO) mod vendor

.PHONY: $(lintGoModules)
$(lintGoModules): bin/$(GOLANGCI_LINT)
$(lintGoModules): $(GOLANGCI_LINT)
$(eval GO_MODULE := "$(subst lint/module,.,$(subst -,/,$(subst lint-module-,,$@)))")

@echo ">> module: $(GO_MODULE)"
@cd "$(GO_MODULE)"; bin/$(GOLANGCI_LINT) run
@cd "$(GO_MODULE)"; $(GOLANGCI_LINT) run

.PHONY: lint
lint: $(lintGoModules)
Expand Down Expand Up @@ -75,7 +77,12 @@ test-compatibility: $(compatibilityTests)
.PHONY: test
test: test-unit test-compatibility

bin/$(GOLANGCI_LINT):
.PHONY: gha-vars
gha-vars:
@echo "::set-output name=MODULE_NAME::$(MODULE_NAME)"
@echo "::set-output name=GOLANGCI_LINT_VERSION::$(GOLANGCI_LINT_VERSION)"

$(GOLANGCI_LINT):
@echo "$(OK_COLOR)==> Installing golangci-lint $(GOLANGCI_LINT_VERSION)$(NO_COLOR)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin "$(GOLANGCI_LINT_VERSION)"
@mv ./bin/golangci-lint bin/$(GOLANGCI_LINT)
@mv ./bin/golangci-lint $(GOLANGCI_LINT)
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
> ⚠️ From `v0.5.0`, the project will be rebranded to `go.nhat.io/otelsql`. `v.4.x` is the last version with `github.com/nhatthm/otelsql`.
> ⚠️ From `v0.5.0`, the project is rebranded to `go.nhat.io/otelsql`. `v0.4.x` is the last version with `github.com/nhatthm/otelsql`.
# OpenTelemetry SQL database driver wrapper for Go

[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/otelsql)](https://github.com/nhatthm/otelsql/releases/latest)
[![Build Status](https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml/badge.svg?branch=master)](https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml)
[![codecov](https://codecov.io/gh/nhatthm/otelsql/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/otelsql)
[![Go Report Card](https://goreportcard.com/badge/github.com/nhatthm/otelsql)](https://goreportcard.com/report/github.com/nhatthm/otelsql)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/nhatthm/otelsql)
[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/otelsql)](https://goreportcard.com/report/go.nhat.io/otelsql)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/otelsql)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)

Add a OpenTelemetry wrapper to your existing database code to instrument the interactions with the database. The wrapper supports both traces and metrics.
Expand Down Expand Up @@ -42,17 +42,20 @@ Add a OpenTelemetry wrapper to your existing database code to instrument the int
## Install

```bash
go get github.com/nhatthm/otelsql
go get go.nhat.io/otelsql
```

Compatibility

| `otelsql` | `go.opentelemetry.io/otel/trace` | `go.opentelemetry.io/otel/sdk/metric` |
|:---------:|:--------------------------------:|:-------------------------------------:|
| `v0.1.*` | `v1.3.0` ~> `latest` | `v0.26.0` ~> `v0.27.0` |
| `v0.2.*` | `v1.3.0` ~> `latest` | `v0.28.0` ~> `v0.30.0` |
| `v0.3.*` | `v1.3.0` ~> `latest` | `v0.28.0` ~> `v0.30.0` |
| `v0.4.*` | `v1.3.0` ~> `latest` | `v0.31.0` ~> `latest` |
| `otelsql` | `go.opentelemetry.io/otel/trace` | `go.opentelemetry.io/otel/sdk/metric` |
|:--------------------------:|:--------------------------------:|:-------------------------------------:|
| `v0.5.*` <sup>&nbsp;</sup> | `v1.10.0` ~> `latest` | `v0.31.0` ~> `latest` |
| `v0.4.*` <sup>1</sup> | `v1.9.0` ~> `latest` | `v0.31.0` ~> `latest` |
| `v0.3.*` <sup>1</sup> | `v1.7.0` ~> `latest` | `v0.28.0` ~> `v0.30.0` |
| `v0.2.*` <sup>1</sup> | `v1.6.2` ~> `latest` | `v0.28.0` ~> `v0.30.0` |
| `v0.1.*` <sup>1</sup> | `v1.4.1` ~> `latest` | `v0.26.0` ~> `v0.27.0` |

<sup>1</sup> Old versions were shipped under `github.com/nhatthm/otelsql`. Use `go get github.com/nhatthm/otelsql` instead.

[<sub><sup>[table of contents]</sup></sub>](#table-of-contents)

Expand All @@ -67,7 +70,7 @@ package example
import (
"database/sql"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
)

Expand Down Expand Up @@ -100,7 +103,7 @@ package example
import (
"database/sql"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
)

Expand Down Expand Up @@ -191,7 +194,7 @@ import (
"context"
"database/sql"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
)

func openDB(dsn string) (*sql.DB, error) {
Expand All @@ -218,7 +221,7 @@ import (
"context"
"database/sql"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
)

func openDB(dsn string) (*sql.DB, error) {
Expand Down Expand Up @@ -257,7 +260,7 @@ import (
"database/sql"
"errors"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
"go.opentelemetry.io/otel/codes"
)

Expand Down Expand Up @@ -323,7 +326,7 @@ import (
"database/sql"
"database/sql/driver"

"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.10.0"
Expand Down Expand Up @@ -393,7 +396,7 @@ import (
"database/sql"

"github.com/jmoiron/sqlx"
"github.com/nhatthm/otelsql"
"go.nhat.io/otelsql"
)

func openDB(dsn string) (*sql.DB, error) {
Expand Down
6 changes: 4 additions & 2 deletions attribute/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ func KeyValueDuration(key attribute.Key, d time.Duration) attribute.KeyValue {
}

func shortenString(s string) string {
if len(s) <= _maxStringValueLength {
runes := []rune(s)

if len(runes) <= _maxStringValueLength {
return s
}

end := _maxStringValueLength - len(_shortenedPattern)
sb := strings.Builder{}

sb.Grow(_maxStringValueLength)
sb.WriteString(s[0:end])
sb.WriteString(string(runes[:end]))
sb.WriteString(_shortenedPattern)

return sb.String()
Expand Down
12 changes: 6 additions & 6 deletions attribute/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"

sqlattribute "github.com/nhatthm/otelsql/attribute"
xattr "go.nhat.io/otelsql/attribute"
)

const key = attribute.Key("key")
Expand Down Expand Up @@ -57,7 +57,7 @@ func BenchmarkFromNamedValue(b *testing.B) {

for i := 0; i < b.N; i++ {
for _, v := range namedValues {
sqlattribute.FromNamedValue(v)
xattr.FromNamedValue(v)
}
}
}
Expand All @@ -67,7 +67,7 @@ func BenchmarkKeyValueDuration(b *testing.B) {
d := time.Duration(r.Int63n(int64(10 * time.Second)))

for i := 0; i < b.N; i++ {
sqlattribute.KeyValueDuration(key, d)
xattr.KeyValueDuration(key, d)
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func TestFromNamedValue(t *testing.T) {
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

actual := sqlattribute.FromNamedValue(tc.value)
actual := xattr.FromNamedValue(tc.value)

assert.Equal(t, tc.expected, actual)
})
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestKeyValue(t *testing.T) {
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

actual := sqlattribute.KeyValue(key, tc.value)
actual := xattr.KeyValue(key, tc.value)

assert.Equal(t, tc.expected, actual)
})
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestKeyValueDuration(t *testing.T) {
t.Run(tc.scenario, func(t *testing.T) {
t.Parallel()

actual := sqlattribute.KeyValueDuration(key, tc.duration)
actual := xattr.KeyValueDuration(key, tc.duration)

assert.Equal(t, tc.expected, actual)
})
Expand Down
Loading

0 comments on commit a588e64

Please sign in to comment.