Skip to content

Commit

Permalink
Add Go 1.11 sql.DBStats tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
dsoo authored Nov 7, 2019
2 parents 61afe01 + 15966b7 commit 82efdfb
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 250 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ workflows:
goversion: "11"
- test_beeline:
goversion: "12"
- test_beeline:
goversion: "13"
171 changes: 84 additions & 87 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,116 +1,115 @@
Release v0.4.5 (2019-09-17)
==
# Release v0.4.7 (2019-11-07)

### Additions

- Add additional go database stats to `hnysql` and `hnysqlx` wrapppers. In go 1.11 and later, we additionally report `db.conns_in_use`, `db.conns_idle`, `db.wait_count`, and `db.wait_duration`. See https://golang.org/pkg/database/sql/#DB.Stats

# Release v0.4.6 (2019-10-31)

### Bugfixes

* Fixed `db.error` not being added by `hnysql` and `hnysqlx` wrappers.
* Reduction in heap allocations when creating a span.
- added missing `Close` function to the `Stmt` type
- renamed `echo` example binary for using the echo web framework so it doesn't collide with the builtin shell `echo` command
- updated transaction's `QueryxContext` to use a span instead of an event

Release v0.4.4 (2019-04-09)
==
# Release v0.4.5 (2019-09-17)

### Bugfixes

* Fixed an issue where the libhoney transmission was being spun up without a default batch timeout, so spans were only getting sent when they hit the batch max (50) rather than after a 100ms timeout.
* Use libhoney defaults for all missing parameters during initialization (previously the beeline had a few values that differed from the libhoney defaults).
- Fixed `db.error` not being added by `hnysql` and `hnysqlx` wrappers.
- Reduction in heap allocations when creating a span.

### Additions
# Release v0.4.4 (2019-04-09)

### Bugfixes

- Fixed an issue where the libhoney transmission was being spun up without a default batch timeout, so spans were only getting sent when they hit the batch max (50) rather than after a 100ms timeout.
- Use libhoney defaults for all missing parameters during initialization (previously the beeline had a few values that differed from the libhoney defaults).

* Added the Contributors file listing people that have made contributions to the Beeline
### Additions

- Added the Contributors file listing people that have made contributions to the Beeline

Release v0.4.3 (2019-04-09)
==
# Release v0.4.3 (2019-04-09)

### Bugfixes

* Fix race condition when concurrently adding children and sending a non-root
- Fix race condition when concurrently adding children and sending a non-root
span. Contribution by @carlosgaldino

Release v0.4.2 (2019-04-08)
==
# Release v0.4.2 (2019-04-08)

### Additions

