Skip to content

Commit

Permalink
tracing: Add documents transaction tag (#44)
Browse files Browse the repository at this point in the history
Tags the `docappender.flush` transaction with the number of documents
that are sent in the bulk request. The tag name is `documents`.

Signed-off-by: Marc Lopez Rubio <[email protected]>
  • Loading branch information
marclop authored Jul 11, 2023
1 parent 31c7e23 commit 96531c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func (a *Appender) flush(ctx context.Context, bulkIndexer *bulkIndexer) error {
logger := a.config.Logger
if a.tracingEnabled() {
tx := a.config.Tracer.StartTransaction("docappender.flush", "output")
tx.Context.SetLabel("documents", n)
defer tx.End()
ctx = apm.ContextWithTransaction(ctx, tx)

Expand Down
4 changes: 4 additions & 0 deletions appender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.elastic.co/apm/v2/apmtest"
"go.elastic.co/apm/v2/model"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
Expand Down Expand Up @@ -876,6 +877,9 @@ func testAppenderTracing(t *testing.T, statusCode int, expectedOutcome string) {

assert.Equal(t, expectedOutcome, payloads.Transactions[0].Outcome)
assert.Equal(t, "output", payloads.Transactions[0].Type)
assert.Equal(t, model.IfaceMapItem{Key: "documents", Value: float64(N)},
payloads.Transactions[0].Context.Tags[0],
)
assert.Equal(t, "docappender.flush", payloads.Transactions[0].Name)
assert.Equal(t, "Elasticsearch: POST _bulk", payloads.Spans[0].Name)
assert.Equal(t, "db", payloads.Spans[0].Type)
Expand Down

0 comments on commit 96531c3

Please sign in to comment.