* @jamietsao contributed middleware for the Echo router (https://echo.labstack.com/)
- @jamietsao contributed middleware for the Echo router (https://echo.labstack.com/)

### Bugfixes

* Events that were coming in with an existing sample rate to a beeline
- Events that were coming in with an existing sample rate to a beeline
configured to do additional sampling were not computing the final sample rate
correctly. This change fixes the sample rate in that specific case.
* Added missing comment describing the semantics of the `dataset` field in the
- Added missing comment describing the semantics of the `dataset` field in the
trace propagation header added in v0.3.5


Release v0.4.1 (2019-03-21)
==
# Release v0.4.1 (2019-03-21)

### Bugfixes

* Sample rate returned by the sampler hook was incorrectly being multiplied with the default global sample rate.
- Sample rate returned by the sampler hook was incorrectly being multiplied with the default global sample rate.

Release v0.4.0 (2018-11-28)
==
# Release v0.4.0 (2018-11-28)

### Additions

* Add a `libhoney.Client` as a configurable item in the beeline initial config.
- Add a `libhoney.Client` as a configurable item in the beeline initial config.
This allows full control over the underlying transmission of spans, so you can
replace the HTTP transport or adjust queue sizes and so on

Release v0.3.6 (2018-11-28)
==
# Release v0.3.6 (2018-11-28)

### Additions

* Add `CopyContext` function to simplify moving trace metadata to a new context
- Add `CopyContext` function to simplify moving trace metadata to a new context
(for example, when trying to avoid a cancellation in an async span).
* Improve handling of broken or partial trace propagation headers
- Improve handling of broken or partial trace propagation headers

Release v0.3.5 (2018-11-28)
==
# Release v0.3.5 (2018-11-28)

### Additions

* Add `dataset` to serialized trace headers to allow one service with multiple
- Add `dataset` to serialized trace headers to allow one service with multiple
upstream callers to send spans to the right destination dataset

Release v0.3.4 (2018-11-28)
==
# Release v0.3.4 (2018-11-28)

### Additions

* Delete spans from the trace when they're sent for improved memory management
* Add a benchmark
- Delete spans from the trace when they're sent for improved memory management
- Add a benchmark

Release v0.3.3 (2018-11-28)
==
# Release v0.3.3 (2018-11-28)

### Additions

* Add URL queries and add name even when empty
- Add URL queries and add name even when empty

Release v0.3.2 (2018-11-28)
==
# Release v0.3.2 (2018-11-28)

### Bugfixes

* Fix multiple races when sending spans. (https://github.com/honeycombio/beeline-go/pull/39 and https://github.com/honeycombio/beeline-go/pull/40)
- Fix multiple races when sending spans. (https://github.com/honeycombio/beeline-go/pull/39 and https://github.com/honeycombio/beeline-go/pull/40)

Release v0.3.1 (2018-10-25)
==
# Release v0.3.1 (2018-10-25)

### Bugfixes

* Fix race condition on map access that can occur with Sampler and Presend hooks when AddField is called concurrently with Send.
- Fix race condition on map access that can occur with Sampler and Presend hooks when AddField is called concurrently with Send.

Release v0.3.0 (2018-10-23)
==
# Release v0.3.0 (2018-10-23)

### Breaking Changes

* `NewResponseWriter` no longer returns a concrete type directly usable as an `http.ResponseWriter`. It now exposes the wrapped `http.ResponseWriter` through the field `Wrapped`.
- `NewResponseWriter` no longer returns a concrete type directly usable as an `http.ResponseWriter`. It now exposes the wrapped `http.ResponseWriter` through the field `Wrapped`.

Code that would have previously looked like:

Expand All @@ -126,82 +125,80 @@ wrappedWriter := common.NewResponseWriter(w)
handler.ServeHTTP(wrappedWriter.Wrapped, r)
```

Release v0.2.4 (2018-10-05)
===
# Release v0.2.4 (2018-10-05)

### Minor Changes

* Allow override of MaxConcurrentBatches, MaxBatchSize, and PendingWorkCapacity in `beeline.Config`
* Sets default value for MaxConcurrentBatches to 20 (from 80), and PendingWorkCapacity to 1000 (from 10000).
- Allow override of MaxConcurrentBatches, MaxBatchSize, and PendingWorkCapacity in `beeline.Config`
- Sets default value for MaxConcurrentBatches to 20 (from 80), and PendingWorkCapacity to 1000 (from 10000).

Release v0.2.3 (2018-09-14)
===
# Release v0.2.3 (2018-09-14)

### Bug Fixes
* rollup fields were not getting the rolled up values added to the root span

- rollup fields were not getting the rolled up values added to the root span

### New Field
* sql and sqlx wrappers get both the DB call being made (eg Select) as well as the name of the function making the call (eg FetchThingsByID)

Release v0.2.2 (2018-09-1)
===
- sql and sqlx wrappers get both the DB call being made (eg Select) as well as the name of the function making the call (eg FetchThingsByID)

# Release v0.2.2 (2018-09-1)

### Bug Fixes
* fix version number inconsistency with a patch bump

Release v0.2.1 (2018-09-14)
===
- fix version number inconsistency with a patch bump

# Release v0.2.1 (2018-09-14)

### Bug Fixes
* fix propagation bug when an incoming request has a serialized beeline trace header

Release v0.2.0 (2018-09-12)
===
- fix propagation bug when an incoming request has a serialized beeline trace header

# Release v0.2.0 (2018-09-12)

This is the second major release of the beeline. It changes the model from "one
current span" to a to a doubly-linked tree of events (now dubbed "spans")
representing a trace.

### Major Changes

* introduces the concept of a span
* adds functions to create new spans in a trace and add fields to specific spans
* adds the ability to create and accept a serialized chunk of data from an upstream service to connect in-process traces in a distributed infrastructure into one large trace.
* adds trace level fields that get copied to every downstream span
* adds rollup fields that sum their values and push them in to the root span
* adds a pre-send hook to modify spans before sending them to Honeycomb
* adds trace-aware deterministic sampling as the default
* adds a sampler hook to manually manage sampling if necessary
- introduces the concept of a span
- adds functions to create new spans in a trace and add fields to specific spans
- adds the ability to create and accept a serialized chunk of data from an upstream service to connect in-process traces in a distributed infrastructure into one large trace.
- adds trace level fields that get copied to every downstream span
- adds rollup fields that sum their values and push them in to the root span
- adds a pre-send hook to modify spans before sending them to Honeycomb
- adds trace-aware deterministic sampling as the default
- adds a sampler hook to manually manage sampling if necessary

### Breaking Changes

* removed `ContextEvent` and `ContextWithEvent` functions; replaced by spans
- removed `ContextEvent` and `ContextWithEvent` functions; replaced by spans

### Wrapper Changes
* augment the net/http wrapper to wrap `RoundTripper`s and handle outbound HTTP calls
* adding a wrapper for the `pop` package

- augment the net/http wrapper to wrap `RoundTripper`s and handle outbound HTTP calls
- adding a wrapper for the `pop` package

Release v0.1.2 (2018-08-30)
===
# Release v0.1.2 (2018-08-30)

### New Features

* add new sqlx functions to add context to transactions and rollbacks
* add HTTP Headers X-Forwarded-For and X-Forwarded-Proto to events if they exist
- add new sqlx functions to add context to transactions and rollbacks
- add HTTP Headers X-Forwarded-For and X-Forwarded-Proto to events if they exist

### Bug Fixes
* use the passed in context in sqlx instead of creating a background context

Release v0.1.1 (2018-08-20)
===
- use the passed in context in sqlx instead of creating a background context

# Release v0.1.1 (2018-08-20)

### Bug Fixes
* Use the right Host header for incoming HTTP requests
* Recognize struct HTTP handlers and add their name
* Fix nil route bug

Release v0.1.0 (2018-05-16)
===
- Use the right Host header for incoming HTTP requests
- Recognize struct HTTP handlers and add their name
- Fix nil route bug

# Release v0.1.0 (2018-05-16)

Initial Release
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package beeline

const version = "0.4.5"
const version = "0.4.7"
9 changes: 6 additions & 3 deletions wrappers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"database/sql"
"net/http"
"runtime"
"strings"
Expand Down Expand Up @@ -148,15 +149,16 @@ func sharedDBEvent(bld *libhoney.Builder, query string, args ...interface{}) *li
}

// BuildDBEvent tries to bring together most of the things that need to happen
// for an event to wrap a DB call in bot the sql and sqlx packages. It returns a
// for an event to wrap a DB call in both the sql and sqlx packages. It returns a
// function which, when called, dispatches the event that it created. This lets
// it finish a timer around the call automatically. This function is only used
// when no context (and therefore no beeline trace) is available to the caller -
// if context is available, use BuildDBSpan() instead to tie it in to the active
// trace.
func BuildDBEvent(bld *libhoney.Builder, query string, args ...interface{}) (*libhoney.Event, func(error)) {
func BuildDBEvent(bld *libhoney.Builder, stats sql.DBStats, query string, args ...interface{}) (*libhoney.Event, func(error)) {
timer := timer.Start()
ev := sharedDBEvent(bld, query, args)
addDBStatsToEvent(ev, stats)
fn := func(err error) {
duration := timer.Finish()
// rollup(ctx, ev, duration)
Expand All @@ -173,7 +175,7 @@ func BuildDBEvent(bld *libhoney.Builder, query string, args ...interface{}) (*li
// BuildDBSpan does the same things as BuildDBEvent except that it has access to
// a trace from the context and takes advantage of that to add the DB events
// into the trace.
func BuildDBSpan(ctx context.Context, bld *libhoney.Builder, query string, args ...interface{}) (context.Context, *trace.Span, func(error)) {
func BuildDBSpan(ctx context.Context, bld *libhoney.Builder, stats sql.DBStats, query string, args ...interface{}) (context.Context, *trace.Span, func(error)) {
timer := timer.Start()
parentSpan := trace.GetSpanFromContext(ctx)
var span *trace.Span
Expand All @@ -188,6 +190,7 @@ func BuildDBSpan(ctx context.Context, bld *libhoney.Builder, query string, args
} else {
ctx, span = parentSpan.CreateChild(ctx)
}
addDBStatsToSpan(span, stats)

ev := sharedDBEvent(bld, query, args...)
for k, v := range ev.Fields() {
Expand Down
26 changes: 26 additions & 0 deletions wrappers/common/common_go1.11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//+build go1.11

package common

import (
"database/sql"

"github.com/honeycombio/beeline-go/trace"
libhoney "github.com/honeycombio/libhoney-go"
)

func addDBStatsToEvent(ev *libhoney.Event, stats sql.DBStats) {
ev.AddField("db.open_conns", stats.OpenConnections)
ev.AddField("db.conns_in_use", stats.InUse)
ev.AddField("db.conns_idle", stats.Idle)
ev.AddField("db.wait_count", stats.WaitCount)
ev.AddField("db.wait_duration", stats.WaitDuration)
}

func addDBStatsToSpan(span *trace.Span, stats sql.DBStats) {
span.AddField("db.open_conns", stats.OpenConnections)
span.AddField("db.conns_in_use", stats.InUse)
span.AddField("db.conns_idle", stats.Idle)
span.AddField("db.wait_count", stats.WaitCount)
span.AddField("db.wait_duration", stats.WaitDuration)
}
18 changes: 18 additions & 0 deletions wrappers/common/common_prego1.11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build !go1.11

package common

import (
"database/sql"

"github.com/honeycombio/beeline-go/trace"
libhoney "github.com/honeycombio/libhoney-go"
)

func addDBStatsToEvent(ev *libhoney.Event, stats sql.DBStats) {
ev.AddField("db.open_conns", stats.OpenConnections)
}

func addDBStatsToSpan(span *trace.Span, stats sql.DBStats) {
span.AddField("db.open_conns", stats.OpenConnections)
}
Loading

0 comments on commit 82efdfb

Please sign in to comment.