From 73590f38a36566f01184ce7cc1e542ea1647e493 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Sun, 12 Jul 2020 20:30:11 +0000 Subject: [PATCH 01/24] Implemented integration using observers and added an dockerized example --- .../github.com/gocql/gocql/cass.go | 94 +++++++ .../github.com/gocql/gocql/config.go | 129 ++++++++++ .../github.com/gocql/gocql/example/client.go | 115 +++++++++ .../gocql/gocql/example/docker-compose.yml | 21 ++ .../github.com/gocql/gocql/example/go.mod | 12 + .../github.com/gocql/gocql/example/go.sum | 114 +++++++++ instrumentation/github.com/gocql/gocql/go.mod | 11 + instrumentation/github.com/gocql/gocql/go.sum | 120 +++++++++ .../github.com/gocql/gocql/gocql.go | 39 +++ .../github.com/gocql/gocql/gocql_test.go | 234 ++++++++++++++++++ .../github.com/gocql/gocql/observer.go | 170 +++++++++++++ 11 files changed, 1059 insertions(+) create mode 100644 instrumentation/github.com/gocql/gocql/cass.go create mode 100644 instrumentation/github.com/gocql/gocql/config.go create mode 100644 instrumentation/github.com/gocql/gocql/example/client.go create mode 100644 instrumentation/github.com/gocql/gocql/example/docker-compose.yml create mode 100644 instrumentation/github.com/gocql/gocql/example/go.mod create mode 100644 instrumentation/github.com/gocql/gocql/example/go.sum create mode 100644 instrumentation/github.com/gocql/gocql/go.mod create mode 100644 instrumentation/github.com/gocql/gocql/go.sum create mode 100644 instrumentation/github.com/gocql/gocql/gocql.go create mode 100644 instrumentation/github.com/gocql/gocql/gocql_test.go create mode 100644 instrumentation/github.com/gocql/gocql/observer.go diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go new file mode 100644 index 00000000000..f8e6c4a9413 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -0,0 +1,94 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import "go.opentelemetry.io/otel/api/kv" + +const ( + // CassVersionKey is the key for the span attribute describing + // the cql version. + CassVersionKey = kv.Key("cassandra.version") + + // CassHostKey is the key for the span attribute describing + // the host of the cassandra instance being queried. + CassHostKey = kv.Key("cassandra.host") + + // CassPortKey is the key for the span attribute describing + // the port of the cassandra server being queried. + CassPortKey = kv.Key("cassandra.port") + + // CassHostStateKey is the key for the span attribute describing + // the state of the casssandra server hosting the node being queried. + CassHostStateKey = kv.Key("cassandra.host_state") + + // CassStatementKey is the key for the span attribute describing the + // the statement used to query the cassandra database. + // This attribute will only be found on a span for a query. + CassStatementKey = kv.Key("cassandra.stmt") + + // CassBatchStatementsKey is the key for the span attribute describing + // the list of statments used to query the cassandra database in a batch query. + // This attribute will only be found on a span for a batch query. + CassBatchStatementsKey = kv.Key("cassandra.batch_stmts") + + // CassErrMsgKey is the key for the span attribute describing + // the error message from an error encountered when executing a query, batch, + // or connection attempt to the cassandra server. + CassErrMsgKey = kv.Key("cassandra.err_msg") + + // Names of the spans for query, batch query, and connect respectively. + cassQueryName = "cassandra.query" + cassBatchQueryName = "cassandra.batch_query" + cassConnectName = "cassandra.connect" +) + +// CassVersion returns the cql version as a KeyValue pair. +func CassVersion(version string) kv.KeyValue { + return CassVersionKey.String(version) +} + +// CassHost returns the cassandra host as a KeyValue pair. +func CassHost(host string) kv.KeyValue { + return CassHostKey.String(host) +} + +// CassPort returns the port of the cassandra node being queried +// as a KeyValue pair. +func CassPort(port int) kv.KeyValue { + return CassPortKey.Int(port) +} + +// CassHostState returns the state of the cassandra host as a KeyValue pair. +func CassHostState(state string) kv.KeyValue { + return CassHostStateKey.String(state) +} + +// CassStatement returns the statement made to the cassandra database as a +// KeyValue pair. +func CassStatement(stmt string) kv.KeyValue { + return CassStatementKey.String(stmt) +} + +// CassBatchStatements returns the array of statments executed in a batch +// query made to the cassandra database as a keyvalue pair. +func CassBatchStatements(stmt []string) kv.KeyValue { + return CassBatchStatementsKey.Array(stmt) +} + +// CassErrMsg returns the keyvalue pair of an error message +// encountered when executing a query, batch query, or error. +func CassErrMsg(msg string) kv.KeyValue { + return CassErrMsgKey.String(msg) +} diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go new file mode 100644 index 00000000000..30931ed01e6 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -0,0 +1,129 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import ( + "github.com/gocql/gocql" + "go.opentelemetry.io/otel/api/global" + "go.opentelemetry.io/otel/api/trace" +) + +// TracedSessionConfig provides configuration for sessions +// created with NewSessionWithTracing. +type TracedSessionConfig struct { + otelConfig *OtelConfig + queryObserver gocql.QueryObserver + batchObserver gocql.BatchObserver + connectObserver gocql.ConnectObserver + instrumentQuery bool + instrumentBatch bool + instrumentConnect bool +} + +// OtelConfig provides OpenTelemetry configuration. +type OtelConfig struct { + tracer trace.Tracer +} + +// TracedSessionOption is a function type that applies +// a particular configuration to the traced session in question. +type TracedSessionOption func(*TracedSessionConfig) + +// ------------------------------------------ TracedSessionOptions + +// WithQueryObserver sets an additional QueryObserver to the session configuration. Use this if +// there is an existing QueryObserver that you would like called. It will be called after the +// OpenTelemetry implementation, if it is not nil. Defaults to nil. +func WithQueryObserver(observer gocql.QueryObserver) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.queryObserver = observer + } +} + +// WithBatchObserver sets an additional BatchObserver to the session configuration. Use this if +// there is an existing BatchObserver that you would like called. It will be called after the +// OpenTelemetry implementation, if it is not nil. Defaults to nil. +func WithBatchObserver(observer gocql.BatchObserver) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.batchObserver = observer + } +} + +// WithConnectObserver sets an additional ConnectObserver to the session configuration. Use this if +// there is an existing ConnectObserver that you would like called. It will be called after the +// OpenTelemetry implementation, if it is not nil. Defaults to nil. +func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.connectObserver = observer + } +} + +// WithQueryInstrumentation will enable and disable instrumentation of +// queries. Defaults to enabled. +func WithQueryInstrumentation(enabled bool) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.instrumentQuery = enabled + } +} + +// WithBatchInstrumentation will enable and disable insturmentation of +// batch queries. Defaults to enabled. +func WithBatchInstrumentation(enabled bool) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.instrumentBatch = enabled + } +} + +// WithConnectInstrumentation will enable and disable instrumentation of +// connection attempts. Defaults to enabled. +func WithConnectInstrumentation(enabled bool) TracedSessionOption { + return func(cfg *TracedSessionConfig) { + cfg.instrumentConnect = enabled + } +} + +// ------------------------------------------ Otel Options + +// WithTracer will set tracer to be the tracer used to create spans +// for query, batch query, and connection instrumentation. +// Defaults to global.Tracer("github.com/gocql/gocql"). +func WithTracer(tracer trace.Tracer) TracedSessionOption { + return func(c *TracedSessionConfig) { + c.otelConfig.tracer = tracer + } +} + +// ------------------------------------------ Private Functions + +func configure(options ...TracedSessionOption) *TracedSessionConfig { + config := &TracedSessionConfig{ + otelConfig: otelConfiguration(), + instrumentQuery: true, + instrumentBatch: true, + instrumentConnect: true, + } + + for _, apply := range options { + apply(config) + } + + return config +} + +func otelConfiguration() *OtelConfig { + return &OtelConfig{ + tracer: global.Tracer("github.com/gocql/gocql"), + } +} diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go new file mode 100644 index 00000000000..d93c821c1fa --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -0,0 +1,115 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// The Cassandra docker container conatains the +// "gocql-integration-example" keyspace and a single table +// with the following schema: +// gocql_integration_example.book +// id UUID +// title text +// author_first_name text +// author_last_name text +// PRIMARY KEY(id) +// The example will insert fictional books into the database. + +package main + +import ( + "context" + "log" + + "github.com/gocql/gocql" + + otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" + "go.opentelemetry.io/otel/api/global" + traceStdout "go.opentelemetry.io/otel/exporters/trace/stdout" + sdktrace "go.opentelemetry.io/otel/sdk/trace" +) + +func initTracer() { + traceExporter, err := traceStdout.NewExporter(traceStdout.Options{ + PrettyPrint: true, + }) + if err != nil { + log.Fatalf("failed to create span exporter, %v", err) + } + + provider, err := sdktrace.NewProvider( + sdktrace.WithSyncer(traceExporter), + sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), + ) + if err != nil { + log.Fatalf("failed to create trace provider, %v", err) + } + + global.SetTraceProvider(provider) +} + +func getCluster() *gocql.ClusterConfig { + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "gocql_integration_example" + cluster.Consistency = gocql.LocalQuorum + cluster.ProtoVersion = 3 + return cluster +} + +func main() { + initTracer() + + ctx, span := global.Tracer( + "go.opentelemetry.io/contrib/github.com/gocql/gocql/example", + ).Start(context.Background(), "begin example") + + cluster := getCluster() + // Create a session to begin making queries + session, err := otelGocql.NewSessionWithTracing(cluster) + if err != nil { + log.Fatalf("failed to create a session, %v", err) + } + defer session.Close() + + id := gocql.TimeUUID() + if err := session.Query( + "INSERT INTO book (id, title, author_first_name, author_last_name) VALUES (?, ?, ?, ?)", + id, + "Example Book 1", + "firstName", + "lastName", + ).WithContext(ctx).Exec(); err != nil { + log.Fatalf("failed to insert data, %v", err) + } + + res := session.Query( + "SELECT title, author_first_name, author_last_name from book WHERE id = ?", + id, + ).WithContext(ctx).Iter() + + var ( + title string + firstName string + lastName string + ) + + res.Scan(&title, &firstName, &lastName) + + log.Printf("Found Book {id: %s, title: %s, Name: %s, %s}", id, title, lastName, firstName) + + res.Close() + + if err = session.Query("DELETE FROM book WHERE id = ?", id).WithContext(ctx).Exec(); err != nil { + log.Fatalf("failed to delete data, %v", err) + } + + span.End() +} diff --git a/instrumentation/github.com/gocql/gocql/example/docker-compose.yml b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml new file mode 100644 index 00000000000..8ee0e0b324c --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml @@ -0,0 +1,21 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +version: '3' +services: + cassandra: + image: cassandra:latest + ports: + - 9042:9042 + - 9160:9160 \ No newline at end of file diff --git a/instrumentation/github.com/gocql/gocql/example/go.mod b/instrumentation/github.com/gocql/gocql/example/go.mod new file mode 100644 index 00000000000..558a0a90fd8 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/go.mod @@ -0,0 +1,12 @@ +module go.opentelemetry.io/contrib/github.com/gocql/gocql/example + +go 1.14 + +require ( + github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e + go.opentelemetry.io/contrib/github.com/gocql/gocql v0.0.0 + go.opentelemetry.io/otel v0.7.0 +) + +// TODO: remove +replace go.opentelemetry.io/contrib/github.com/gocql/gocql => ../ diff --git a/instrumentation/github.com/gocql/gocql/example/go.sum b/instrumentation/github.com/gocql/gocql/example/go.sum new file mode 100644 index 00000000000..fa12e03ce19 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/go.sum @@ -0,0 +1,114 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7 h1:qELHH0AWCvf98Yf+CNIJx9vOZOfHFDDzgDRYsnNk/vs= +github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60= +github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= +github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e h1:SroDcndcOU9BVAduPf/PXihXoR2ZYTQYLXbupbqxAyQ= +github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +go.opentelemetry.io/contrib v0.7.0 h1:6IuKhaeEk+uxX5icJCdsgqlDVbsbDEPFD6NcHCDp9QI= +go.opentelemetry.io/contrib v0.7.0/go.mod h1:g4BXWOrb66AyXbXlSgfGWR7TQzXQX4Oq2NidBrSwZPM= +go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0= +go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 h1:MRHtG0U6SnaUb+s+LhNE1qt1FQ1wlhqr5E4usBKC0uA= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/instrumentation/github.com/gocql/gocql/go.mod b/instrumentation/github.com/gocql/gocql/go.mod new file mode 100644 index 00000000000..ef1c3c4fa56 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/go.mod @@ -0,0 +1,11 @@ +module go.opentelemetry.io/contrib/github.com/gocql/gocql + +go 1.14 + +require ( + github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e + github.com/stretchr/testify v1.6.1 + go.opentelemetry.io/contrib v0.7.0 + go.opentelemetry.io/otel v0.7.0 + google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 // indirect +) diff --git a/instrumentation/github.com/gocql/gocql/go.sum b/instrumentation/github.com/gocql/gocql/go.sum new file mode 100644 index 00000000000..35331c8727d --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/go.sum @@ -0,0 +1,120 @@ +cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7 h1:qELHH0AWCvf98Yf+CNIJx9vOZOfHFDDzgDRYsnNk/vs= +github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60= +github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= +github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= +github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e h1:SroDcndcOU9BVAduPf/PXihXoR2ZYTQYLXbupbqxAyQ= +github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= +github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +go.opentelemetry.io/contrib v0.7.0 h1:6IuKhaeEk+uxX5icJCdsgqlDVbsbDEPFD6NcHCDp9QI= +go.opentelemetry.io/contrib v0.7.0/go.mod h1:g4BXWOrb66AyXbXlSgfGWR7TQzXQX4Oq2NidBrSwZPM= +go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0= +go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 h1:4HYDjxeNXAOTv3o1N2tjo8UUSlhQgAD52FVkwxnWgM8= +google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 h1:MRHtG0U6SnaUb+s+LhNE1qt1FQ1wlhqr5E4usBKC0uA= +google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.30.0 h1:M5a8xTlYTxwMn5ZFkwhRabsygDY5G8TYLyQDBxJNAxE= +google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/instrumentation/github.com/gocql/gocql/gocql.go b/instrumentation/github.com/gocql/gocql/gocql.go new file mode 100644 index 00000000000..8176c50b1a3 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/gocql.go @@ -0,0 +1,39 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import "github.com/gocql/gocql" + +// NewSessionWithTracing creates a new session using the given cluster +// configuration enabling tracing for queries, batch queries, and connection attempts. +// You may use additional observers and disable specific tracing using the provided `TracedSessionOption`s. +func NewSessionWithTracing(cluster *gocql.ClusterConfig, options ...TracedSessionOption) (*gocql.Session, error) { + config := configure(options...) + otelConfig := config.otelConfig + + if config.instrumentQuery { + cluster.QueryObserver = NewQueryObserver(config.queryObserver, otelConfig.tracer) + } + + if config.instrumentBatch { + cluster.BatchObserver = NewBatchObserver(config.batchObserver, otelConfig.tracer) + } + + if config.instrumentConnect { + cluster.ConnectObserver = NewConnectObserver(config.connectObserver, otelConfig.tracer) + } + + return cluster.CreateSession() +} diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go new file mode 100644 index 00000000000..46ad4f233bc --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -0,0 +1,234 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import ( + "context" + "fmt" + "log" + "os" + "strings" + "testing" + + "github.com/gocql/gocql" + "github.com/stretchr/testify/assert" + mocktracer "go.opentelemetry.io/contrib/internal/trace" +) + +const ( + keyspace string = "gotest" + tableName string = "test_table" +) + +type mockConnectObserver struct { + callCount int +} + +func (m *mockConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { + m.callCount++ +} + +func TestQuery(t *testing.T) { + defer afterEach() + cluster := getCluster() + tracer := mocktracer.NewTracer("gocql-test") + connectObserver := &mockConnectObserver{} + + session, err := NewSessionWithTracing( + cluster, + WithTracer(tracer), + WithConnectObserver(connectObserver), + ) + assert.NoError(t, err) + defer session.Close() + + ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") + + id := gocql.TimeUUID() + title := "example-title" + insertStmt := fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) + query := session.Query(insertStmt, id, title).WithContext(ctx) + assert.NotNil(t, query, "expected query to not be nil") + if err := query.Exec(); err != nil { + t.Fatal(err.Error()) + } + + parentSpan.End() + + // Get the spans and ensure that they are child spans to the local parent + spans := tracer.EndedSpans() + + // Collect all the connection spans + numberOfConnections := connectObserver.callCount + // there should be numberOfConnections + 1 Query + 1 Batch spans + assert.Equal(t, numberOfConnections+2, len(spans)) + assert.Greater(t, numberOfConnections, 0, "at least one connection needs to have been made") + + // Verify attributes are correctly added to the spans. Omit the one local span + for _, span := range spans[0 : len(spans)-1] { + + switch span.Name { + case cassQueryName: + assert.Equal(t, insertStmt, span.Attributes[CassStatementKey].AsString()) + assert.Equal(t, parentSpan.SpanContext().SpanID.String(), span.ParentSpanID.String()) + break + case cassConnectName: + numberOfConnections-- + default: + t.Fatalf("unexpected span name %s", span.Name) + } + assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) + } + + assert.Equal(t, 0, numberOfConnections) + +} + +func TestBatch(t *testing.T) { + defer afterEach() + cluster := getCluster() + tracer := mocktracer.NewTracer("gocql-test") + + session, err := NewSessionWithTracing( + cluster, + WithTracer(tracer), + WithConnectInstrumentation(false), + ) + assert.NoError(t, err) + defer session.Close() + + ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") + + batch := session.NewBatch(gocql.LoggedBatch).WithContext(ctx) + ids := make([]gocql.UUID, 10) + stmts := make([]string, 10) + for i := 0; i < 10; i++ { + ids[i] = gocql.TimeUUID() + title := fmt.Sprintf("batch-title-%d", i) + stmts[i] = fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) + batch.Query(stmts[i], ids[i], title) + } + + err = session.ExecuteBatch(batch) + assert.NoError(t, err) + + parentSpan.End() + + spans := tracer.EndedSpans() + assert.Equal(t, 2, len(spans)) + span := spans[0] + + assert.Equal(t, cassBatchQueryName, span.Name) + assert.Equal(t, parentSpan.SpanContext().SpanID, span.ParentSpanID) + assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) + assert.Equal(t, stmts, span.Attributes[CassBatchStatementsKey].AsArray()) + +} + +func TestConnection(t *testing.T) { + defer afterEach() + cluster := getCluster() + tracer := mocktracer.NewTracer("gocql-test") + + session, err := NewSessionWithTracing(cluster, WithTracer(tracer)) + assert.NoError(t, err) + defer session.Close() + + spans := tracer.EndedSpans() + + for _, span := range spans { + assert.Equal(t, cassConnectName, span.Name) + assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) + } +} + +// getCluster creates a gocql ClusterConfig with the appropriate +// settings for test cases. +func getCluster() *gocql.ClusterConfig { + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = keyspace + cluster.Consistency = gocql.LocalQuorum + cluster.NumConns = 1 + return cluster +} + +// initDb recreates the testing keyspace so that a new table +// can be created. This allows the test to be run multiple times +// consecutively withouth any issues arising. +func beforeAll() { + cluster := gocql.NewCluster("localhost") + cluster.Consistency = gocql.LocalQuorum + cluster.Keyspace = "system" + + session, err := cluster.CreateSession() + if err != nil { + log.Fatalf("failed to connect to database during beforeAll, %v", err) + } + + err = session.Query( + fmt.Sprintf( + "create keyspace if not exists %s with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", + keyspace, + ), + ).Exec() + if err != nil { + log.Fatal(err) + } + + cluster.Keyspace = keyspace + session, err = cluster.CreateSession() + if err != nil { + log.Fatal(err) + } + + err = session.Query( + fmt.Sprintf("create table if not exists %s(id UUID, title text, PRIMARY KEY(id))", tableName), + ).Exec() + if err != nil { + log.Fatal(err) + } +} + +// cleanup removes the keyspace from the database for later test sessions. +func afterEach() { + cluster := gocql.NewCluster("localhost") + cluster.Consistency = gocql.LocalQuorum + cluster.Keyspace = keyspace + session, err := cluster.CreateSession() + if err != nil { + log.Fatalf("failed to connect to database during afterEach, %v", err) + } + if err = session.Query(fmt.Sprintf("truncate table %s", tableName)).Exec(); err != nil { + log.Fatalf("failed to truncate table, %v", err) + } +} + +func TestMain(m *testing.M) { + if _, present := os.LookupEnv("INTEGRATION"); !present { + log.Print("--- SKIP: to enable integration test, set the INTEGRATION environment variable") + os.Exit(0) + } + beforeAll() + os.Exit(m.Run()) +} diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go new file mode 100644 index 00000000000..9103474d5d3 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -0,0 +1,170 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import ( + "context" + "strings" + + "github.com/gocql/gocql" + "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/api/trace" +) + +// OtelQueryObserver implements the gocql.QueryObserver interface +// to provide instrumentation to gocql queries. +type OtelQueryObserver struct { + observer gocql.QueryObserver + tracer trace.Tracer +} + +// OtelBatchObserver implements the gocql.BatchObserver interface +// to provide instrumentation to gocql batch queries. +type OtelBatchObserver struct { + observer gocql.BatchObserver + tracer trace.Tracer +} + +// OtelConnectObserver implements the gocql.ConnectObserver interface +// to provide instrumentation to connection attempts made by the session. +type OtelConnectObserver struct { + observer gocql.ConnectObserver + tracer trace.Tracer +} + +// ----------------------------------------- Constructor Functions + +// NewQueryObserver creates a QueryObserver that provides OpenTelemetry +// tracing and metrics. +func NewQueryObserver(observer gocql.QueryObserver, tracer trace.Tracer) gocql.QueryObserver { + return &OtelQueryObserver{ + observer, + tracer, + } +} + +// NewBatchObserver creates a BatchObserver that provides OpenTelemetry instrumentation for +// batch queries. +func NewBatchObserver(observer gocql.BatchObserver, tracer trace.Tracer) gocql.BatchObserver { + return &OtelBatchObserver{ + observer, + tracer, + } +} + +// NewConnectObserver creates a ConnectObserver that provides OpenTelemetry instrumentation for +// connection attempts. +func NewConnectObserver(observer gocql.ConnectObserver, tracer trace.Tracer) gocql.ConnectObserver { + return &OtelConnectObserver{ + observer, + tracer, + } +} + +// ------------------------------------------ Observer Functions + +// ObserveQuery instruments a specific query. +func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { + attributes := append( + defaultAttributes(observedQuery.Host), + CassStatement(observedQuery.Statement), + ) + + if observedQuery.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedQuery.Err.Error()), + ) + } + + ctx, span := o.tracer.Start( + ctx, + cassQueryName, + trace.WithStartTime(observedQuery.Start), + trace.WithAttributes(attributes...), + ) + + span.End(trace.WithEndTime(observedQuery.End)) + + if o.observer != nil { + o.observer.ObserveQuery(ctx, observedQuery) + } +} + +// ObserveBatch instruments a specific batch query. +func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { + attributes := append( + defaultAttributes(observedBatch.Host), + CassBatchStatements(observedBatch.Statements), + ) + + if observedBatch.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedBatch.Err.Error()), + ) + } + + ctx, span := o.tracer.Start( + ctx, + cassBatchQueryName, + trace.WithStartTime(observedBatch.Start), + trace.WithAttributes(attributes...), + ) + + span.End(trace.WithEndTime(observedBatch.End)) + + if o.observer != nil { + o.observer.ObserveBatch(ctx, observedBatch) + } +} + +// ObserveConnect instruments a specific connection attempt. +func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { + attributes := defaultAttributes(observedConnect.Host) + + if observedConnect.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedConnect.Err.Error()), + ) + } + + _, span := o.tracer.Start( + // TODO: fix the context issue + context.TODO(), + cassConnectName, + trace.WithStartTime(observedConnect.Start), + trace.WithAttributes(attributes...), + ) + + span.End(trace.WithEndTime(observedConnect.End)) + + if o.observer != nil { + o.observer.ObserveConnect(observedConnect) + } +} + +// ------------------------------------------ Private Functions + +func defaultAttributes(host *gocql.HostInfo) []kv.KeyValue { + hostnameAndPort := host.HostnameAndPort() + return []kv.KeyValue{ + CassVersion(host.Version().String()), + CassHost(hostnameAndPort[0:strings.Index(hostnameAndPort, ":")]), + CassPort(host.Port()), + CassHostState(host.State().String()), + } +} From 577daf4c83041cdfdbf07e200d954dc12d5131ee Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Mon, 13 Jul 2020 16:47:46 +0000 Subject: [PATCH 02/24] began adding metric instrumentation --- .../github.com/gocql/gocql/gocql_test.go | 2 +- .../github.com/gocql/gocql/instrument.go | 61 +++++++++++++++++++ .../github.com/gocql/gocql/observer.go | 15 ++++- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 instrumentation/github.com/gocql/gocql/instrument.go diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 46ad4f233bc..10b5d20cdd4 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -173,7 +173,7 @@ func getCluster() *gocql.ClusterConfig { return cluster } -// initDb recreates the testing keyspace so that a new table +// beforeAll recreates the testing keyspace so that a new table // can be created. This allows the test to be run multiple times // consecutively withouth any issues arising. func beforeAll() { diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go new file mode 100644 index 00000000000..3a49188407b --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -0,0 +1,61 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package gocql + +import ( + "context" + "log" + + "go.opentelemetry.io/otel/api/global" + "go.opentelemetry.io/otel/api/metric" +) + +var ( + // Query + iQueryCount metric.Int64Counter + iQueryErrors metric.Int64Counter + + // Batch + iBatchCount metric.Int64Counter + iBatchErrors metric.Int64Counter + + // Connections + iConnectionCount metric.Int64Counter + iConnectErrors metric.Int64Counter + + iLatency metric.Int64ValueRecorder +) + +func init() { + defer func() { + if recovered := recover(); recovered != nil { + log.Print("failed to create meter. metrics are not being recorded") + } + }() + meter := metric.Must(global.Meter("github.com/gocql/gocql")) + + iQueryCount = meter.NewInt64Counter("cassandra.queries") + iQueryErrors = meter.NewInt64Counter("cassandra.query_errors") + + iBatchCount = meter.NewInt64Counter("cassandra.batch_queries") + iBatchErrors = meter.NewInt64Counter("cassandra.batch_errors") + + iConnectionCount = meter.NewInt64Counter("cassandra.connections") + iConnectErrors = meter.NewInt64Counter("cassandra.connect_errors") +} + +func countQuery(ctx context.Context, stmt string) { + iQueryCount.Add(ctx, 1, CassStatement(stmt)) +} diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 9103474d5d3..01529911909 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -87,6 +87,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq attributes, CassErrMsg(observedQuery.Err.Error()), ) + iQueryErrors.Add(ctx, 1) } ctx, span := o.tracer.Start( @@ -98,6 +99,8 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq span.End(trace.WithEndTime(observedQuery.End)) + iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) + if o.observer != nil { o.observer.ObserveQuery(ctx, observedQuery) } @@ -115,6 +118,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq attributes, CassErrMsg(observedBatch.Err.Error()), ) + iBatchErrors.Add(ctx, 1) } ctx, span := o.tracer.Start( @@ -126,6 +130,8 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq span.End(trace.WithEndTime(observedBatch.End)) + iBatchCount.Add(ctx, 1, CassBatchStatements(observedBatch.Statements)) + if o.observer != nil { o.observer.ObserveBatch(ctx, observedBatch) } @@ -133,6 +139,8 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq // ObserveConnect instruments a specific connection attempt. func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { + // TODO: fix context issue + ctx := context.TODO() attributes := defaultAttributes(observedConnect.Host) if observedConnect.Err != nil { @@ -140,11 +148,11 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne attributes, CassErrMsg(observedConnect.Err.Error()), ) + iConnectErrors.Add(ctx, 1) } _, span := o.tracer.Start( - // TODO: fix the context issue - context.TODO(), + ctx, cassConnectName, trace.WithStartTime(observedConnect.Start), trace.WithAttributes(attributes...), @@ -152,6 +160,9 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne span.End(trace.WithEndTime(observedConnect.End)) + host := observedConnect.Host.HostnameAndPort() + iConnectionCount.Add(ctx, 1, CassHostKey.String(host)) + if o.observer != nil { o.observer.ObserveConnect(observedConnect) } From 0a41bc331b9151c7a9710023b435dd52e7303fe4 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Tue, 14 Jul 2020 03:47:24 +0000 Subject: [PATCH 03/24] added meter unit tests --- .../github.com/gocql/gocql/gocql_test.go | 167 +++++++++++++++++- .../github.com/gocql/gocql/instrument.go | 14 +- .../github.com/gocql/gocql/observer.go | 3 +- 3 files changed, 176 insertions(+), 8 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 10b5d20cdd4..579409439c4 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -21,10 +21,18 @@ import ( "os" "strings" "testing" + "time" + + "go.opentelemetry.io/otel/sdk/metric/controller/push" + "go.opentelemetry.io/otel/sdk/metric/selector/simple" "github.com/gocql/gocql" "github.com/stretchr/testify/assert" mocktracer "go.opentelemetry.io/contrib/internal/trace" + "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/api/metric" + export "go.opentelemetry.io/otel/sdk/export/metric" + "go.opentelemetry.io/otel/sdk/export/metric/aggregation" ) const ( @@ -32,6 +40,43 @@ const ( tableName string = "test_table" ) +var exporter *mockExporter + +// mockExporter provides an exporter to access metrics +// used for testing puporses only. +type mockExporter struct { + t *testing.T + records []export.Record +} + +func (mockExporter) ExportKindFor(*metric.Descriptor, aggregation.Kind) export.ExportKind { + return export.PassThroughExporter +} + +func (e *mockExporter) Export(_ context.Context, set export.CheckpointSet) error { + if err := set.ForEach(e, func(record export.Record) error { + e.records = append(e.records, record) + return nil + }); err != nil { + e.t.Fatal(err) + return err + } + return nil +} + +// mockExportPipeline returns a push controller with a mockExporter. +func mockExportPipeline(t *testing.T) *push.Controller { + var records []export.Record + exporter = &mockExporter{t, records} + controller := push.New( + simple.NewWithExactDistribution(), + exporter, + push.WithPeriod(1*time.Second), + ) + controller.Start() + return controller +} + type mockConnectObserver struct { callCount int } @@ -40,7 +85,15 @@ func (m *mockConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne m.callCount++ } +type testRecord struct { + Name string + MeterName string + Labels []kv.KeyValue + Number metric.Number +} + func TestQuery(t *testing.T) { + controller := getController(t) defer afterEach() cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") @@ -94,12 +147,55 @@ func TestQuery(t *testing.T) { assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) } - assert.Equal(t, 0, numberOfConnections) + // Check metrics + controller.Stop() + + assert.Equal(t, 3, len(exporter.records)) + expected := []testRecord{ + testRecord{ + Name: "cassandra.connections", + MeterName: "github.com/gocql/gocql", + // TODO: Labels + Number: 3, + }, + testRecord{ + Name: "cassandra.queries", + MeterName: "github.com/gocql/gocql", + // TODO: Labels + Number: 1, + }, + testRecord{ + Name: "cassandra.rows", + MeterName: "github.com/gocql/gocql", + Number: 0, + }, + } + + for _, record := range exporter.records { + name := record.Descriptor().Name() + agg := record.Aggregation() + switch name { + case "cassandra.connections": + recordEqual(t, expected[0], record) + numberEqual(t, expected[0].Number, agg) + case "cassandra.queries": + recordEqual(t, expected[1], record) + numberEqual(t, expected[1].Number, agg) + break + case "cassandra.rows": + recordEqual(t, expected[2], record) + numberEqual(t, expected[2].Number, agg) + default: + t.Fatalf("wrong metric %s", name) + } + } + } func TestBatch(t *testing.T) { + controller := getController(t) defer afterEach() cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") @@ -141,6 +237,30 @@ func TestBatch(t *testing.T) { assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) assert.Equal(t, stmts, span.Attributes[CassBatchStatementsKey].AsArray()) + controller.Stop() + + assert.Equal(t, 1, len(exporter.records)) + expected := []testRecord{ + testRecord{ + Name: "cassandra.batch_queries", + MeterName: "github.com/gocql/gocql", + // TODO: Labels + Number: 1, + }, + } + + for _, record := range exporter.records { + name := record.Descriptor().Name() + agg := record.Aggregation() + switch name { + case "cassandra.batch_queries": + recordEqual(t, expected[0], record) + numberEqual(t, expected[0].Number, agg) + default: + t.Fatalf("wrong metric %s", name) + } + } + } func TestConnection(t *testing.T) { @@ -173,6 +293,49 @@ func getCluster() *gocql.ClusterConfig { return cluster } +// beforeEach creates a metric export pipeline with mockExporter +// to enable testing metric collection. +func getController(t *testing.T) *push.Controller { + controller := mockExportPipeline(t) + InstrumentWithProvider(controller.Provider()) + return controller +} + +// recordEqual checks that the given metric name and instrumentation names are equal. +func recordEqual(t *testing.T, expected testRecord, actual export.Record) { + descriptor := actual.Descriptor() + assert.Equal(t, expected.Name, descriptor.Name()) + assert.Equal(t, expected.MeterName, descriptor.InstrumentationName()) +} + +func numberEqual(t *testing.T, expected metric.Number, agg aggregation.Aggregation) { + kind := agg.Kind() + switch kind { + case aggregation.SumKind: + if sum, ok := agg.(aggregation.Sum); !ok { + t.Fatal("missing sum value") + } else { + if num, err := sum.Sum(); err == nil { + assert.Equal(t, expected, num) + } else { + t.Fatal("missing value") + } + } + case aggregation.ExactKind: + if mmsc, ok := agg.(aggregation.MinMaxSumCount); !ok { + t.Fatal("missing aggregation") + } else { + if max, err := mmsc.Max(); err == nil { + assert.Equal(t, expected, max) + } else { + t.Fatal("missing sum") + } + } + default: + t.Fatalf("unexpected kind %s", kind) + } +} + // beforeAll recreates the testing keyspace so that a new table // can be created. This allows the test to be run multiple times // consecutively withouth any issues arising. @@ -210,7 +373,7 @@ func beforeAll() { } } -// cleanup removes the keyspace from the database for later test sessions. +// afterEach removes the keyspace from the database for later test sessions. func afterEach() { cluster := gocql.NewCluster("localhost") cluster.Consistency = gocql.LocalQuorum diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index 3a49188407b..65e740e32e7 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -15,10 +15,10 @@ package gocql import ( - "context" "log" "go.opentelemetry.io/otel/api/global" + "go.opentelemetry.io/otel/api/metric" ) @@ -26,6 +26,7 @@ var ( // Query iQueryCount metric.Int64Counter iQueryErrors metric.Int64Counter + iQueryRows metric.Int64ValueRecorder // Batch iBatchCount metric.Int64Counter @@ -38,16 +39,19 @@ var ( iLatency metric.Int64ValueRecorder ) -func init() { +// InstrumentWithProvider will recreate instruments using a meter +// from the given provider p. +func InstrumentWithProvider(p metric.Provider) { defer func() { if recovered := recover(); recovered != nil { log.Print("failed to create meter. metrics are not being recorded") } }() - meter := metric.Must(global.Meter("github.com/gocql/gocql")) + meter := metric.Must(p.Meter("github.com/gocql/gocql")) iQueryCount = meter.NewInt64Counter("cassandra.queries") iQueryErrors = meter.NewInt64Counter("cassandra.query_errors") + iQueryRows = meter.NewInt64ValueRecorder("cassandra.rows") iBatchCount = meter.NewInt64Counter("cassandra.batch_queries") iBatchErrors = meter.NewInt64Counter("cassandra.batch_errors") @@ -56,6 +60,6 @@ func init() { iConnectErrors = meter.NewInt64Counter("cassandra.connect_errors") } -func countQuery(ctx context.Context, stmt string) { - iQueryCount.Add(ctx, 1, CassStatement(stmt)) +func init() { + InstrumentWithProvider(global.MeterProvider()) } diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 01529911909..8ef4b332d3a 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -100,6 +100,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq span.End(trace.WithEndTime(observedQuery.End)) iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) + iQueryRows.Record(ctx, int64(observedQuery.Rows)) if o.observer != nil { o.observer.ObserveQuery(ctx, observedQuery) @@ -130,7 +131,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq span.End(trace.WithEndTime(observedBatch.End)) - iBatchCount.Add(ctx, 1, CassBatchStatements(observedBatch.Statements)) + iBatchCount.Add(ctx, 1) if o.observer != nil { o.observer.ObserveBatch(ctx, observedBatch) From f28b50ab9790f8b160c95232228d50b73a9fd53d Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Tue, 14 Jul 2020 08:54:46 -0600 Subject: [PATCH 04/24] example: Update example to export metrics and trace to prometheus and zipkin --- .../github.com/gocql/gocql/example/client.go | 69 ++++++++++-- .../gocql/gocql/example/docker-compose.yml | 14 ++- .../github.com/gocql/gocql/example/go.mod | 4 +- .../github.com/gocql/gocql/example/go.sum | 103 ++++++++++++++++++ .../gocql/gocql/example/prometheus.yml | 23 ++++ 5 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 instrumentation/github.com/gocql/gocql/example/prometheus.yml diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index d93c821c1fa..ee4ed979fc3 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -27,26 +27,68 @@ package main import ( "context" - "log" - "github.com/gocql/gocql" + "log" + "net/http" + "os" + "os/signal" + "sync" otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" "go.opentelemetry.io/otel/api/global" - traceStdout "go.opentelemetry.io/otel/exporters/trace/stdout" + "go.opentelemetry.io/otel/exporters/metric/prometheus" + zipkintrace "go.opentelemetry.io/otel/exporters/trace/zipkin" sdktrace "go.opentelemetry.io/otel/sdk/trace" ) +var logger = log.New(os.Stderr, "zipkin-example", log.Ldate|log.Ltime|log.Llongfile) +var wg sync.WaitGroup + +func initMetrics() { + // Start prometheus + metricExporter, err := prometheus.NewExportPipeline(prometheus.Config{}) + if err != nil { + logger.Fatalf("failed to install metric exporter, %v", err) + } + server := http.Server{Addr: ":2222"} + http.HandleFunc("/", metricExporter.ServeHTTP) + go func() { + defer wg.Done() + wg.Add(1) + log.Print(server.ListenAndServe()) + }() + + // ctrl+c will stop the server gracefully + shutdown := make(chan os.Signal, 1) + signal.Notify(shutdown, os.Interrupt) + go func() { + <-shutdown + if err := server.Shutdown(context.Background()); err != nil { + log.Printf("problem shutting down server, %v", err) + } else { + log.Print("gracefully shutting down server") + } + }() + + otelGocql.InstrumentWithProvider(metricExporter.Provider()) +} + func initTracer() { - traceExporter, err := traceStdout.NewExporter(traceStdout.Options{ - PrettyPrint: true, - }) + traceExporter, err := zipkintrace.NewExporter( + "http://localhost:9411/api/v2/spans", + "zipkin-example", + zipkintrace.WithLogger(logger), + ) if err != nil { - log.Fatalf("failed to create span exporter, %v", err) + log.Fatalf("failed to create span traceExporter, %v", err) } provider, err := sdktrace.NewProvider( - sdktrace.WithSyncer(traceExporter), + sdktrace.WithBatcher( + traceExporter, + sdktrace.WithBatchTimeout(5), + sdktrace.WithMaxExportBatchSize(10), + ), sdktrace.WithConfig(sdktrace.Config{DefaultSampler: sdktrace.AlwaysSample()}), ) if err != nil { @@ -65,6 +107,7 @@ func getCluster() *gocql.ClusterConfig { } func main() { + initMetrics() initTracer() ctx, span := global.Tracer( @@ -73,7 +116,9 @@ func main() { cluster := getCluster() // Create a session to begin making queries - session, err := otelGocql.NewSessionWithTracing(cluster) + session, err := otelGocql.NewSessionWithTracing( + cluster, + ) if err != nil { log.Fatalf("failed to create a session, %v", err) } @@ -87,7 +132,7 @@ func main() { "firstName", "lastName", ).WithContext(ctx).Exec(); err != nil { - log.Fatalf("failed to insert data, %v", err) + log.Printf("failed to insert data, %v", err) } res := session.Query( @@ -108,8 +153,10 @@ func main() { res.Close() if err = session.Query("DELETE FROM book WHERE id = ?", id).WithContext(ctx).Exec(); err != nil { - log.Fatalf("failed to delete data, %v", err) + log.Printf("failed to delete data, %v", err) } span.End() + + wg.Wait() } diff --git a/instrumentation/github.com/gocql/gocql/example/docker-compose.yml b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml index 8ee0e0b324c..f82df2f27f4 100644 --- a/instrumentation/github.com/gocql/gocql/example/docker-compose.yml +++ b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml @@ -14,8 +14,12 @@ version: '3' services: - cassandra: - image: cassandra:latest - ports: - - 9042:9042 - - 9160:9160 \ No newline at end of file +# cassandra: +# image: cassandra:latest +# ports: +# - 9042:9042 +# - 9160:9160 + zipkin: + image: openzipkin/zipkin + ports: + - 9411:9411 \ No newline at end of file diff --git a/instrumentation/github.com/gocql/gocql/example/go.mod b/instrumentation/github.com/gocql/gocql/example/go.mod index 558a0a90fd8..1101fe5d2ba 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.mod +++ b/instrumentation/github.com/gocql/gocql/example/go.mod @@ -5,7 +5,9 @@ go 1.14 require ( github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e go.opentelemetry.io/contrib/github.com/gocql/gocql v0.0.0 - go.opentelemetry.io/otel v0.7.0 + go.opentelemetry.io/otel v0.8.0 + go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0 + go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0 ) // TODO: remove diff --git a/instrumentation/github.com/gocql/gocql/example/go.sum b/instrumentation/github.com/gocql/gocql/example/go.sum index fa12e03ce19..5bd99b870ab 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.sum +++ b/instrumentation/github.com/gocql/gocql/example/go.sum @@ -2,27 +2,53 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7 h1:qELHH0AWCvf98Yf+CNIJx9vOZOfHFDDzgDRYsnNk/vs= github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60= +github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= +github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e h1:SroDcndcOU9BVAduPf/PXihXoR2ZYTQYLXbupbqxAyQ= github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e/go.mod h1:DL0ekTmBSTdlNF25Orwt/JMzqIq3EJ4MVa/J/uK64OY= +github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= @@ -34,6 +60,8 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -42,25 +70,80 @@ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= +github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= +github.com/openzipkin/zipkin-go v0.2.2 h1:nY8Hti+WKaP0cRsSeQ026wU03QsM762XBeCXBb9NAWI= +github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= +github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= +github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA= +github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= +github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/common v0.10.0 h1:RyRA7RzGXQZiW+tGMr7sxa85G1z0yOpM1qq5c8lNawc= +github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8= +github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= go.opentelemetry.io/contrib v0.7.0 h1:6IuKhaeEk+uxX5icJCdsgqlDVbsbDEPFD6NcHCDp9QI= go.opentelemetry.io/contrib v0.7.0/go.mod h1:g4BXWOrb66AyXbXlSgfGWR7TQzXQX4Oq2NidBrSwZPM= go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0= go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo= +go.opentelemetry.io/otel v0.8.0 h1:he/8j/EBlKjENVtDvFalawIUcQ+1E3uHRsvJZWLIa7M= +go.opentelemetry.io/otel v0.8.0/go.mod h1:ckxzUEfk7tAkTwEMVdkllBM+YOfE/K9iwg6zYntFYSg= +go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0 h1:xx6oiW/vBazlT54mPPY0NcIIx6fCvfb8Ouj791KC4XE= +go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0/go.mod h1:pI1yrP+VSHWiXIjUpM8cSVCcJ93wIINZNlD3McNkEvY= +go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0 h1:CcMuR0SK/4OCnDjQleq0WwnSe2/bVQ34r23EubOwioU= +go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0/go.mod h1:ci5ENfbinkRc9aD5EdaR7IbQB1K9R03JXstvfhvdfw4= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -68,14 +151,26 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -91,6 +186,7 @@ google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvx google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 h1:MRHtG0U6SnaUb+s+LhNE1qt1FQ1wlhqr5E4usBKC0uA= google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= @@ -103,11 +199,18 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/instrumentation/github.com/gocql/gocql/example/prometheus.yml b/instrumentation/github.com/gocql/gocql/example/prometheus.yml new file mode 100644 index 00000000000..5d04ef89d67 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/prometheus.yml @@ -0,0 +1,23 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +global: + scrape_interval: 15s # Default is every 1 minute. + +scrape_configs: + - job_name: 'opentelemetry' + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + static_configs: + - targets: ['localhost:9464'] \ No newline at end of file From 1e4bea169f101baa6e3b93ca641de2ad23cd5d0f Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Tue, 14 Jul 2020 20:02:16 +0000 Subject: [PATCH 05/24] Added context to connect observer to allow for connect spans to have parent spans --- .../github.com/gocql/gocql/config.go | 54 +++---- .../github.com/gocql/gocql/gocql.go | 22 ++- .../github.com/gocql/gocql/gocql_test.go | 18 ++- .../github.com/gocql/gocql/observer.go | 143 +++++++++--------- 4 files changed, 122 insertions(+), 115 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index 30931ed01e6..9a1870a42e4 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -23,18 +23,18 @@ import ( // TracedSessionConfig provides configuration for sessions // created with NewSessionWithTracing. type TracedSessionConfig struct { - otelConfig *OtelConfig - queryObserver gocql.QueryObserver - batchObserver gocql.BatchObserver - connectObserver gocql.ConnectObserver - instrumentQuery bool - instrumentBatch bool - instrumentConnect bool + otelConfig *OtelConfig + queryObserver gocql.QueryObserver + batchObserver gocql.BatchObserver + connectObserver gocql.ConnectObserver } // OtelConfig provides OpenTelemetry configuration. type OtelConfig struct { - tracer trace.Tracer + tracer trace.Tracer + instrumentQuery bool + instrumentBatch bool + instrumentConnect bool } // TracedSessionOption is a function type that applies @@ -70,11 +70,22 @@ func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { } } +// ------------------------------------------ Otel Options + +// WithTracer will set tracer to be the tracer used to create spans +// for query, batch query, and connection instrumentation. +// Defaults to global.Tracer("github.com/gocql/gocql"). +func WithTracer(tracer trace.Tracer) TracedSessionOption { + return func(c *TracedSessionConfig) { + c.otelConfig.tracer = tracer + } +} + // WithQueryInstrumentation will enable and disable instrumentation of // queries. Defaults to enabled. func WithQueryInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.instrumentQuery = enabled + cfg.otelConfig.instrumentQuery = enabled } } @@ -82,7 +93,7 @@ func WithQueryInstrumentation(enabled bool) TracedSessionOption { // batch queries. Defaults to enabled. func WithBatchInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.instrumentBatch = enabled + cfg.otelConfig.instrumentBatch = enabled } } @@ -90,18 +101,7 @@ func WithBatchInstrumentation(enabled bool) TracedSessionOption { // connection attempts. Defaults to enabled. func WithConnectInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.instrumentConnect = enabled - } -} - -// ------------------------------------------ Otel Options - -// WithTracer will set tracer to be the tracer used to create spans -// for query, batch query, and connection instrumentation. -// Defaults to global.Tracer("github.com/gocql/gocql"). -func WithTracer(tracer trace.Tracer) TracedSessionOption { - return func(c *TracedSessionConfig) { - c.otelConfig.tracer = tracer + cfg.otelConfig.instrumentConnect = enabled } } @@ -109,10 +109,7 @@ func WithTracer(tracer trace.Tracer) TracedSessionOption { func configure(options ...TracedSessionOption) *TracedSessionConfig { config := &TracedSessionConfig{ - otelConfig: otelConfiguration(), - instrumentQuery: true, - instrumentBatch: true, - instrumentConnect: true, + otelConfig: otelConfiguration(), } for _, apply := range options { @@ -124,6 +121,9 @@ func configure(options ...TracedSessionOption) *TracedSessionConfig { func otelConfiguration() *OtelConfig { return &OtelConfig{ - tracer: global.Tracer("github.com/gocql/gocql"), + tracer: global.Tracer("github.com/gocql/gocql"), + instrumentQuery: true, + instrumentBatch: true, + instrumentConnect: true, } } diff --git a/instrumentation/github.com/gocql/gocql/gocql.go b/instrumentation/github.com/gocql/gocql/gocql.go index 8176c50b1a3..1e8a59ffc5a 100644 --- a/instrumentation/github.com/gocql/gocql/gocql.go +++ b/instrumentation/github.com/gocql/gocql/gocql.go @@ -14,26 +14,22 @@ package gocql -import "github.com/gocql/gocql" +import ( + "context" + + "github.com/gocql/gocql" +) // NewSessionWithTracing creates a new session using the given cluster // configuration enabling tracing for queries, batch queries, and connection attempts. // You may use additional observers and disable specific tracing using the provided `TracedSessionOption`s. -func NewSessionWithTracing(cluster *gocql.ClusterConfig, options ...TracedSessionOption) (*gocql.Session, error) { +func NewSessionWithTracing(ctx context.Context, cluster *gocql.ClusterConfig, options ...TracedSessionOption) (*gocql.Session, error) { config := configure(options...) otelConfig := config.otelConfig - if config.instrumentQuery { - cluster.QueryObserver = NewQueryObserver(config.queryObserver, otelConfig.tracer) - } - - if config.instrumentBatch { - cluster.BatchObserver = NewBatchObserver(config.batchObserver, otelConfig.tracer) - } - - if config.instrumentConnect { - cluster.ConnectObserver = NewConnectObserver(config.connectObserver, otelConfig.tracer) - } + cluster.QueryObserver = NewQueryObserver(config.queryObserver, otelConfig) + cluster.BatchObserver = NewBatchObserver(config.batchObserver, otelConfig) + cluster.ConnectObserver = NewConnectObserver(ctx, config.connectObserver, otelConfig) return cluster.CreateSession() } diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 579409439c4..7f20c6c1800 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -99,7 +99,10 @@ func TestQuery(t *testing.T) { tracer := mocktracer.NewTracer("gocql-test") connectObserver := &mockConnectObserver{} + ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") + session, err := NewSessionWithTracing( + ctx, cluster, WithTracer(tracer), WithConnectObserver(connectObserver), @@ -107,8 +110,6 @@ func TestQuery(t *testing.T) { assert.NoError(t, err) defer session.Close() - ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") - id := gocql.TimeUUID() title := "example-title" insertStmt := fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) @@ -200,7 +201,10 @@ func TestBatch(t *testing.T) { cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") + ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") + session, err := NewSessionWithTracing( + ctx, cluster, WithTracer(tracer), WithConnectInstrumentation(false), @@ -208,8 +212,6 @@ func TestBatch(t *testing.T) { assert.NoError(t, err) defer session.Close() - ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") - batch := session.NewBatch(gocql.LoggedBatch).WithContext(ctx) ids := make([]gocql.UUID, 10) stmts := make([]string, 10) @@ -268,7 +270,11 @@ func TestConnection(t *testing.T) { cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") - session, err := NewSessionWithTracing(cluster, WithTracer(tracer)) + session, err := NewSessionWithTracing( + context.Background(), + cluster, + WithTracer(tracer), + ) assert.NoError(t, err) defer session.Close() @@ -389,7 +395,7 @@ func afterEach() { func TestMain(m *testing.M) { if _, present := os.LookupEnv("INTEGRATION"); !present { - log.Print("--- SKIP: to enable integration test, set the INTEGRATION environment variable") + fmt.Println("--- SKIP: to enable integration test, set the INTEGRATION environment variable") os.Exit(0) } beforeAll() diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 8ef4b332d3a..f451802d4f8 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -27,49 +27,51 @@ import ( // to provide instrumentation to gocql queries. type OtelQueryObserver struct { observer gocql.QueryObserver - tracer trace.Tracer + cfg *OtelConfig } // OtelBatchObserver implements the gocql.BatchObserver interface // to provide instrumentation to gocql batch queries. type OtelBatchObserver struct { observer gocql.BatchObserver - tracer trace.Tracer + cfg *OtelConfig } // OtelConnectObserver implements the gocql.ConnectObserver interface // to provide instrumentation to connection attempts made by the session. type OtelConnectObserver struct { observer gocql.ConnectObserver - tracer trace.Tracer + cfg *OtelConfig + ctx context.Context } // ----------------------------------------- Constructor Functions // NewQueryObserver creates a QueryObserver that provides OpenTelemetry // tracing and metrics. -func NewQueryObserver(observer gocql.QueryObserver, tracer trace.Tracer) gocql.QueryObserver { +func NewQueryObserver(observer gocql.QueryObserver, cfg *OtelConfig) gocql.QueryObserver { return &OtelQueryObserver{ observer, - tracer, + cfg, } } // NewBatchObserver creates a BatchObserver that provides OpenTelemetry instrumentation for // batch queries. -func NewBatchObserver(observer gocql.BatchObserver, tracer trace.Tracer) gocql.BatchObserver { +func NewBatchObserver(observer gocql.BatchObserver, cfg *OtelConfig) gocql.BatchObserver { return &OtelBatchObserver{ observer, - tracer, + cfg, } } // NewConnectObserver creates a ConnectObserver that provides OpenTelemetry instrumentation for // connection attempts. -func NewConnectObserver(observer gocql.ConnectObserver, tracer trace.Tracer) gocql.ConnectObserver { +func NewConnectObserver(ctx context.Context, observer gocql.ConnectObserver, cfg *OtelConfig) gocql.ConnectObserver { return &OtelConnectObserver{ observer, - tracer, + cfg, + ctx, } } @@ -77,31 +79,32 @@ func NewConnectObserver(observer gocql.ConnectObserver, tracer trace.Tracer) goc // ObserveQuery instruments a specific query. func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { - attributes := append( - defaultAttributes(observedQuery.Host), - CassStatement(observedQuery.Statement), - ) - - if observedQuery.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedQuery.Err.Error()), + if o.cfg.instrumentQuery { + attributes := append( + defaultAttributes(observedQuery.Host), + CassStatement(observedQuery.Statement), ) - iQueryErrors.Add(ctx, 1) - } - - ctx, span := o.tracer.Start( - ctx, - cassQueryName, - trace.WithStartTime(observedQuery.Start), - trace.WithAttributes(attributes...), - ) - span.End(trace.WithEndTime(observedQuery.End)) + if observedQuery.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedQuery.Err.Error()), + ) + iQueryErrors.Add(ctx, 1) + } + + ctx, span := o.cfg.tracer.Start( + ctx, + cassQueryName, + trace.WithStartTime(observedQuery.Start), + trace.WithAttributes(attributes...), + ) - iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) - iQueryRows.Record(ctx, int64(observedQuery.Rows)) + span.End(trace.WithEndTime(observedQuery.End)) + iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) + iQueryRows.Record(ctx, int64(observedQuery.Rows)) + } if o.observer != nil { o.observer.ObserveQuery(ctx, observedQuery) } @@ -109,29 +112,31 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq // ObserveBatch instruments a specific batch query. func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { - attributes := append( - defaultAttributes(observedBatch.Host), - CassBatchStatements(observedBatch.Statements), - ) - - if observedBatch.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedBatch.Err.Error()), + if o.cfg.instrumentBatch { + attributes := append( + defaultAttributes(observedBatch.Host), + CassBatchStatements(observedBatch.Statements), ) - iBatchErrors.Add(ctx, 1) - } - ctx, span := o.tracer.Start( - ctx, - cassBatchQueryName, - trace.WithStartTime(observedBatch.Start), - trace.WithAttributes(attributes...), - ) + if observedBatch.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedBatch.Err.Error()), + ) + iBatchErrors.Add(ctx, 1) + } + + ctx, span := o.cfg.tracer.Start( + ctx, + cassBatchQueryName, + trace.WithStartTime(observedBatch.Start), + trace.WithAttributes(attributes...), + ) - span.End(trace.WithEndTime(observedBatch.End)) + span.End(trace.WithEndTime(observedBatch.End)) - iBatchCount.Add(ctx, 1) + iBatchCount.Add(ctx, 1) + } if o.observer != nil { o.observer.ObserveBatch(ctx, observedBatch) @@ -140,29 +145,29 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq // ObserveConnect instruments a specific connection attempt. func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { - // TODO: fix context issue - ctx := context.TODO() - attributes := defaultAttributes(observedConnect.Host) - - if observedConnect.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedConnect.Err.Error()), + if o.cfg.instrumentConnect { + attributes := defaultAttributes(observedConnect.Host) + + if observedConnect.Err != nil { + attributes = append( + attributes, + CassErrMsg(observedConnect.Err.Error()), + ) + iConnectErrors.Add(o.ctx, 1) + } + + _, span := o.cfg.tracer.Start( + o.ctx, + cassConnectName, + trace.WithStartTime(observedConnect.Start), + trace.WithAttributes(attributes...), ) - iConnectErrors.Add(ctx, 1) - } - _, span := o.tracer.Start( - ctx, - cassConnectName, - trace.WithStartTime(observedConnect.Start), - trace.WithAttributes(attributes...), - ) - - span.End(trace.WithEndTime(observedConnect.End)) + span.End(trace.WithEndTime(observedConnect.End)) - host := observedConnect.Host.HostnameAndPort() - iConnectionCount.Add(ctx, 1, CassHostKey.String(host)) + host := observedConnect.Host.HostnameAndPort() + iConnectionCount.Add(o.ctx, 1, CassHostKey.String(host)) + } if o.observer != nil { o.observer.ObserveConnect(observedConnect) From 4d82bcea736f96e11f411680ac6b9eabdc649526 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Tue, 14 Jul 2020 20:13:54 +0000 Subject: [PATCH 06/24] updated example to use a batched query --- .../github.com/gocql/gocql/example/client.go | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index ee4ed979fc3..ae6cb47dc4e 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -27,13 +27,15 @@ package main import ( "context" - "github.com/gocql/gocql" + "fmt" "log" "net/http" "os" "os/signal" "sync" + "github.com/gocql/gocql" + otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/exporters/metric/prometheus" @@ -41,14 +43,13 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" ) -var logger = log.New(os.Stderr, "zipkin-example", log.Ldate|log.Ltime|log.Llongfile) var wg sync.WaitGroup func initMetrics() { // Start prometheus metricExporter, err := prometheus.NewExportPipeline(prometheus.Config{}) if err != nil { - logger.Fatalf("failed to install metric exporter, %v", err) + log.Fatalf("failed to install metric exporter, %v", err) } server := http.Server{Addr: ":2222"} http.HandleFunc("/", metricExporter.ServeHTTP) @@ -77,7 +78,6 @@ func initTracer() { traceExporter, err := zipkintrace.NewExporter( "http://localhost:9411/api/v2/spans", "zipkin-example", - zipkintrace.WithLogger(logger), ) if err != nil { log.Fatalf("failed to create span traceExporter, %v", err) @@ -117,6 +117,7 @@ func main() { cluster := getCluster() // Create a session to begin making queries session, err := otelGocql.NewSessionWithTracing( + ctx, cluster, ) if err != nil { @@ -124,21 +125,24 @@ func main() { } defer session.Close() - id := gocql.TimeUUID() - if err := session.Query( - "INSERT INTO book (id, title, author_first_name, author_last_name) VALUES (?, ?, ?, ?)", - id, - "Example Book 1", - "firstName", - "lastName", - ).WithContext(ctx).Exec(); err != nil { - log.Printf("failed to insert data, %v", err) + batch := session.NewBatch(gocql.LoggedBatch) + for i := 0; i < 500; i++ { + batch.Query( + "INSERT INTO book (id, title, author_first_name, author_last_name) VALUES (?, ?, ?, ?)", + gocql.TimeUUID(), + fmt.Sprintf("Example Book %d", i), + "firstName", + "lastName", + ) + } + if err := session.ExecuteBatch(batch.WithContext(ctx)); err != nil { + log.Printf("failed to batch insert, %v", err) } res := session.Query( - "SELECT title, author_first_name, author_last_name from book WHERE id = ?", - id, - ).WithContext(ctx).Iter() + "SELECT title, author_first_name, author_last_name from book WHERE author_last_name = ?", + "lastName", + ).WithContext(ctx).PageSize(100).Iter() var ( title string @@ -146,13 +150,13 @@ func main() { lastName string ) - res.Scan(&title, &firstName, &lastName) - - log.Printf("Found Book {id: %s, title: %s, Name: %s, %s}", id, title, lastName, firstName) + for res.Scan(&title, &firstName, &lastName) { + res.Scan(&title, &firstName, &lastName) + } res.Close() - if err = session.Query("DELETE FROM book WHERE id = ?", id).WithContext(ctx).Exec(); err != nil { + if err = session.Query("truncate table book").WithContext(ctx).Exec(); err != nil { log.Printf("failed to delete data, %v", err) } From 5e327be075d5dfbfd71b8cdffcef8fd4cb859593 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Tue, 14 Jul 2020 23:02:06 +0000 Subject: [PATCH 07/24] added additional metrics --- .../github.com/gocql/gocql/cass.go | 58 ++++++++++++--- .../github.com/gocql/gocql/gocql_test.go | 22 ++++-- .../github.com/gocql/gocql/instrument.go | 72 +++++++++++++++---- .../github.com/gocql/gocql/observer.go | 51 ++++++------- 4 files changed, 149 insertions(+), 54 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index f8e6c4a9413..3b745a88100 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -25,28 +25,43 @@ const ( // the host of the cassandra instance being queried. CassHostKey = kv.Key("cassandra.host") + // CassHostIDKey is the key for the metric label describing the id + // of the host being queried. + CassHostIDKey = kv.Key("cassandra.host.id") + // CassPortKey is the key for the span attribute describing // the port of the cassandra server being queried. CassPortKey = kv.Key("cassandra.port") // CassHostStateKey is the key for the span attribute describing // the state of the casssandra server hosting the node being queried. - CassHostStateKey = kv.Key("cassandra.host_state") + CassHostStateKey = kv.Key("cassandra.host.state") // CassStatementKey is the key for the span attribute describing the // the statement used to query the cassandra database. // This attribute will only be found on a span for a query. CassStatementKey = kv.Key("cassandra.stmt") - // CassBatchStatementsKey is the key for the span attribute describing - // the list of statments used to query the cassandra database in a batch query. - // This attribute will only be found on a span for a batch query. - CassBatchStatementsKey = kv.Key("cassandra.batch_stmts") + // CassBatchQueriesKey is the key for the span attributed describing + // the number of queries contained within the batch statement. + CassBatchQueriesKey = kv.Key("cassandra.batch.queries") // CassErrMsgKey is the key for the span attribute describing // the error message from an error encountered when executing a query, batch, // or connection attempt to the cassandra server. - CassErrMsgKey = kv.Key("cassandra.err_msg") + CassErrMsgKey = kv.Key("cassandra.err.msg") + + // CassRowsReturnedKey is the key for the span attribute describing the number of rows + // returned on a query to the database. + CassRowsReturnedKey = kv.Key("cassandra.rows.returned") + + // CassQueryAttemptsKey is the key for the span attribute describing the number of attempts + // made for the query in question. + CassQueryAttemptsKey = kv.Key("cassandra.attempts") + + // CassQueryAttemptNumKey is the key for the span attribute describing + // which attempt the current query is as a 0-based index. + CassQueryAttemptNumKey = kv.Key("cassandra.attempt") // Names of the spans for query, batch query, and connect respectively. cassQueryName = "cassandra.query" @@ -64,6 +79,11 @@ func CassHost(host string) kv.KeyValue { return CassHostKey.String(host) } +// CassHostID returns the id of the cassandra host as a keyvalue pair. +func CassHostID(id string) kv.KeyValue { + return CassHostIDKey.String(id) +} + // CassPort returns the port of the cassandra node being queried // as a KeyValue pair. func CassPort(port int) kv.KeyValue { @@ -81,10 +101,10 @@ func CassStatement(stmt string) kv.KeyValue { return CassStatementKey.String(stmt) } -// CassBatchStatements returns the array of statments executed in a batch -// query made to the cassandra database as a keyvalue pair. -func CassBatchStatements(stmt []string) kv.KeyValue { - return CassBatchStatementsKey.Array(stmt) +// CassBatchQueries returns the number of queries in a batch query +// as a keyvalue pair. +func CassBatchQueries(num int) kv.KeyValue { + return CassBatchQueriesKey.Int(num) } // CassErrMsg returns the keyvalue pair of an error message @@ -92,3 +112,21 @@ func CassBatchStatements(stmt []string) kv.KeyValue { func CassErrMsg(msg string) kv.KeyValue { return CassErrMsgKey.String(msg) } + +// CassRowsReturned returns the keyvalue pair of the number of rows +// returned from a query. +func CassRowsReturned(rows int) kv.KeyValue { + return CassRowsReturnedKey.Int(rows) +} + +// CassQueryAttempts returns the keyvalue pair of the number of attempts +// made for a query. +func CassQueryAttempts(num int) kv.KeyValue { + return CassQueryAttemptsKey.Int(num) +} + +// CassQueryAttemptNum returns the 0-based index attempt number of a +// query as a keyvalue pair. +func CassQueryAttemptNum(num int) kv.KeyValue { + return CassQueryAttemptNumKey.Int(num) +} diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 7f20c6c1800..937205a8840 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -153,7 +153,7 @@ func TestQuery(t *testing.T) { // Check metrics controller.Stop() - assert.Equal(t, 3, len(exporter.records)) + assert.Equal(t, 4, len(exporter.records)) expected := []testRecord{ testRecord{ Name: "cassandra.connections", @@ -172,6 +172,10 @@ func TestQuery(t *testing.T) { MeterName: "github.com/gocql/gocql", Number: 0, }, + testRecord{ + Name: "cassandra.latency", + MeterName: "github.com/gocql/gocql", + }, } for _, record := range exporter.records { @@ -188,6 +192,8 @@ func TestQuery(t *testing.T) { case "cassandra.rows": recordEqual(t, expected[2], record) numberEqual(t, expected[2].Number, agg) + case "cassandra.latency": + recordEqual(t, expected[3], record) default: t.Fatalf("wrong metric %s", name) } @@ -237,27 +243,33 @@ func TestBatch(t *testing.T) { assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) - assert.Equal(t, stmts, span.Attributes[CassBatchStatementsKey].AsArray()) + assert.Equal(t, int32(len(stmts)), span.Attributes[CassBatchQueriesKey].AsInt32()) controller.Stop() - assert.Equal(t, 1, len(exporter.records)) + assert.Equal(t, 2, len(exporter.records)) expected := []testRecord{ testRecord{ - Name: "cassandra.batch_queries", + Name: "cassandra.batch.queries", MeterName: "github.com/gocql/gocql", // TODO: Labels Number: 1, }, + testRecord{ + Name: "cassandra.latency", + MeterName: "github.com/gocql/gocql", + }, } for _, record := range exporter.records { name := record.Descriptor().Name() agg := record.Aggregation() switch name { - case "cassandra.batch_queries": + case "cassandra.batch.queries": recordEqual(t, expected[0], record) numberEqual(t, expected[0].Number, agg) + case "cassandra.latency": + recordEqual(t, expected[1], record) default: t.Fatalf("wrong metric %s", name) } diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index 65e740e32e7..8c11d5e3b46 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -23,19 +23,32 @@ import ( ) var ( - // Query - iQueryCount metric.Int64Counter + // iQueryCount is the number of queries executed. + iQueryCount metric.Int64Counter + + // iQueryErrors is the number of errors encountered when + // executing queries. iQueryErrors metric.Int64Counter - iQueryRows metric.Int64ValueRecorder - // Batch - iBatchCount metric.Int64Counter + // iQueryRows is the number of rows returned by a query. + iQueryRows metric.Int64ValueRecorder + + // iBatchCount is the number of batch queries executed. + iBatchCount metric.Int64Counter + + // iBatchErrors is the number of errors encountered when + // executing batch queries. iBatchErrors metric.Int64Counter - // Connections + // iConnectionCount is the number of connections made + // with the traced session. iConnectionCount metric.Int64Counter - iConnectErrors metric.Int64Counter + // iConnectErrors is the number of errors encountered + // when making connections with the current traced session. + iConnectErrors metric.Int64Counter + + // iLatency is the sum of attempt latencies. iLatency metric.Int64ValueRecorder ) @@ -49,15 +62,46 @@ func InstrumentWithProvider(p metric.Provider) { }() meter := metric.Must(p.Meter("github.com/gocql/gocql")) - iQueryCount = meter.NewInt64Counter("cassandra.queries") - iQueryErrors = meter.NewInt64Counter("cassandra.query_errors") - iQueryRows = meter.NewInt64ValueRecorder("cassandra.rows") + iQueryCount = meter.NewInt64Counter( + "cassandra.queries", + metric.WithDescription("Number queries executed"), + ) + + iQueryErrors = meter.NewInt64Counter( + "cassandra.query.errors", + metric.WithDescription("Number of errors encountered when executing queries"), + ) + + iQueryRows = meter.NewInt64ValueRecorder( + "cassandra.rows", + metric.WithDescription("Number of rows returned from query"), + ) + + iBatchCount = meter.NewInt64Counter( + "cassandra.batch.queries", + metric.WithDescription("Number of batch queries executed"), + ) + + iBatchErrors = meter.NewInt64Counter( + "cassandra.batch.errors", + metric.WithDescription("Number of errors encountered when executing batch queries"), + ) + + iConnectionCount = meter.NewInt64Counter( + "cassandra.connections", + metric.WithDescription("Number of connections created"), + ) - iBatchCount = meter.NewInt64Counter("cassandra.batch_queries") - iBatchErrors = meter.NewInt64Counter("cassandra.batch_errors") + iConnectErrors = meter.NewInt64Counter( + "cassandra.connect.errors", + metric.WithDescription("Number of errors encountered when creating connections"), + ) - iConnectionCount = meter.NewInt64Counter("cassandra.connections") - iConnectErrors = meter.NewInt64Counter("cassandra.connect_errors") + iLatency = meter.NewInt64ValueRecorder( + "cassandra.latency", + metric.WithDescription("Sum of latency to host"), + // TODO: dimension + ) } func init() { diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index f451802d4f8..858f57bef19 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -83,16 +83,11 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq attributes := append( defaultAttributes(observedQuery.Host), CassStatement(observedQuery.Statement), + CassRowsReturned(observedQuery.Rows), + CassQueryAttempts(observedQuery.Metrics.Attempts), + CassQueryAttemptNum(observedQuery.Attempt), ) - if observedQuery.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedQuery.Err.Error()), - ) - iQueryErrors.Add(ctx, 1) - } - ctx, span := o.cfg.tracer.Start( ctx, cassQueryName, @@ -100,11 +95,18 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq trace.WithAttributes(attributes...), ) + if observedQuery.Err != nil { + span.SetAttributes(CassErrMsg(observedQuery.Err.Error())) + iQueryErrors.Add(ctx, 1) + } + span.End(trace.WithEndTime(observedQuery.End)) iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) iQueryRows.Record(ctx, int64(observedQuery.Rows)) + iLatency.Record(ctx, observedQuery.Metrics.TotalLatency) } + if o.observer != nil { o.observer.ObserveQuery(ctx, observedQuery) } @@ -115,17 +117,9 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq if o.cfg.instrumentBatch { attributes := append( defaultAttributes(observedBatch.Host), - CassBatchStatements(observedBatch.Statements), + CassBatchQueries(len(observedBatch.Statements)), ) - if observedBatch.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedBatch.Err.Error()), - ) - iBatchErrors.Add(ctx, 1) - } - ctx, span := o.cfg.tracer.Start( ctx, cassBatchQueryName, @@ -133,9 +127,19 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq trace.WithAttributes(attributes...), ) + if observedBatch.Err != nil { + span.SetAttributes(CassErrMsg(observedBatch.Err.Error())) + iBatchErrors.Add(ctx, 1) + } + span.End(trace.WithEndTime(observedBatch.End)) iBatchCount.Add(ctx, 1) + iLatency.Record( + ctx, + observedBatch.Metrics.TotalLatency, + CassHostID(observedBatch.Host.HostID()), + ) } if o.observer != nil { @@ -148,14 +152,6 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne if o.cfg.instrumentConnect { attributes := defaultAttributes(observedConnect.Host) - if observedConnect.Err != nil { - attributes = append( - attributes, - CassErrMsg(observedConnect.Err.Error()), - ) - iConnectErrors.Add(o.ctx, 1) - } - _, span := o.cfg.tracer.Start( o.ctx, cassConnectName, @@ -163,6 +159,11 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne trace.WithAttributes(attributes...), ) + if observedConnect.Err != nil { + span.SetAttributes(CassErrMsg(observedConnect.Err.Error())) + iConnectErrors.Add(o.ctx, 1) + } + span.End(trace.WithEndTime(observedConnect.End)) host := observedConnect.Host.HostnameAndPort() From b74f0c1557028044b9996fbfa620899205980aff Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Wed, 15 Jul 2020 22:50:53 +0000 Subject: [PATCH 08/24] added unit to latency --- instrumentation/github.com/gocql/gocql/instrument.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index 8c11d5e3b46..b12cadb1f9d 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -20,6 +20,7 @@ import ( "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/metric" + "go.opentelemetry.io/otel/api/unit" ) var ( @@ -99,8 +100,8 @@ func InstrumentWithProvider(p metric.Provider) { iLatency = meter.NewInt64ValueRecorder( "cassandra.latency", - metric.WithDescription("Sum of latency to host"), - // TODO: dimension + metric.WithDescription("Sum of latency to host in milliseconds"), + metric.WithUnit(unit.Milliseconds), ) } From a9b7e2e26d716824de31ca13ba9d1b1c022e2836 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Wed, 15 Jul 2020 23:18:28 +0000 Subject: [PATCH 09/24] added additional labels and attributes --- .../github.com/gocql/gocql/cass.go | 9 ++ .../github.com/gocql/gocql/gocql_test.go | 121 ++++++++++++++---- .../github.com/gocql/gocql/observer.go | 102 +++++++++++++-- 3 files changed, 192 insertions(+), 40 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index 3b745a88100..ba3ffa4df45 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -37,6 +37,10 @@ const ( // the state of the casssandra server hosting the node being queried. CassHostStateKey = kv.Key("cassandra.host.state") + // CassKeyspaceKey is the key for the KeyValue pair describing the + // keyspace of the current session. + CassKeyspaceKey = kv.Key("cassandra.keyspace") + // CassStatementKey is the key for the span attribute describing the // the statement used to query the cassandra database. // This attribute will only be found on a span for a query. @@ -95,6 +99,11 @@ func CassHostState(state string) kv.KeyValue { return CassHostStateKey.String(state) } +// CassKeyspace returns the keyspace of the session as a keyvalue pair. +func CassKeyspace(keyspace string) kv.KeyValue { + return CassKeyspaceKey.String(keyspace) +} + // CassStatement returns the statement made to the cassandra database as a // KeyValue pair. func CassStatement(stmt string) kv.KeyValue { diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 937205a8840..dcb512f7728 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -97,7 +97,6 @@ func TestQuery(t *testing.T) { defer afterEach() cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") - connectObserver := &mockConnectObserver{} ctx, parentSpan := tracer.Start(context.Background(), "gocql-test") @@ -105,7 +104,7 @@ func TestQuery(t *testing.T) { ctx, cluster, WithTracer(tracer), - WithConnectObserver(connectObserver), + WithConnectInstrumentation(false), ) assert.NoError(t, err) defer session.Close() @@ -125,10 +124,10 @@ func TestQuery(t *testing.T) { spans := tracer.EndedSpans() // Collect all the connection spans - numberOfConnections := connectObserver.callCount - // there should be numberOfConnections + 1 Query + 1 Batch spans - assert.Equal(t, numberOfConnections+2, len(spans)) - assert.Greater(t, numberOfConnections, 0, "at least one connection needs to have been made") + // total spans: + // 1 span for the Query + // 1 span created in test + assert.Equal(t, 2, len(spans)) // Verify attributes are correctly added to the spans. Omit the one local span for _, span := range spans[0 : len(spans)-1] { @@ -138,8 +137,6 @@ func TestQuery(t *testing.T) { assert.Equal(t, insertStmt, span.Attributes[CassStatementKey].AsString()) assert.Equal(t, parentSpan.SpanContext().SpanID.String(), span.ParentSpanID.String()) break - case cassConnectName: - numberOfConnections-- default: t.Fatalf("unexpected span name %s", span.Name) } @@ -148,33 +145,38 @@ func TestQuery(t *testing.T) { assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) } - assert.Equal(t, 0, numberOfConnections) // Check metrics controller.Stop() - assert.Equal(t, 4, len(exporter.records)) + assert.Equal(t, 3, len(exporter.records)) expected := []testRecord{ - testRecord{ - Name: "cassandra.connections", - MeterName: "github.com/gocql/gocql", - // TODO: Labels - Number: 3, - }, testRecord{ Name: "cassandra.queries", MeterName: "github.com/gocql/gocql", - // TODO: Labels + Labels: []kv.KeyValue{ + CassHostID("test-id"), + CassKeyspace(keyspace), + CassStatement(insertStmt), + }, Number: 1, }, testRecord{ Name: "cassandra.rows", MeterName: "github.com/gocql/gocql", - Number: 0, + Labels: []kv.KeyValue{ + CassHostID("test-id"), + CassKeyspace(keyspace), + }, + Number: 0, }, testRecord{ Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", + Labels: []kv.KeyValue{ + CassHostID("test-id"), + CassKeyspace(keyspace), + }, }, } @@ -182,18 +184,19 @@ func TestQuery(t *testing.T) { name := record.Descriptor().Name() agg := record.Aggregation() switch name { - case "cassandra.connections": + case "cassandra.queries": recordEqual(t, expected[0], record) numberEqual(t, expected[0].Number, agg) - case "cassandra.queries": - recordEqual(t, expected[1], record) - numberEqual(t, expected[1].Number, agg) break case "cassandra.rows": - recordEqual(t, expected[2], record) - numberEqual(t, expected[2].Number, agg) + recordEqual(t, expected[1], record) + numberEqual(t, expected[1].Number, agg) case "cassandra.latency": - recordEqual(t, expected[3], record) + recordEqual(t, expected[2], record) + // The latency will vary, so just check that it exists + if _, ok := agg.(aggregation.MinMaxSumCount); !ok { + t.Fatal("missing aggregation in latency record") + } default: t.Fatalf("wrong metric %s", name) } @@ -234,6 +237,9 @@ func TestBatch(t *testing.T) { parentSpan.End() spans := tracer.EndedSpans() + // total spans: + // 1 span for the query + // 1 span for the local span assert.Equal(t, 2, len(spans)) span := spans[0] @@ -247,17 +253,25 @@ func TestBatch(t *testing.T) { controller.Stop() + // Check metrics assert.Equal(t, 2, len(exporter.records)) expected := []testRecord{ testRecord{ Name: "cassandra.batch.queries", MeterName: "github.com/gocql/gocql", - // TODO: Labels + Labels: []kv.KeyValue{ + CassHostID("test-id"), + CassKeyspace(keyspace), + }, Number: 1, }, testRecord{ Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", + Labels: []kv.KeyValue{ + CassHostID("test-id"), + CassKeyspace(keyspace), + }, }, } @@ -270,6 +284,9 @@ func TestBatch(t *testing.T) { numberEqual(t, expected[0].Number, agg) case "cassandra.latency": recordEqual(t, expected[1], record) + if _, ok := agg.(aggregation.MinMaxSumCount); !ok { + t.Fatal("missing aggregation in latency record") + } default: t.Fatalf("wrong metric %s", name) } @@ -278,20 +295,28 @@ func TestBatch(t *testing.T) { } func TestConnection(t *testing.T) { + controller := getController(t) defer afterEach() cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") + connectObserver := &mockConnectObserver{0} session, err := NewSessionWithTracing( context.Background(), cluster, WithTracer(tracer), + WithConnectObserver(connectObserver), ) assert.NoError(t, err) defer session.Close() spans := tracer.EndedSpans() + assert.Less(t, 0, connectObserver.callCount) + + controller.Stop() + + // Verify the span attributes for _, span := range spans { assert.Equal(t, cassConnectName, span.Name) assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) @@ -299,6 +324,39 @@ func TestConnection(t *testing.T) { assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) } + + // Verify the metrics + expected := []testRecord{ + testRecord{ + Name: "cassandra.connections", + MeterName: "github.com/gocql/gocql", + Labels: []kv.KeyValue{ + CassHost("127.0.0.1"), + CassHostID("test-id"), + }, + }, + } + + for _, record := range exporter.records { + name := record.Descriptor().Name() + switch name { + case "cassandra.connections": + recordEqual(t, expected[0], record) + default: + t.Fatalf("wrong metric %s", name) + } + } +} + +func TestGetHost(t *testing.T) { + hostAndPort := "localhost:9042" + assert.Equal(t, "localhost", getHost(hostAndPort)) + + hostAndPort = "127.0.0.1:9042" + assert.Equal(t, "127.0.0.1", getHost(hostAndPort)) + + hostAndPort = ":9042" + assert.Equal(t, "", getHost(hostAndPort)) } // getCluster creates a gocql ClusterConfig with the appropriate @@ -324,6 +382,17 @@ func recordEqual(t *testing.T, expected testRecord, actual export.Record) { descriptor := actual.Descriptor() assert.Equal(t, expected.Name, descriptor.Name()) assert.Equal(t, expected.MeterName, descriptor.InstrumentationName()) + for _, label := range expected.Labels { + actualValue, ok := actual.Labels().Value(label.Key) + assert.True(t, ok) + assert.NotNil(t, actualValue) + // Cant test equality of host id + if label.Key != CassHostIDKey { + assert.Equal(t, label.Value, actualValue) + } else { + assert.NotEmpty(t, actualValue) + } + } } func numberEqual(t *testing.T, expected metric.Number, agg aggregation.Aggregation) { diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 858f57bef19..70c98ac782a 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -17,9 +17,11 @@ package gocql import ( "context" "strings" + "time" "github.com/gocql/gocql" "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" ) @@ -80,12 +82,16 @@ func NewConnectObserver(ctx context.Context, observer gocql.ConnectObserver, cfg // ObserveQuery instruments a specific query. func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { if o.cfg.instrumentQuery { + host := observedQuery.Host + keyspace := observedQuery.Keyspace + attributes := append( - defaultAttributes(observedQuery.Host), + defaultAttributes(host), CassStatement(observedQuery.Statement), CassRowsReturned(observedQuery.Rows), CassQueryAttempts(observedQuery.Metrics.Attempts), CassQueryAttemptNum(observedQuery.Attempt), + CassKeyspace(keyspace), ) ctx, span := o.cfg.tracer.Start( @@ -97,14 +103,30 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq if observedQuery.Err != nil { span.SetAttributes(CassErrMsg(observedQuery.Err.Error())) - iQueryErrors.Add(ctx, 1) + recordError(ctx, iQueryErrors, keyspace, host) } span.End(trace.WithEndTime(observedQuery.End)) - iQueryCount.Add(ctx, 1, CassStatement(observedQuery.Statement)) - iQueryRows.Record(ctx, int64(observedQuery.Rows)) - iLatency.Record(ctx, observedQuery.Metrics.TotalLatency) + queryLabels := append( + defaultMetricLabels(keyspace, host), + CassStatement(observedQuery.Statement), + ) + iQueryCount.Add( + ctx, + 1, + queryLabels..., + ) + iQueryRows.Record( + ctx, + int64(observedQuery.Rows), + defaultMetricLabels(keyspace, host)..., + ) + iLatency.Record( + ctx, + nanoToMilliseconds(observedQuery.Metrics.TotalLatency), + defaultMetricLabels(keyspace, host)..., + ) } if o.observer != nil { @@ -115,9 +137,12 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq // ObserveBatch instruments a specific batch query. func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { if o.cfg.instrumentBatch { + host := observedBatch.Host + keyspace := observedBatch.Keyspace attributes := append( - defaultAttributes(observedBatch.Host), + defaultAttributes(host), CassBatchQueries(len(observedBatch.Statements)), + CassKeyspace(keyspace), ) ctx, span := o.cfg.tracer.Start( @@ -129,16 +154,20 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq if observedBatch.Err != nil { span.SetAttributes(CassErrMsg(observedBatch.Err.Error())) - iBatchErrors.Add(ctx, 1) + recordError(ctx, iBatchErrors, keyspace, host) } span.End(trace.WithEndTime(observedBatch.End)) - iBatchCount.Add(ctx, 1) + iBatchCount.Add( + ctx, + 1, + defaultMetricLabels(observedBatch.Keyspace, observedBatch.Host)..., + ) iLatency.Record( ctx, - observedBatch.Metrics.TotalLatency, - CassHostID(observedBatch.Host.HostID()), + nanoToMilliseconds(observedBatch.Metrics.TotalLatency), + defaultMetricLabels(keyspace, host)..., ) } @@ -150,6 +179,8 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq // ObserveConnect instruments a specific connection attempt. func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { if o.cfg.instrumentConnect { + host := observedConnect.Host + hostname := getHost(host.HostnameAndPort()) attributes := defaultAttributes(observedConnect.Host) _, span := o.cfg.tracer.Start( @@ -161,13 +192,22 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne if observedConnect.Err != nil { span.SetAttributes(CassErrMsg(observedConnect.Err.Error())) - iConnectErrors.Add(o.ctx, 1) + iConnectErrors.Add( + o.ctx, + 1, + CassHost(hostname), + CassHostID(host.HostID()), + ) } span.End(trace.WithEndTime(observedConnect.End)) - host := observedConnect.Host.HostnameAndPort() - iConnectionCount.Add(o.ctx, 1, CassHostKey.String(host)) + iConnectionCount.Add( + o.ctx, + 1, + CassHost(hostname), + CassHostID(host.HostID()), + ) } if o.observer != nil { @@ -177,12 +217,46 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne // ------------------------------------------ Private Functions +// getHost returns the hostname as a string. +// gocql.HostInfo.HostnameAndPort() returns a string +// formatted like host:port. This function returns the host. +func getHost(hostPort string) string { + idx := strings.Index(hostPort, ":") + host := hostPort[0:idx] + return host +} + +// defaultAttributes creates an array of KeyValue pairs that are +// attributes for all gocql spans. func defaultAttributes(host *gocql.HostInfo) []kv.KeyValue { hostnameAndPort := host.HostnameAndPort() return []kv.KeyValue{ CassVersion(host.Version().String()), - CassHost(hostnameAndPort[0:strings.Index(hostnameAndPort, ":")]), + CassHost(getHost(hostnameAndPort)), CassPort(host.Port()), CassHostState(host.State().String()), + CassHostID(host.HostID()), + } +} + +// defaultMetricLabels returns an array of the default labels added to metrics. +func defaultMetricLabels(keyspace string, host *gocql.HostInfo) []kv.KeyValue { + return []kv.KeyValue{ + CassHostID(host.HostID()), + CassKeyspace(keyspace), } } + +// nanoToMilliseconds converts nanoseconds to milliseconds. +func nanoToMilliseconds(ns int64) int64 { + return ns / int64(time.Millisecond) +} + +func recordError(ctx context.Context, counter metric.Int64Counter, keyspace string, host *gocql.HostInfo) { + labels := append(defaultMetricLabels(keyspace, host), CassHostState(host.State().String())) + counter.Add( + ctx, + 1, + labels..., + ) +} From 98440be5c141870788fe40bd84074f6c52e47a84 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 00:09:34 +0000 Subject: [PATCH 10/24] added doc --- instrumentation/github.com/gocql/gocql/doc.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 instrumentation/github.com/gocql/gocql/doc.go diff --git a/instrumentation/github.com/gocql/gocql/doc.go b/instrumentation/github.com/gocql/gocql/doc.go new file mode 100644 index 00000000000..78618f03115 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/doc.go @@ -0,0 +1,18 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package gocql provides functions to instrument the gocql/gocql package +// (https://github.com/gocql/gocql). +// +package gocql // import "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" \ No newline at end of file From c04e34e2633d00ecae1c77de87e7d4e2fdfa3e49 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 15:24:40 +0000 Subject: [PATCH 11/24] added package readme --- .../github.com/gocql/gocql/README.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 instrumentation/github.com/gocql/gocql/README.md diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md new file mode 100644 index 00000000000..3980bbbf1ad --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -0,0 +1,55 @@ +## `go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql` + +This package provides tracing and metrics to the golang cassandra client `github.com/gocql/gocql` using the `ConnectObserver`, `QueryObserver` and `BatchObserver` interfaces. + +To enable tracing in your application: + +```go +package main + +import ( + "context" + + "github.com/gocql/gocql" + otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" +) + +func main() { + // Create a cluster + host := "localhost" + cluster := gocql.NewCluster(host) + + // Create a session with tracing + session, err := otelGocql.NewSessionWithTracing( + context.Background(), + cluster, + // Include any options here + ) + + // Begin using the session + +} +``` + +You can customize the tracing session by passing any of the following options to `NewSessionWithTracing`: + +| Function | Description | +| -------- | ----------- | +| `WithQueryObserver(gocql.QueryObserver)` | Specify an additional QueryObserver to be called. | +| `WithBatchObserver(gocql.BatchObserver)` | Specify an additional BatchObserver to be called. | +| `WithConnectObserver(gocql.ConnectObserver)` | Specify an additional ConnectObserver to be called. | +| `WithTracer(trace.Tracer)` | The tracer to be used to create spans for the gocql session. If not specified, `global.Tracer("github.com/gocql/gocql")` will be used. | +| `WithQueryInstrumentation(bool)` | To enable/disable tracing and metrics for queries. | +| `WithBatchInstrumentation(bool)` | To enable/disable tracing and metrics for batch queries. | +| `WithConnectInstrumentation(bool)` | To enable/disable tracing and metrics for new connections. | + +In addition to using the convenience function, you may also manually set the obsevers: + +```go +host := "localhost" +cluster := gocql.NewCluster(host) +cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ + tracer: global.Tracer("github.com/gocql/gocql"), +}) +session, err := cluster.CreateSession() +``` \ No newline at end of file From 71014690fcb5f9133fd317ada3bf54790f5b498d Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 16:43:12 +0000 Subject: [PATCH 12/24] added readme to example --- .../github.com/gocql/gocql/example/README.md | 18 +++ .../github.com/gocql/gocql/example/client.go | 123 +++++++++--------- .../github.com/gocql/gocql/example/db.go | 52 ++++++++ .../gocql/gocql/example/docker-compose.yml | 13 +- 4 files changed, 139 insertions(+), 67 deletions(-) create mode 100644 instrumentation/github.com/gocql/gocql/example/README.md create mode 100644 instrumentation/github.com/gocql/gocql/example/db.go diff --git a/instrumentation/github.com/gocql/gocql/example/README.md b/instrumentation/github.com/gocql/gocql/example/README.md new file mode 100644 index 00000000000..0ade422ce1a --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/README.md @@ -0,0 +1,18 @@ +## Integration Example + +### To run the example: +1. `cd` into the example directory. +2. Run `docker-compose up`. +3. Wait for cassandra to listen for cql clients with the following message in the logs: + +``` +Server.java:159 - Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)... +``` + +4. Run the example using `go run .`. + +5. You can view the spans in the browser at `localhost:9411` and the metrics at `localhost:2222`. + +### When you're done: +1. `ctrl+c` to kill the example program. +2. `docker-compose down` to stop cassandra and zipkin. diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index ae6cb47dc4e..bb1eb3b523f 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -43,8 +43,70 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" ) +const keyspace = "gocql_integration_example" + var wg sync.WaitGroup +func main() { + initMetrics() + initTracer() + initDb() + + ctx, span := global.Tracer( + "go.opentelemetry.io/contrib/github.com/gocql/gocql/example", + ).Start(context.Background(), "begin example") + + cluster := getCluster() + // Create a session to begin making queries + session, err := otelGocql.NewSessionWithTracing( + ctx, + cluster, + ) + if err != nil { + log.Fatalf("failed to create a session, %v", err) + } + defer session.Close() + + batch := session.NewBatch(gocql.LoggedBatch) + for i := 0; i < 500; i++ { + batch.Query( + "INSERT INTO book (id, title, author_first_name, author_last_name) VALUES (?, ?, ?, ?)", + gocql.TimeUUID(), + fmt.Sprintf("Example Book %d", i), + "firstName", + "lastName", + ) + } + if err := session.ExecuteBatch(batch.WithContext(ctx)); err != nil { + log.Printf("failed to batch insert, %v", err) + } + + res := session.Query( + "SELECT title, author_first_name, author_last_name from book WHERE author_last_name = ?", + "lastName", + ).WithContext(ctx).PageSize(100).Iter() + + var ( + title string + firstName string + lastName string + ) + + for res.Scan(&title, &firstName, &lastName) { + res.Scan(&title, &firstName, &lastName) + } + + res.Close() + + if err = session.Query("truncate table book").WithContext(ctx).Exec(); err != nil { + log.Printf("failed to delete data, %v", err) + } + + span.End() + + wg.Wait() +} + func initMetrics() { // Start prometheus metricExporter, err := prometheus.NewExportPipeline(prometheus.Config{}) @@ -100,67 +162,8 @@ func initTracer() { func getCluster() *gocql.ClusterConfig { cluster := gocql.NewCluster("127.0.0.1") - cluster.Keyspace = "gocql_integration_example" + cluster.Keyspace = keyspace cluster.Consistency = gocql.LocalQuorum cluster.ProtoVersion = 3 return cluster } - -func main() { - initMetrics() - initTracer() - - ctx, span := global.Tracer( - "go.opentelemetry.io/contrib/github.com/gocql/gocql/example", - ).Start(context.Background(), "begin example") - - cluster := getCluster() - // Create a session to begin making queries - session, err := otelGocql.NewSessionWithTracing( - ctx, - cluster, - ) - if err != nil { - log.Fatalf("failed to create a session, %v", err) - } - defer session.Close() - - batch := session.NewBatch(gocql.LoggedBatch) - for i := 0; i < 500; i++ { - batch.Query( - "INSERT INTO book (id, title, author_first_name, author_last_name) VALUES (?, ?, ?, ?)", - gocql.TimeUUID(), - fmt.Sprintf("Example Book %d", i), - "firstName", - "lastName", - ) - } - if err := session.ExecuteBatch(batch.WithContext(ctx)); err != nil { - log.Printf("failed to batch insert, %v", err) - } - - res := session.Query( - "SELECT title, author_first_name, author_last_name from book WHERE author_last_name = ?", - "lastName", - ).WithContext(ctx).PageSize(100).Iter() - - var ( - title string - firstName string - lastName string - ) - - for res.Scan(&title, &firstName, &lastName) { - res.Scan(&title, &firstName, &lastName) - } - - res.Close() - - if err = session.Query("truncate table book").WithContext(ctx).Exec(); err != nil { - log.Printf("failed to delete data, %v", err) - } - - span.End() - - wg.Wait() -} diff --git a/instrumentation/github.com/gocql/gocql/example/db.go b/instrumentation/github.com/gocql/gocql/example/db.go new file mode 100644 index 00000000000..25d27638859 --- /dev/null +++ b/instrumentation/github.com/gocql/gocql/example/db.go @@ -0,0 +1,52 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "log" + + "github.com/gocql/gocql" +) + +func initDb() { + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "system" + cluster.Consistency = gocql.LocalQuorum + session, err := cluster.CreateSession() + if err != nil { + log.Fatal(err) + } + stmt := fmt.Sprintf( + "create keyspace if not exists %s with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", + keyspace, + ) + if err := session.Query(stmt).Exec(); err != nil { + log.Fatal(err) + } + + cluster.Keyspace = keyspace + session, err = cluster.CreateSession() + + stmt = "create table if not exists book(id UUID, title text, author_first_name text, author_last_name text, PRIMARY KEY(id))" + if err = session.Query(stmt).Exec(); err != nil { + log.Fatal(err) + } + + if err := session.Query("create index if not exists on book(author_last_name)").Exec(); err != nil { + log.Fatal(err) + } +} + diff --git a/instrumentation/github.com/gocql/gocql/example/docker-compose.yml b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml index f82df2f27f4..e9eaeb86b91 100644 --- a/instrumentation/github.com/gocql/gocql/example/docker-compose.yml +++ b/instrumentation/github.com/gocql/gocql/example/docker-compose.yml @@ -14,12 +14,11 @@ version: '3' services: -# cassandra: -# image: cassandra:latest -# ports: -# - 9042:9042 -# - 9160:9160 + cassandra: + image: cassandra:3 + ports: + - 9042:9042 zipkin: - image: openzipkin/zipkin + image: openzipkin/zipkin:2 ports: - - 9411:9411 \ No newline at end of file + - 9411:9411 From 4f12361b3e3191812f1530065000d1297afb3458 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 17:03:41 +0000 Subject: [PATCH 13/24] fix formatting --- instrumentation/github.com/gocql/gocql/doc.go | 2 +- instrumentation/github.com/gocql/gocql/example/db.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/doc.go b/instrumentation/github.com/gocql/gocql/doc.go index 78618f03115..6bc0e28e1c7 100644 --- a/instrumentation/github.com/gocql/gocql/doc.go +++ b/instrumentation/github.com/gocql/gocql/doc.go @@ -15,4 +15,4 @@ // Package gocql provides functions to instrument the gocql/gocql package // (https://github.com/gocql/gocql). // -package gocql // import "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" \ No newline at end of file +package gocql // import "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" diff --git a/instrumentation/github.com/gocql/gocql/example/db.go b/instrumentation/github.com/gocql/gocql/example/db.go index 25d27638859..71a36d35c00 100644 --- a/instrumentation/github.com/gocql/gocql/example/db.go +++ b/instrumentation/github.com/gocql/gocql/example/db.go @@ -49,4 +49,3 @@ func initDb() { log.Fatal(err) } } - From 6b6c73661001fe3c627b21189169ca4af960ebfb Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 11:39:01 -0600 Subject: [PATCH 14/24] Remove unecessary export of keyvalue pairs --- .../github.com/gocql/gocql/cass.go | 122 +++++++++--------- .../github.com/gocql/gocql/gocql_test.go | 56 ++++---- .../github.com/gocql/gocql/observer.go | 46 +++---- 3 files changed, 112 insertions(+), 112 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index ba3ffa4df45..40d0b4133eb 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -17,125 +17,125 @@ package gocql import "go.opentelemetry.io/otel/api/kv" const ( - // CassVersionKey is the key for the span attribute describing + // cassVersionKey is the key for the span attribute describing // the cql version. - CassVersionKey = kv.Key("cassandra.version") + cassVersionKey = kv.Key("cassandra.version") - // CassHostKey is the key for the span attribute describing + // cassHostKey is the key for the span attribute describing // the host of the cassandra instance being queried. - CassHostKey = kv.Key("cassandra.host") + cassHostKey = kv.Key("cassandra.host") - // CassHostIDKey is the key for the metric label describing the id + // cassHostIDKey is the key for the metric label describing the id // of the host being queried. - CassHostIDKey = kv.Key("cassandra.host.id") + cassHostIDKey = kv.Key("cassandra.host.id") - // CassPortKey is the key for the span attribute describing + // cassPortKey is the key for the span attribute describing // the port of the cassandra server being queried. - CassPortKey = kv.Key("cassandra.port") + cassPortKey = kv.Key("cassandra.port") - // CassHostStateKey is the key for the span attribute describing + // cassHostStateKey is the key for the span attribute describing // the state of the casssandra server hosting the node being queried. - CassHostStateKey = kv.Key("cassandra.host.state") + cassHostStateKey = kv.Key("cassandra.host.state") - // CassKeyspaceKey is the key for the KeyValue pair describing the + // cassKeyspaceKey is the key for the KeyValue pair describing the // keyspace of the current session. - CassKeyspaceKey = kv.Key("cassandra.keyspace") + cassKeyspaceKey = kv.Key("cassandra.keyspace") - // CassStatementKey is the key for the span attribute describing the + // cassStatementKey is the key for the span attribute describing the // the statement used to query the cassandra database. // This attribute will only be found on a span for a query. - CassStatementKey = kv.Key("cassandra.stmt") + cassStatementKey = kv.Key("cassandra.stmt") - // CassBatchQueriesKey is the key for the span attributed describing + // cassBatchQueriesKey is the key for the span attributed describing // the number of queries contained within the batch statement. - CassBatchQueriesKey = kv.Key("cassandra.batch.queries") + cassBatchQueriesKey = kv.Key("cassandra.batch.queries") - // CassErrMsgKey is the key for the span attribute describing + // cassErrMsgKey is the key for the span attribute describing // the error message from an error encountered when executing a query, batch, // or connection attempt to the cassandra server. - CassErrMsgKey = kv.Key("cassandra.err.msg") + cassErrMsgKey = kv.Key("cassandra.err.msg") - // CassRowsReturnedKey is the key for the span attribute describing the number of rows + // cassRowsReturnedKey is the key for the span attribute describing the number of rows // returned on a query to the database. - CassRowsReturnedKey = kv.Key("cassandra.rows.returned") + cassRowsReturnedKey = kv.Key("cassandra.rows.returned") - // CassQueryAttemptsKey is the key for the span attribute describing the number of attempts + // cassQueryAttemptsKey is the key for the span attribute describing the number of attempts // made for the query in question. - CassQueryAttemptsKey = kv.Key("cassandra.attempts") + cassQueryAttemptsKey = kv.Key("cassandra.attempts") - // CassQueryAttemptNumKey is the key for the span attribute describing + // cassQueryAttemptNumKey is the key for the span attribute describing // which attempt the current query is as a 0-based index. - CassQueryAttemptNumKey = kv.Key("cassandra.attempt") + cassQueryAttemptNumKey = kv.Key("cassandra.attempt") // Names of the spans for query, batch query, and connect respectively. cassQueryName = "cassandra.query" - cassBatchQueryName = "cassandra.batch_query" + cassBatchQueryName = "cassandra.batch.query" cassConnectName = "cassandra.connect" ) -// CassVersion returns the cql version as a KeyValue pair. -func CassVersion(version string) kv.KeyValue { - return CassVersionKey.String(version) +// cassVersion returns the cql version as a KeyValue pair. +func cassVersion(version string) kv.KeyValue { + return cassVersionKey.String(version) } -// CassHost returns the cassandra host as a KeyValue pair. -func CassHost(host string) kv.KeyValue { - return CassHostKey.String(host) +// cassHost returns the cassandra host as a KeyValue pair. +func cassHost(host string) kv.KeyValue { + return cassHostKey.String(host) } -// CassHostID returns the id of the cassandra host as a keyvalue pair. -func CassHostID(id string) kv.KeyValue { - return CassHostIDKey.String(id) +// cassHostID returns the id of the cassandra host as a keyvalue pair. +func cassHostID(id string) kv.KeyValue { + return cassHostIDKey.String(id) } -// CassPort returns the port of the cassandra node being queried +// cassPort returns the port of the cassandra node being queried // as a KeyValue pair. -func CassPort(port int) kv.KeyValue { - return CassPortKey.Int(port) +func cassPort(port int) kv.KeyValue { + return cassPortKey.Int(port) } -// CassHostState returns the state of the cassandra host as a KeyValue pair. -func CassHostState(state string) kv.KeyValue { - return CassHostStateKey.String(state) +// cassHostState returns the state of the cassandra host as a KeyValue pair. +func cassHostState(state string) kv.KeyValue { + return cassHostStateKey.String(state) } -// CassKeyspace returns the keyspace of the session as a keyvalue pair. -func CassKeyspace(keyspace string) kv.KeyValue { - return CassKeyspaceKey.String(keyspace) +// cassKeyspace returns the keyspace of the session as a keyvalue pair. +func cassKeyspace(keyspace string) kv.KeyValue { + return cassKeyspaceKey.String(keyspace) } -// CassStatement returns the statement made to the cassandra database as a +// cassStatement returns the statement made to the cassandra database as a // KeyValue pair. -func CassStatement(stmt string) kv.KeyValue { - return CassStatementKey.String(stmt) +func cassStatement(stmt string) kv.KeyValue { + return cassStatementKey.String(stmt) } -// CassBatchQueries returns the number of queries in a batch query +// cassBatchQueries returns the number of queries in a batch query // as a keyvalue pair. -func CassBatchQueries(num int) kv.KeyValue { - return CassBatchQueriesKey.Int(num) +func cassBatchQueries(num int) kv.KeyValue { + return cassBatchQueriesKey.Int(num) } -// CassErrMsg returns the keyvalue pair of an error message +// cassErrMsg returns the keyvalue pair of an error message // encountered when executing a query, batch query, or error. -func CassErrMsg(msg string) kv.KeyValue { - return CassErrMsgKey.String(msg) +func cassErrMsg(msg string) kv.KeyValue { + return cassErrMsgKey.String(msg) } -// CassRowsReturned returns the keyvalue pair of the number of rows +// cassRowsReturned returns the keyvalue pair of the number of rows // returned from a query. -func CassRowsReturned(rows int) kv.KeyValue { - return CassRowsReturnedKey.Int(rows) +func cassRowsReturned(rows int) kv.KeyValue { + return cassRowsReturnedKey.Int(rows) } -// CassQueryAttempts returns the keyvalue pair of the number of attempts +// cassQueryAttempts returns the keyvalue pair of the number of attempts // made for a query. -func CassQueryAttempts(num int) kv.KeyValue { - return CassQueryAttemptsKey.Int(num) +func cassQueryAttempts(num int) kv.KeyValue { + return cassQueryAttemptsKey.Int(num) } -// CassQueryAttemptNum returns the 0-based index attempt number of a +// cassQueryAttemptNum returns the 0-based index attempt number of a // query as a keyvalue pair. -func CassQueryAttemptNum(num int) kv.KeyValue { - return CassQueryAttemptNumKey.Int(num) +func cassQueryAttemptNum(num int) kv.KeyValue { + return cassQueryAttemptNumKey.Int(num) } diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index dcb512f7728..b83fdcff215 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -134,16 +134,16 @@ func TestQuery(t *testing.T) { switch span.Name { case cassQueryName: - assert.Equal(t, insertStmt, span.Attributes[CassStatementKey].AsString()) + assert.Equal(t, insertStmt, span.Attributes[cassStatementKey].AsString()) assert.Equal(t, parentSpan.SpanContext().SpanID.String(), span.ParentSpanID.String()) break default: t.Fatalf("unexpected span name %s", span.Name) } - assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) + assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) } // Check metrics @@ -155,9 +155,9 @@ func TestQuery(t *testing.T) { Name: "cassandra.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHostID("test-id"), - CassKeyspace(keyspace), - CassStatement(insertStmt), + cassHostID("test-id"), + cassKeyspace(keyspace), + cassStatement(insertStmt), }, Number: 1, }, @@ -165,8 +165,8 @@ func TestQuery(t *testing.T) { Name: "cassandra.rows", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHostID("test-id"), - CassKeyspace(keyspace), + cassHostID("test-id"), + cassKeyspace(keyspace), }, Number: 0, }, @@ -174,8 +174,8 @@ func TestQuery(t *testing.T) { Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHostID("test-id"), - CassKeyspace(keyspace), + cassHostID("test-id"), + cassKeyspace(keyspace), }, }, } @@ -245,11 +245,11 @@ func TestBatch(t *testing.T) { assert.Equal(t, cassBatchQueryName, span.Name) assert.Equal(t, parentSpan.SpanContext().SpanID, span.ParentSpanID) - assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) - assert.Equal(t, int32(len(stmts)), span.Attributes[CassBatchQueriesKey].AsInt32()) + assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) + assert.Equal(t, int32(len(stmts)), span.Attributes[cassBatchQueriesKey].AsInt32()) controller.Stop() @@ -260,8 +260,8 @@ func TestBatch(t *testing.T) { Name: "cassandra.batch.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHostID("test-id"), - CassKeyspace(keyspace), + cassHostID("test-id"), + cassKeyspace(keyspace), }, Number: 1, }, @@ -269,8 +269,8 @@ func TestBatch(t *testing.T) { Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHostID("test-id"), - CassKeyspace(keyspace), + cassHostID("test-id"), + cassKeyspace(keyspace), }, }, } @@ -319,10 +319,10 @@ func TestConnection(t *testing.T) { // Verify the span attributes for _, span := range spans { assert.Equal(t, cassConnectName, span.Name) - assert.NotNil(t, span.Attributes[CassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[CassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[CassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[CassHostStateKey].AsString())) + assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) + assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) + assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) + assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) } // Verify the metrics @@ -331,8 +331,8 @@ func TestConnection(t *testing.T) { Name: "cassandra.connections", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - CassHost("127.0.0.1"), - CassHostID("test-id"), + cassHost("127.0.0.1"), + cassHostID("test-id"), }, }, } @@ -387,7 +387,7 @@ func recordEqual(t *testing.T, expected testRecord, actual export.Record) { assert.True(t, ok) assert.NotNil(t, actualValue) // Cant test equality of host id - if label.Key != CassHostIDKey { + if label.Key != cassHostIDKey { assert.Equal(t, label.Value, actualValue) } else { assert.NotEmpty(t, actualValue) diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 70c98ac782a..a843e95f22a 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -87,11 +87,11 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq attributes := append( defaultAttributes(host), - CassStatement(observedQuery.Statement), - CassRowsReturned(observedQuery.Rows), - CassQueryAttempts(observedQuery.Metrics.Attempts), - CassQueryAttemptNum(observedQuery.Attempt), - CassKeyspace(keyspace), + cassStatement(observedQuery.Statement), + cassRowsReturned(observedQuery.Rows), + cassQueryAttempts(observedQuery.Metrics.Attempts), + cassQueryAttemptNum(observedQuery.Attempt), + cassKeyspace(keyspace), ) ctx, span := o.cfg.tracer.Start( @@ -102,7 +102,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq ) if observedQuery.Err != nil { - span.SetAttributes(CassErrMsg(observedQuery.Err.Error())) + span.SetAttributes(cassErrMsg(observedQuery.Err.Error())) recordError(ctx, iQueryErrors, keyspace, host) } @@ -110,7 +110,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq queryLabels := append( defaultMetricLabels(keyspace, host), - CassStatement(observedQuery.Statement), + cassStatement(observedQuery.Statement), ) iQueryCount.Add( ctx, @@ -141,8 +141,8 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq keyspace := observedBatch.Keyspace attributes := append( defaultAttributes(host), - CassBatchQueries(len(observedBatch.Statements)), - CassKeyspace(keyspace), + cassBatchQueries(len(observedBatch.Statements)), + cassKeyspace(keyspace), ) ctx, span := o.cfg.tracer.Start( @@ -153,7 +153,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq ) if observedBatch.Err != nil { - span.SetAttributes(CassErrMsg(observedBatch.Err.Error())) + span.SetAttributes(cassErrMsg(observedBatch.Err.Error())) recordError(ctx, iBatchErrors, keyspace, host) } @@ -191,12 +191,12 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne ) if observedConnect.Err != nil { - span.SetAttributes(CassErrMsg(observedConnect.Err.Error())) + span.SetAttributes(cassErrMsg(observedConnect.Err.Error())) iConnectErrors.Add( o.ctx, 1, - CassHost(hostname), - CassHostID(host.HostID()), + cassHost(hostname), + cassHostID(host.HostID()), ) } @@ -205,8 +205,8 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne iConnectionCount.Add( o.ctx, 1, - CassHost(hostname), - CassHostID(host.HostID()), + cassHost(hostname), + cassHostID(host.HostID()), ) } @@ -231,19 +231,19 @@ func getHost(hostPort string) string { func defaultAttributes(host *gocql.HostInfo) []kv.KeyValue { hostnameAndPort := host.HostnameAndPort() return []kv.KeyValue{ - CassVersion(host.Version().String()), - CassHost(getHost(hostnameAndPort)), - CassPort(host.Port()), - CassHostState(host.State().String()), - CassHostID(host.HostID()), + cassVersion(host.Version().String()), + cassHost(getHost(hostnameAndPort)), + cassPort(host.Port()), + cassHostState(host.State().String()), + cassHostID(host.HostID()), } } // defaultMetricLabels returns an array of the default labels added to metrics. func defaultMetricLabels(keyspace string, host *gocql.HostInfo) []kv.KeyValue { return []kv.KeyValue{ - CassHostID(host.HostID()), - CassKeyspace(keyspace), + cassHostID(host.HostID()), + cassKeyspace(keyspace), } } @@ -253,7 +253,7 @@ func nanoToMilliseconds(ns int64) int64 { } func recordError(ctx context.Context, counter metric.Int64Counter, keyspace string, host *gocql.HostInfo) { - labels := append(defaultMetricLabels(keyspace, host), CassHostState(host.State().String())) + labels := append(defaultMetricLabels(keyspace, host), cassHostState(host.State().String())) counter.Add( ctx, 1, From f7cb0c757a5d5d4a64054a9b0cc24d07c5329beb Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 18:22:07 +0000 Subject: [PATCH 15/24] fix typos --- .../github.com/gocql/gocql/README.md | 23 ++++++++++--------- .../github.com/gocql/gocql/cass.go | 14 +++++------ .../github.com/gocql/gocql/gocql_test.go | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index 3980bbbf1ad..db61b0da34d 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -31,7 +31,18 @@ func main() { } ``` -You can customize the tracing session by passing any of the following options to `NewSessionWithTracing`: +In addition to using the convenience function, you can also manually set observers: + +```go +host := "localhost" +cluster := gocql.NewCluster(host) +cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ + tracer: global.Tracer("github.com/gocql/gocql"), +}) +session, err := cluster.CreateSession() +``` + +You can customize instrumentation by passing any of the following options to `NewSessionWithTracing`: | Function | Description | | -------- | ----------- | @@ -43,13 +54,3 @@ You can customize the tracing session by passing any of the following options to | `WithBatchInstrumentation(bool)` | To enable/disable tracing and metrics for batch queries. | | `WithConnectInstrumentation(bool)` | To enable/disable tracing and metrics for new connections. | -In addition to using the convenience function, you may also manually set the obsevers: - -```go -host := "localhost" -cluster := gocql.NewCluster(host) -cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ - tracer: global.Tracer("github.com/gocql/gocql"), -}) -session, err := cluster.CreateSession() -``` \ No newline at end of file diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index 40d0b4133eb..2c98ed99f1b 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -83,7 +83,7 @@ func cassHost(host string) kv.KeyValue { return cassHostKey.String(host) } -// cassHostID returns the id of the cassandra host as a keyvalue pair. +// cassHostID returns the id of the cassandra host as a KeyValue pair. func cassHostID(id string) kv.KeyValue { return cassHostIDKey.String(id) } @@ -99,7 +99,7 @@ func cassHostState(state string) kv.KeyValue { return cassHostStateKey.String(state) } -// cassKeyspace returns the keyspace of the session as a keyvalue pair. +// cassKeyspace returns the keyspace of the session as a KeyValue pair. func cassKeyspace(keyspace string) kv.KeyValue { return cassKeyspaceKey.String(keyspace) } @@ -111,31 +111,31 @@ func cassStatement(stmt string) kv.KeyValue { } // cassBatchQueries returns the number of queries in a batch query -// as a keyvalue pair. +// as a KeyValue pair. func cassBatchQueries(num int) kv.KeyValue { return cassBatchQueriesKey.Int(num) } -// cassErrMsg returns the keyvalue pair of an error message +// cassErrMsg returns the KeyValue pair of an error message // encountered when executing a query, batch query, or error. func cassErrMsg(msg string) kv.KeyValue { return cassErrMsgKey.String(msg) } -// cassRowsReturned returns the keyvalue pair of the number of rows +// cassRowsReturned returns the KeyValue pair of the number of rows // returned from a query. func cassRowsReturned(rows int) kv.KeyValue { return cassRowsReturnedKey.Int(rows) } -// cassQueryAttempts returns the keyvalue pair of the number of attempts +// cassQueryAttempts returns the KeyValue pair of the number of attempts // made for a query. func cassQueryAttempts(num int) kv.KeyValue { return cassQueryAttemptsKey.Int(num) } // cassQueryAttemptNum returns the 0-based index attempt number of a -// query as a keyvalue pair. +// query as a KeyValue pair. func cassQueryAttemptNum(num int) kv.KeyValue { return cassQueryAttemptNumKey.Int(num) } diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index b83fdcff215..4263685ba0c 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -386,7 +386,7 @@ func recordEqual(t *testing.T, expected testRecord, actual export.Record) { actualValue, ok := actual.Labels().Value(label.Key) assert.True(t, ok) assert.NotNil(t, actualValue) - // Cant test equality of host id + // Can't test equality of host id if label.Key != cassHostIDKey { assert.Equal(t, label.Value, actualValue) } else { From 846d51bc1131c68f032ef3f0713a7c9eeb4eeb0d Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 15:54:31 -0600 Subject: [PATCH 16/24] Export otelconfig --- .../github.com/gocql/gocql/README.md | 3 ++- .../github.com/gocql/gocql/config.go | 24 +++++++++---------- .../github.com/gocql/gocql/example/README.md | 2 +- .../github.com/gocql/gocql/example/client.go | 7 +++--- .../github.com/gocql/gocql/observer.go | 12 +++++----- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index db61b0da34d..129a8e23f8a 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -37,7 +37,8 @@ In addition to using the convenience function, you can also manually set observe host := "localhost" cluster := gocql.NewCluster(host) cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ - tracer: global.Tracer("github.com/gocql/gocql"), + Tracer: global.Tracer("github.com/gocql/gocql"), + InstrumentQuery: true, }) session, err := cluster.CreateSession() ``` diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index 9a1870a42e4..30b67a61b6f 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -31,10 +31,10 @@ type TracedSessionConfig struct { // OtelConfig provides OpenTelemetry configuration. type OtelConfig struct { - tracer trace.Tracer - instrumentQuery bool - instrumentBatch bool - instrumentConnect bool + Tracer trace.Tracer + InstrumentQuery bool + InstrumentBatch bool + InstrumentConnect bool } // TracedSessionOption is a function type that applies @@ -77,7 +77,7 @@ func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { // Defaults to global.Tracer("github.com/gocql/gocql"). func WithTracer(tracer trace.Tracer) TracedSessionOption { return func(c *TracedSessionConfig) { - c.otelConfig.tracer = tracer + c.otelConfig.Tracer = tracer } } @@ -85,7 +85,7 @@ func WithTracer(tracer trace.Tracer) TracedSessionOption { // queries. Defaults to enabled. func WithQueryInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.otelConfig.instrumentQuery = enabled + cfg.otelConfig.InstrumentQuery = enabled } } @@ -93,7 +93,7 @@ func WithQueryInstrumentation(enabled bool) TracedSessionOption { // batch queries. Defaults to enabled. func WithBatchInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.otelConfig.instrumentBatch = enabled + cfg.otelConfig.InstrumentBatch = enabled } } @@ -101,7 +101,7 @@ func WithBatchInstrumentation(enabled bool) TracedSessionOption { // connection attempts. Defaults to enabled. func WithConnectInstrumentation(enabled bool) TracedSessionOption { return func(cfg *TracedSessionConfig) { - cfg.otelConfig.instrumentConnect = enabled + cfg.otelConfig.InstrumentConnect = enabled } } @@ -121,9 +121,9 @@ func configure(options ...TracedSessionOption) *TracedSessionConfig { func otelConfiguration() *OtelConfig { return &OtelConfig{ - tracer: global.Tracer("github.com/gocql/gocql"), - instrumentQuery: true, - instrumentBatch: true, - instrumentConnect: true, + Tracer: global.Tracer("github.com/gocql/gocql"), + InstrumentQuery: true, + InstrumentBatch: true, + InstrumentConnect: true, } } diff --git a/instrumentation/github.com/gocql/gocql/example/README.md b/instrumentation/github.com/gocql/gocql/example/README.md index 0ade422ce1a..a2c7683f15f 100644 --- a/instrumentation/github.com/gocql/gocql/example/README.md +++ b/instrumentation/github.com/gocql/gocql/example/README.md @@ -14,5 +14,5 @@ Server.java:159 - Starting listening for CQL clients on /0.0.0.0:9042 (unencrypt 5. You can view the spans in the browser at `localhost:9411` and the metrics at `localhost:2222`. ### When you're done: -1. `ctrl+c` to kill the example program. +1. `ctrl+c` to stop the example program. 2. `docker-compose down` to stop cassandra and zipkin. diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index bb1eb3b523f..7683ed3821c 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// The Cassandra docker container conatains the -// "gocql-integration-example" keyspace and a single table +// This example will create the keyspace +// "gocql-integration-example" and a single table // with the following schema: // gocql_integration_example.book // id UUID @@ -21,7 +21,8 @@ // author_first_name text // author_last_name text // PRIMARY KEY(id) -// The example will insert fictional books into the database. +// The example will insert fictional books into the database and +// then truncate the table. package main diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index a843e95f22a..67aaa6969ff 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -81,7 +81,7 @@ func NewConnectObserver(ctx context.Context, observer gocql.ConnectObserver, cfg // ObserveQuery instruments a specific query. func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { - if o.cfg.instrumentQuery { + if o.cfg.InstrumentQuery { host := observedQuery.Host keyspace := observedQuery.Keyspace @@ -94,7 +94,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq cassKeyspace(keyspace), ) - ctx, span := o.cfg.tracer.Start( + ctx, span := o.cfg.Tracer.Start( ctx, cassQueryName, trace.WithStartTime(observedQuery.Start), @@ -136,7 +136,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq // ObserveBatch instruments a specific batch query. func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { - if o.cfg.instrumentBatch { + if o.cfg.InstrumentBatch { host := observedBatch.Host keyspace := observedBatch.Keyspace attributes := append( @@ -145,7 +145,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq cassKeyspace(keyspace), ) - ctx, span := o.cfg.tracer.Start( + ctx, span := o.cfg.Tracer.Start( ctx, cassBatchQueryName, trace.WithStartTime(observedBatch.Start), @@ -178,12 +178,12 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq // ObserveConnect instruments a specific connection attempt. func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { - if o.cfg.instrumentConnect { + if o.cfg.InstrumentConnect { host := observedConnect.Host hostname := getHost(host.HostnameAndPort()) attributes := defaultAttributes(observedConnect.Host) - _, span := o.cfg.tracer.Start( + _, span := o.cfg.Tracer.Start( o.ctx, cassConnectName, trace.WithStartTime(observedConnect.Start), From b94fcaa215abcc08fb8db80467a72bbc8c5eadad Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 16:09:21 -0600 Subject: [PATCH 17/24] Fix lint --- instrumentation/github.com/gocql/gocql/config.go | 1 + .../github.com/gocql/gocql/example/client.go | 2 +- .../github.com/gocql/gocql/example/db.go | 3 +++ .../github.com/gocql/gocql/gocql_test.go | 15 +++++++-------- .../github.com/gocql/gocql/observer.go | 1 + 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index 30b67a61b6f..039c03a67b0 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -16,6 +16,7 @@ package gocql import ( "github.com/gocql/gocql" + "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/api/trace" ) diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index 7683ed3821c..76921e794da 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -13,7 +13,7 @@ // limitations under the License. // This example will create the keyspace -// "gocql-integration-example" and a single table +// "gocql_integration_example" and a single table // with the following schema: // gocql_integration_example.book // id UUID diff --git a/instrumentation/github.com/gocql/gocql/example/db.go b/instrumentation/github.com/gocql/gocql/example/db.go index 71a36d35c00..61ad6bae61b 100644 --- a/instrumentation/github.com/gocql/gocql/example/db.go +++ b/instrumentation/github.com/gocql/gocql/example/db.go @@ -39,6 +39,9 @@ func initDb() { cluster.Keyspace = keyspace session, err = cluster.CreateSession() + if err != nil { + log.Fatal(err) + } stmt = "create table if not exists book(id UUID, title text, author_first_name text, author_last_name text, PRIMARY KEY(id))" if err = session.Query(stmt).Exec(); err != nil { diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 4263685ba0c..50da61eeff2 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -28,6 +28,7 @@ import ( "github.com/gocql/gocql" "github.com/stretchr/testify/assert" + mocktracer "go.opentelemetry.io/contrib/internal/trace" "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" @@ -136,7 +137,6 @@ func TestQuery(t *testing.T) { case cassQueryName: assert.Equal(t, insertStmt, span.Attributes[cassStatementKey].AsString()) assert.Equal(t, parentSpan.SpanContext().SpanID.String(), span.ParentSpanID.String()) - break default: t.Fatalf("unexpected span name %s", span.Name) } @@ -151,7 +151,7 @@ func TestQuery(t *testing.T) { assert.Equal(t, 3, len(exporter.records)) expected := []testRecord{ - testRecord{ + { Name: "cassandra.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ @@ -161,7 +161,7 @@ func TestQuery(t *testing.T) { }, Number: 1, }, - testRecord{ + { Name: "cassandra.rows", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ @@ -170,7 +170,7 @@ func TestQuery(t *testing.T) { }, Number: 0, }, - testRecord{ + { Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ @@ -187,7 +187,6 @@ func TestQuery(t *testing.T) { case "cassandra.queries": recordEqual(t, expected[0], record) numberEqual(t, expected[0].Number, agg) - break case "cassandra.rows": recordEqual(t, expected[1], record) numberEqual(t, expected[1].Number, agg) @@ -256,7 +255,7 @@ func TestBatch(t *testing.T) { // Check metrics assert.Equal(t, 2, len(exporter.records)) expected := []testRecord{ - testRecord{ + { Name: "cassandra.batch.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ @@ -265,7 +264,7 @@ func TestBatch(t *testing.T) { }, Number: 1, }, - testRecord{ + { Name: "cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ @@ -327,7 +326,7 @@ func TestConnection(t *testing.T) { // Verify the metrics expected := []testRecord{ - testRecord{ + { Name: "cassandra.connections", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 67aaa6969ff..56071e32c1a 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -20,6 +20,7 @@ import ( "time" "github.com/gocql/gocql" + "go.opentelemetry.io/otel/api/kv" "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" From 20fedd9434b53b46cee9173bca9c3a30613244ed Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 16:14:48 -0600 Subject: [PATCH 18/24] Delete prometheus.yml --- .../gocql/gocql/example/prometheus.yml | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 instrumentation/github.com/gocql/gocql/example/prometheus.yml diff --git a/instrumentation/github.com/gocql/gocql/example/prometheus.yml b/instrumentation/github.com/gocql/gocql/example/prometheus.yml deleted file mode 100644 index 5d04ef89d67..00000000000 --- a/instrumentation/github.com/gocql/gocql/example/prometheus.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -global: - scrape_interval: 15s # Default is every 1 minute. - -scrape_configs: - - job_name: 'opentelemetry' - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. - static_configs: - - targets: ['localhost:9464'] \ No newline at end of file From 05dd54fcbe196f52e57e6df4a134151b7d387f9c Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 16 Jul 2020 16:42:24 -0600 Subject: [PATCH 19/24] Fix comments --- .../github.com/gocql/gocql/gocql_test.go | 20 ++++++++----------- .../github.com/gocql/gocql/instrument.go | 2 +- .../github.com/gocql/gocql/observer.go | 8 ++++---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 50da61eeff2..e887f26978f 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -221,13 +221,11 @@ func TestBatch(t *testing.T) { defer session.Close() batch := session.NewBatch(gocql.LoggedBatch).WithContext(ctx) - ids := make([]gocql.UUID, 10) - stmts := make([]string, 10) for i := 0; i < 10; i++ { - ids[i] = gocql.TimeUUID() + id := gocql.TimeUUID() title := fmt.Sprintf("batch-title-%d", i) - stmts[i] = fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) - batch.Query(stmts[i], ids[i], title) + stmt := fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) + batch.Query(stmt, id, title) } err = session.ExecuteBatch(batch) @@ -248,7 +246,7 @@ func TestBatch(t *testing.T) { assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) - assert.Equal(t, int32(len(stmts)), span.Attributes[cassBatchQueriesKey].AsInt32()) + assert.Equal(t, int32(10), span.Attributes[cassBatchQueriesKey].AsInt32()) controller.Stop() @@ -368,8 +366,8 @@ func getCluster() *gocql.ClusterConfig { return cluster } -// beforeEach creates a metric export pipeline with mockExporter -// to enable testing metric collection. +// getController returns the push controller for the mock +// export pipeline. func getController(t *testing.T) *push.Controller { controller := mockExportPipeline(t) InstrumentWithProvider(controller.Provider()) @@ -422,9 +420,7 @@ func numberEqual(t *testing.T, expected metric.Number, agg aggregation.Aggregati } } -// beforeAll recreates the testing keyspace so that a new table -// can be created. This allows the test to be run multiple times -// consecutively withouth any issues arising. +// beforeAll creates the testing keyspace and table if they do not already exist. func beforeAll() { cluster := gocql.NewCluster("localhost") cluster.Consistency = gocql.LocalQuorum @@ -459,7 +455,7 @@ func beforeAll() { } } -// afterEach removes the keyspace from the database for later test sessions. +// afterEach truncates the table used for testing. func afterEach() { cluster := gocql.NewCluster("localhost") cluster.Consistency = gocql.LocalQuorum diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index b12cadb1f9d..21820af2504 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -65,7 +65,7 @@ func InstrumentWithProvider(p metric.Provider) { iQueryCount = meter.NewInt64Counter( "cassandra.queries", - metric.WithDescription("Number queries executed"), + metric.WithDescription("Number of queries executed"), ) iQueryErrors = meter.NewInt64Counter( diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 56071e32c1a..050f4a59fc2 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -51,7 +51,7 @@ type OtelConnectObserver struct { // ----------------------------------------- Constructor Functions // NewQueryObserver creates a QueryObserver that provides OpenTelemetry -// tracing and metrics. +// instrumentation for queries. func NewQueryObserver(observer gocql.QueryObserver, cfg *OtelConfig) gocql.QueryObserver { return &OtelQueryObserver{ observer, @@ -80,7 +80,7 @@ func NewConnectObserver(ctx context.Context, observer gocql.ConnectObserver, cfg // ------------------------------------------ Observer Functions -// ObserveQuery instruments a specific query. +// ObserveQuery is called once per query, and provides instrumentation for it. func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { if o.cfg.InstrumentQuery { host := observedQuery.Host @@ -135,7 +135,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq } } -// ObserveBatch instruments a specific batch query. +// ObserveBatch is called once per batch query, and provides instrumentation for it. func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { if o.cfg.InstrumentBatch { host := observedBatch.Host @@ -177,7 +177,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq } } -// ObserveConnect instruments a specific connection attempt. +// ObserveConnect is called once per connection attempt, and provides instrumentation for it. func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { if o.cfg.InstrumentConnect { host := observedConnect.Host From 31e2e1ff68a4b71ad3d1f994e36b1b5213f23227 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Fri, 24 Jul 2020 16:50:17 +0000 Subject: [PATCH 20/24] Addressed pr feedback by refactoring attributes and labels to conform to semantic conventions --- .../github.com/gocql/gocql/README.md | 38 ++--- .../github.com/gocql/gocql/cass.go | 132 ++++++++------- .../github.com/gocql/gocql/example/client.go | 35 ++++ .../github.com/gocql/gocql/example/db.go | 54 ------- .../github.com/gocql/gocql/example/go.mod | 9 +- .../github.com/gocql/gocql/example/go.sum | 32 ++-- instrumentation/github.com/gocql/gocql/go.mod | 5 +- instrumentation/github.com/gocql/gocql/go.sum | 14 +- .../github.com/gocql/gocql/gocql_test.go | 153 ++++++++++++------ .../github.com/gocql/gocql/instrument.go | 81 ++++------ .../github.com/gocql/gocql/observer.go | 149 ++++++++--------- 11 files changed, 371 insertions(+), 331 deletions(-) delete mode 100644 instrumentation/github.com/gocql/gocql/example/db.go diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index 129a8e23f8a..36fc34026fe 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -8,26 +8,26 @@ To enable tracing in your application: package main import ( - "context" - - "github.com/gocql/gocql" - otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" + "context" + + "github.com/gocql/gocql" + otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" ) func main() { - // Create a cluster - host := "localhost" - cluster := gocql.NewCluster(host) - - // Create a session with tracing - session, err := otelGocql.NewSessionWithTracing( - context.Background(), - cluster, - // Include any options here - ) - - // Begin using the session - + // Create a cluster + host := "localhost" + cluster := gocql.NewCluster(host) + + // Create a session with tracing + session, err := otelGocql.NewSessionWithTracing( + context.Background(), + cluster, + // Include any options here + ) + + // Begin using the session + } ``` @@ -37,8 +37,8 @@ In addition to using the convenience function, you can also manually set observe host := "localhost" cluster := gocql.NewCluster(host) cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ - Tracer: global.Tracer("github.com/gocql/gocql"), - InstrumentQuery: true, + Tracer: global.Tracer("github.com/gocql/gocql"), + InstrumentQuery: true, }) session, err := cluster.CreateSession() ``` diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index 2c98ed99f1b..81e94071bf1 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -14,100 +14,116 @@ package gocql -import "go.opentelemetry.io/otel/api/kv" +import ( + "go.opentelemetry.io/otel/api/kv" + "go.opentelemetry.io/otel/api/standard" +) const ( - // cassVersionKey is the key for the span attribute describing + // cassVersionKey is the key for the attribute/label describing // the cql version. - cassVersionKey = kv.Key("cassandra.version") - - // cassHostKey is the key for the span attribute describing - // the host of the cassandra instance being queried. - cassHostKey = kv.Key("cassandra.host") + cassVersionKey = kv.Key("db.cassandra.version") - // cassHostIDKey is the key for the metric label describing the id + // cassHostIDKey is the key for the attribute/label describing the id // of the host being queried. - cassHostIDKey = kv.Key("cassandra.host.id") + cassHostIDKey = kv.Key("db.cassandra.host.id") - // cassPortKey is the key for the span attribute describing - // the port of the cassandra server being queried. - cassPortKey = kv.Key("cassandra.port") - - // cassHostStateKey is the key for the span attribute describing + // cassHostStateKey is the key for the attribute/label describing // the state of the casssandra server hosting the node being queried. - cassHostStateKey = kv.Key("cassandra.host.state") - - // cassKeyspaceKey is the key for the KeyValue pair describing the - // keyspace of the current session. - cassKeyspaceKey = kv.Key("cassandra.keyspace") + cassHostStateKey = kv.Key("db.cassandra.host.state") - // cassStatementKey is the key for the span attribute describing the - // the statement used to query the cassandra database. - // This attribute will only be found on a span for a query. - cassStatementKey = kv.Key("cassandra.stmt") - - // cassBatchQueriesKey is the key for the span attributed describing + // cassBatchQueriesKey is the key for the attribute describing // the number of queries contained within the batch statement. - cassBatchQueriesKey = kv.Key("cassandra.batch.queries") + cassBatchQueriesKey = kv.Key("db.cassandra.batch.queries") - // cassErrMsgKey is the key for the span attribute describing + // cassErrMsgKey is the key for the attribute/label describing // the error message from an error encountered when executing a query, batch, // or connection attempt to the cassandra server. - cassErrMsgKey = kv.Key("cassandra.err.msg") + cassErrMsgKey = kv.Key("db.cassandra.error.message") // cassRowsReturnedKey is the key for the span attribute describing the number of rows // returned on a query to the database. - cassRowsReturnedKey = kv.Key("cassandra.rows.returned") + cassRowsReturnedKey = kv.Key("db.cassandra.rows.returned") // cassQueryAttemptsKey is the key for the span attribute describing the number of attempts // made for the query in question. - cassQueryAttemptsKey = kv.Key("cassandra.attempts") - - // cassQueryAttemptNumKey is the key for the span attribute describing - // which attempt the current query is as a 0-based index. - cassQueryAttemptNumKey = kv.Key("cassandra.attempt") + cassQueryAttemptsKey = kv.Key("db.cassandra.attempts") - // Names of the spans for query, batch query, and connect respectively. - cassQueryName = "cassandra.query" - cassBatchQueryName = "cassandra.batch.query" - cassConnectName = "cassandra.connect" + // Static span names + cassBatchQueryName = "Batch Query" + cassConnectName = "New Connection" ) +// ------------------------------------------ Connection-level Attributes + +// cassDBSystem returns the name of the DB system, +// cassandra, as a KeyValue pair (db.system). +func cassDBSystem() kv.KeyValue { + return standard.DBSystemCassandra +} + +// cassPeerName returns the hostname of the cassandra +// server as a standard KeyValue pair (net.peer.name). +func cassPeerName(name string) kv.KeyValue { + return standard.NetPeerNameKey.String(name) +} + +// cassPeerPort returns the port number of the cassandra +// server as a standard KeyValue pair (net.peer.port). +func cassPeerPort(port int) kv.KeyValue { + return standard.NetPeerPortKey.Int(port) +} + +// cassPeerIP returns the IP address of the cassandra +// server as a standard KeyValue pair (net.peer.ip). +func cassPeerIP(ip string) kv.KeyValue { + return standard.NetPeerIPKey.String(ip) +} + // cassVersion returns the cql version as a KeyValue pair. func cassVersion(version string) kv.KeyValue { return cassVersionKey.String(version) } -// cassHost returns the cassandra host as a KeyValue pair. -func cassHost(host string) kv.KeyValue { - return cassHostKey.String(host) -} - // cassHostID returns the id of the cassandra host as a KeyValue pair. func cassHostID(id string) kv.KeyValue { return cassHostIDKey.String(id) } -// cassPort returns the port of the cassandra node being queried -// as a KeyValue pair. -func cassPort(port int) kv.KeyValue { - return cassPortKey.Int(port) -} - // cassHostState returns the state of the cassandra host as a KeyValue pair. func cassHostState(state string) kv.KeyValue { return cassHostStateKey.String(state) } -// cassKeyspace returns the keyspace of the session as a KeyValue pair. -func cassKeyspace(keyspace string) kv.KeyValue { - return cassKeyspaceKey.String(keyspace) -} +// ------------------------------------------ Call-level attributes // cassStatement returns the statement made to the cassandra database as a -// KeyValue pair. +// standard KeyValue pair (db.statement). func cassStatement(stmt string) kv.KeyValue { - return cassStatementKey.String(stmt) + return standard.DBStatementKey.String(stmt) +} + +// cassDBOperation returns the batch query operation +// as a standard KeyValue pair (db.operation). This is used in lieu of a +// db.statement, which is not feasible to include in a span for a batch query +// because there can be n different query statements in a batch query. +func cassBatchQueryOperation() kv.KeyValue { + cassBatchQueryOperation := "db.cassandra.batch.query" + return standard.DBOperationKey.String(cassBatchQueryOperation) +} + +// cassConnectOperation returns the connect operation +// as a standard KeyValue pair (db.operation). This is used in lieu of a +// db.statement since connection creation does not have a CQL statement. +func cassConnectOperation() kv.KeyValue { + cassConnectOperation := "db.cassandra.connect" + return standard.DBOperationKey.String(cassConnectOperation) +} + +// cassKeyspace returns the keyspace of the session as +// a standard KeyValue pair (db.cassandra.keyspace). +func cassKeyspace(keyspace string) kv.KeyValue { + return standard.DBCassandraKeyspaceKey.String(keyspace) } // cassBatchQueries returns the number of queries in a batch query @@ -133,9 +149,3 @@ func cassRowsReturned(rows int) kv.KeyValue { func cassQueryAttempts(num int) kv.KeyValue { return cassQueryAttemptsKey.Int(num) } - -// cassQueryAttemptNum returns the 0-based index attempt number of a -// query as a KeyValue pair. -func cassQueryAttemptNum(num int) kv.KeyValue { - return cassQueryAttemptNumKey.Int(num) -} diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index 76921e794da..7e828c98702 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -34,6 +34,7 @@ import ( "os" "os/signal" "sync" + "time" "github.com/gocql/gocql" @@ -161,10 +162,44 @@ func initTracer() { global.SetTraceProvider(provider) } +func initDb() { + cluster := gocql.NewCluster("127.0.0.1") + cluster.Keyspace = "system" + cluster.Consistency = gocql.LocalQuorum + cluster.Timeout = time.Second * 2 + session, err := cluster.CreateSession() + if err != nil { + log.Fatal(err) + } + stmt := fmt.Sprintf( + "create keyspace if not exists %s with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", + keyspace, + ) + if err := session.Query(stmt).Exec(); err != nil { + log.Fatal(err) + } + + cluster.Keyspace = keyspace + session, err = cluster.CreateSession() + if err != nil { + log.Fatal(err) + } + + stmt = "create table if not exists book(id UUID, title text, author_first_name text, author_last_name text, PRIMARY KEY(id))" + if err = session.Query(stmt).Exec(); err != nil { + log.Fatal(err) + } + + if err := session.Query("create index if not exists on book(author_last_name)").Exec(); err != nil { + log.Fatal(err) + } +} + func getCluster() *gocql.ClusterConfig { cluster := gocql.NewCluster("127.0.0.1") cluster.Keyspace = keyspace cluster.Consistency = gocql.LocalQuorum cluster.ProtoVersion = 3 + cluster.Timeout = 2 * time.Second return cluster } diff --git a/instrumentation/github.com/gocql/gocql/example/db.go b/instrumentation/github.com/gocql/gocql/example/db.go deleted file mode 100644 index 61ad6bae61b..00000000000 --- a/instrumentation/github.com/gocql/gocql/example/db.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright The OpenTelemetry Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "fmt" - "log" - - "github.com/gocql/gocql" -) - -func initDb() { - cluster := gocql.NewCluster("127.0.0.1") - cluster.Keyspace = "system" - cluster.Consistency = gocql.LocalQuorum - session, err := cluster.CreateSession() - if err != nil { - log.Fatal(err) - } - stmt := fmt.Sprintf( - "create keyspace if not exists %s with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }", - keyspace, - ) - if err := session.Query(stmt).Exec(); err != nil { - log.Fatal(err) - } - - cluster.Keyspace = keyspace - session, err = cluster.CreateSession() - if err != nil { - log.Fatal(err) - } - - stmt = "create table if not exists book(id UUID, title text, author_first_name text, author_last_name text, PRIMARY KEY(id))" - if err = session.Query(stmt).Exec(); err != nil { - log.Fatal(err) - } - - if err := session.Query("create index if not exists on book(author_last_name)").Exec(); err != nil { - log.Fatal(err) - } -} diff --git a/instrumentation/github.com/gocql/gocql/example/go.mod b/instrumentation/github.com/gocql/gocql/example/go.mod index 1101fe5d2ba..c0351d7469a 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.mod +++ b/instrumentation/github.com/gocql/gocql/example/go.mod @@ -3,11 +3,14 @@ module go.opentelemetry.io/contrib/github.com/gocql/gocql/example go 1.14 require ( + github.com/DataDog/sketches-go v0.0.1 // indirect github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e go.opentelemetry.io/contrib/github.com/gocql/gocql v0.0.0 - go.opentelemetry.io/otel v0.8.0 - go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0 - go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0 + go.opentelemetry.io/otel v0.9.0 + go.opentelemetry.io/otel/exporters/metric/prometheus v0.9.0 + go.opentelemetry.io/otel/exporters/trace/zipkin v0.9.0 + golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6 // indirect + google.golang.org/protobuf v1.25.0 // indirect ) // TODO: remove diff --git a/instrumentation/github.com/gocql/gocql/example/go.sum b/instrumentation/github.com/gocql/gocql/example/go.sum index 5bd99b870ab..b072602d8f7 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.sum +++ b/instrumentation/github.com/gocql/gocql/example/go.sum @@ -2,6 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7 h1:qELHH0AWCvf98Yf+CNIJx9vOZOfHFDDzgDRYsnNk/vs= github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60= +github.com/DataDog/sketches-go v0.0.1 h1:RtG+76WKgZuz6FIaGsjoPePmadDBkuD/KC6+ZWu78b8= +github.com/DataDog/sketches-go v0.0.1/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -56,12 +58,15 @@ github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:x github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -96,7 +101,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/openzipkin/zipkin-go v0.2.2 h1:nY8Hti+WKaP0cRsSeQ026wU03QsM762XBeCXBb9NAWI= github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= @@ -133,16 +137,14 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.opentelemetry.io/contrib v0.7.0 h1:6IuKhaeEk+uxX5icJCdsgqlDVbsbDEPFD6NcHCDp9QI= -go.opentelemetry.io/contrib v0.7.0/go.mod h1:g4BXWOrb66AyXbXlSgfGWR7TQzXQX4Oq2NidBrSwZPM= -go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0= -go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo= -go.opentelemetry.io/otel v0.8.0 h1:he/8j/EBlKjENVtDvFalawIUcQ+1E3uHRsvJZWLIa7M= -go.opentelemetry.io/otel v0.8.0/go.mod h1:ckxzUEfk7tAkTwEMVdkllBM+YOfE/K9iwg6zYntFYSg= -go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0 h1:xx6oiW/vBazlT54mPPY0NcIIx6fCvfb8Ouj791KC4XE= -go.opentelemetry.io/otel/exporters/metric/prometheus v0.8.0/go.mod h1:pI1yrP+VSHWiXIjUpM8cSVCcJ93wIINZNlD3McNkEvY= -go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0 h1:CcMuR0SK/4OCnDjQleq0WwnSe2/bVQ34r23EubOwioU= -go.opentelemetry.io/otel/exporters/trace/zipkin v0.8.0/go.mod h1:ci5ENfbinkRc9aD5EdaR7IbQB1K9R03JXstvfhvdfw4= +go.opentelemetry.io/contrib v0.9.0 h1:4FgJizPVyLabjo4BDy9yJC8NvVbSYjqEHwHBRz3u2vQ= +go.opentelemetry.io/contrib v0.9.0/go.mod h1:LGBQF/ydvt3WgH9NbFNzsFFwIkzTBFcJNiVkEQ165/Q= +go.opentelemetry.io/otel v0.9.0 h1:nsdCDHzQx1Yv8E2nwCPcMXMfg+EMIlx1LBOXNC8qSQ8= +go.opentelemetry.io/otel v0.9.0/go.mod h1:ckxzUEfk7tAkTwEMVdkllBM+YOfE/K9iwg6zYntFYSg= +go.opentelemetry.io/otel/exporters/metric/prometheus v0.9.0 h1:Q06RcQzoI7eeXOsdUROTx71TktUNdpCJT0FJJJAq9cQ= +go.opentelemetry.io/otel/exporters/metric/prometheus v0.9.0/go.mod h1:za3FCvOkKCM3H9RpkseWpKVF3RApyQj4WNnpaBjB3Mc= +go.opentelemetry.io/otel/exporters/trace/zipkin v0.9.0 h1:Ndk6Ajf2fLEq9/yCxwlVPG8DiARTJMp4D2gkVGB9vUw= +go.opentelemetry.io/otel/exporters/trace/zipkin v0.9.0/go.mod h1:dZhgw4MjVLIWEgKZZVNw6FyE0FhLPTB2QgqXWi1bjxM= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -171,6 +173,8 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6 h1:X9xIZ1YU8bLZA3l6gqDUHSFiD0GFI9S548h6C8nDtOY= +golang.org/x/sys v0.0.0-20200722175500-76b94024e4b6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -185,6 +189,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 h1:MRHtG0U6SnaUb+s+LhNE1qt1FQ1wlhqr5E4usBKC0uA= google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= @@ -197,8 +203,12 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= diff --git a/instrumentation/github.com/gocql/gocql/go.mod b/instrumentation/github.com/gocql/gocql/go.mod index ef1c3c4fa56..d1bbbb2a9a5 100644 --- a/instrumentation/github.com/gocql/gocql/go.mod +++ b/instrumentation/github.com/gocql/gocql/go.mod @@ -4,8 +4,9 @@ go 1.14 require ( github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e + github.com/golang/snappy v0.0.1 // indirect github.com/stretchr/testify v1.6.1 - go.opentelemetry.io/contrib v0.7.0 - go.opentelemetry.io/otel v0.7.0 + go.opentelemetry.io/contrib v0.9.0 + go.opentelemetry.io/otel v0.9.0 google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 // indirect ) diff --git a/instrumentation/github.com/gocql/gocql/go.sum b/instrumentation/github.com/gocql/gocql/go.sum index 35331c8727d..6e795f3ffec 100644 --- a/instrumentation/github.com/gocql/gocql/go.sum +++ b/instrumentation/github.com/gocql/gocql/go.sum @@ -35,6 +35,8 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20170215233205-553a64147049 h1:K9KHZbXKpGydfDN0aZrsoHpLJlZsBrGMFWbgLDGnPZk= github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -50,7 +52,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -59,10 +61,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -go.opentelemetry.io/contrib v0.7.0 h1:6IuKhaeEk+uxX5icJCdsgqlDVbsbDEPFD6NcHCDp9QI= -go.opentelemetry.io/contrib v0.7.0/go.mod h1:g4BXWOrb66AyXbXlSgfGWR7TQzXQX4Oq2NidBrSwZPM= -go.opentelemetry.io/otel v0.7.0 h1:u43jukpwqR8EsyeJOMgrsUgZwVI1e1eVw7yuzRkD1l0= -go.opentelemetry.io/otel v0.7.0/go.mod h1:aZMyHG5TqDOXEgH2tyLiXSUKly1jT3yqE9PmrzIeCdo= +go.opentelemetry.io/contrib v0.9.0 h1:4FgJizPVyLabjo4BDy9yJC8NvVbSYjqEHwHBRz3u2vQ= +go.opentelemetry.io/contrib v0.9.0/go.mod h1:LGBQF/ydvt3WgH9NbFNzsFFwIkzTBFcJNiVkEQ165/Q= +go.opentelemetry.io/otel v0.9.0 h1:nsdCDHzQx1Yv8E2nwCPcMXMfg+EMIlx1LBOXNC8qSQ8= +go.opentelemetry.io/otel v0.9.0/go.mod h1:ckxzUEfk7tAkTwEMVdkllBM+YOfE/K9iwg6zYntFYSg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -73,6 +75,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -80,6 +83,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index e887f26978f..3134f495911 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -23,6 +23,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + + "go.opentelemetry.io/otel/api/standard" + "go.opentelemetry.io/otel/sdk/metric/controller/push" "go.opentelemetry.io/otel/sdk/metric/selector/simple" @@ -107,17 +111,16 @@ func TestQuery(t *testing.T) { WithTracer(tracer), WithConnectInstrumentation(false), ) - assert.NoError(t, err) + require.NoError(t, err) defer session.Close() + require.NoError(t, session.AwaitSchemaAgreement(ctx)) id := gocql.TimeUUID() title := "example-title" insertStmt := fmt.Sprintf("insert into %s (id, title) values (?, ?)", tableName) query := session.Query(insertStmt, id, title).WithContext(ctx) assert.NotNil(t, query, "expected query to not be nil") - if err := query.Exec(); err != nil { - t.Fatal(err.Error()) - } + require.NoError(t, query.Exec()) parentSpan.End() @@ -128,53 +131,65 @@ func TestQuery(t *testing.T) { // total spans: // 1 span for the Query // 1 span created in test - assert.Equal(t, 2, len(spans)) + require.Len(t, spans, 2) // Verify attributes are correctly added to the spans. Omit the one local span for _, span := range spans[0 : len(spans)-1] { switch span.Name { - case cassQueryName: - assert.Equal(t, insertStmt, span.Attributes[cassStatementKey].AsString()) + case insertStmt: + assert.Equal(t, insertStmt, span.Attributes[standard.DBStatementKey].AsString()) assert.Equal(t, parentSpan.SpanContext().SpanID.String(), span.ParentSpanID.String()) default: t.Fatalf("unexpected span name %s", span.Name) } - assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) + assertConnectionLevelAttributes(t, span) } // Check metrics controller.Stop() - assert.Equal(t, 3, len(exporter.records)) + require.Len(t, exporter.records, 3) expected := []testRecord{ { - Name: "cassandra.queries", + Name: "db.cassandra.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), cassKeyspace(keyspace), cassStatement(insertStmt), }, Number: 1, }, { - Name: "cassandra.rows", + Name: "db.cassandra.rows", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), cassKeyspace(keyspace), }, Number: 0, }, { - Name: "cassandra.latency", + Name: "db.cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), cassKeyspace(keyspace), }, }, @@ -184,13 +199,13 @@ func TestQuery(t *testing.T) { name := record.Descriptor().Name() agg := record.Aggregation() switch name { - case "cassandra.queries": + case "db.cassandra.queries": recordEqual(t, expected[0], record) numberEqual(t, expected[0].Number, agg) - case "cassandra.rows": + case "db.cassandra.rows": recordEqual(t, expected[1], record) numberEqual(t, expected[1].Number, agg) - case "cassandra.latency": + case "db.cassandra.latency": recordEqual(t, expected[2], record) // The latency will vary, so just check that it exists if _, ok := agg.(aggregation.MinMaxSumCount); !ok { @@ -217,8 +232,9 @@ func TestBatch(t *testing.T) { WithTracer(tracer), WithConnectInstrumentation(false), ) - assert.NoError(t, err) + require.NoError(t, err) defer session.Close() + require.NoError(t, session.AwaitSchemaAgreement(ctx)) batch := session.NewBatch(gocql.LoggedBatch).WithContext(ctx) for i := 0; i < 10; i++ { @@ -228,8 +244,7 @@ func TestBatch(t *testing.T) { batch.Query(stmt, id, title) } - err = session.ExecuteBatch(batch) - assert.NoError(t, err) + require.NoError(t, session.ExecuteBatch(batch)) parentSpan.End() @@ -237,36 +252,45 @@ func TestBatch(t *testing.T) { // total spans: // 1 span for the query // 1 span for the local span - assert.Equal(t, 2, len(spans)) - span := spans[0] - - assert.Equal(t, cassBatchQueryName, span.Name) - assert.Equal(t, parentSpan.SpanContext().SpanID, span.ParentSpanID) - assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) - assert.Equal(t, int32(10), span.Attributes[cassBatchQueriesKey].AsInt32()) + if assert.Len(t, spans, 2) { + span := spans[0] + assert.Equal(t, cassBatchQueryName, span.Name) + assert.Equal(t, parentSpan.SpanContext().SpanID, span.ParentSpanID) + assert.Equal(t, "db.cassandra.batch.query", + span.Attributes[standard.DBOperationKey].AsString(), + ) + assertConnectionLevelAttributes(t, span) + } controller.Stop() // Check metrics - assert.Equal(t, 2, len(exporter.records)) + require.Len(t, exporter.records, 2) expected := []testRecord{ { - Name: "cassandra.batch.queries", + Name: "db.cassandra.batch.queries", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), cassKeyspace(keyspace), }, Number: 1, }, { - Name: "cassandra.latency", + Name: "db.cassandra.latency", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), cassKeyspace(keyspace), }, }, @@ -276,10 +300,10 @@ func TestBatch(t *testing.T) { name := record.Descriptor().Name() agg := record.Aggregation() switch name { - case "cassandra.batch.queries": + case "db.cassandra.batch.queries": recordEqual(t, expected[0], record) numberEqual(t, expected[0].Number, agg) - case "cassandra.latency": + case "db.cassandra.latency": recordEqual(t, expected[1], record) if _, ok := agg.(aggregation.MinMaxSumCount); !ok { t.Fatal("missing aggregation in latency record") @@ -297,15 +321,17 @@ func TestConnection(t *testing.T) { cluster := getCluster() tracer := mocktracer.NewTracer("gocql-test") connectObserver := &mockConnectObserver{0} + ctx := context.Background() session, err := NewSessionWithTracing( - context.Background(), + ctx, cluster, WithTracer(tracer), WithConnectObserver(connectObserver), ) - assert.NoError(t, err) + require.NoError(t, err) defer session.Close() + require.NoError(t, session.AwaitSchemaAgreement(ctx)) spans := tracer.EndedSpans() @@ -316,20 +342,22 @@ func TestConnection(t *testing.T) { // Verify the span attributes for _, span := range spans { assert.Equal(t, cassConnectName, span.Name) - assert.NotNil(t, span.Attributes[cassVersionKey].AsString()) - assert.Equal(t, cluster.Hosts[0], span.Attributes[cassHostKey].AsString()) - assert.Equal(t, int32(cluster.Port), span.Attributes[cassPortKey].AsInt32()) - assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) + assert.Equal(t, "db.cassandra.connect", span.Attributes[standard.DBOperationKey].AsString()) + assertConnectionLevelAttributes(t, span) } // Verify the metrics expected := []testRecord{ { - Name: "cassandra.connections", + Name: "db.cassandra.connections", MeterName: "github.com/gocql/gocql", Labels: []kv.KeyValue{ - cassHost("127.0.0.1"), + cassDBSystem(), + cassPeerIP("127.0.0.1"), + cassPeerPort(9042), + cassVersion("3"), cassHostID("test-id"), + cassHostState("UP"), }, }, } @@ -337,7 +365,7 @@ func TestConnection(t *testing.T) { for _, record := range exporter.records { name := record.Descriptor().Name() switch name { - case "cassandra.connections": + case "db.cassandra.connections": recordEqual(t, expected[0], record) default: t.Fatalf("wrong metric %s", name) @@ -345,15 +373,31 @@ func TestConnection(t *testing.T) { } } -func TestGetHost(t *testing.T) { - hostAndPort := "localhost:9042" - assert.Equal(t, "localhost", getHost(hostAndPort)) +func TestHostOrIP(t *testing.T) { + hostAndPort := "127.0.0.1:9042" + attribute := hostOrIP(hostAndPort) + assert.Equal(t, standard.NetPeerIPKey, attribute.Key) + assert.Equal(t, "127.0.0.1", attribute.Value.AsString()) + + hostAndPort = "exampleHost:9042" + attribute = hostOrIP(hostAndPort) + assert.Equal(t, standard.NetPeerNameKey, attribute.Key) + assert.Equal(t, "exampleHost", attribute.Value.AsString()) - hostAndPort = "127.0.0.1:9042" - assert.Equal(t, "127.0.0.1", getHost(hostAndPort)) + hostAndPort = "invalid-host-and-port-string" + attribute = hostOrIP(hostAndPort) + require.Empty(t, attribute.Value.AsString()) +} - hostAndPort = ":9042" - assert.Equal(t, "", getHost(hostAndPort)) +func assertConnectionLevelAttributes(t *testing.T, span *mocktracer.Span) { + assert.Equal(t, span.Attributes[standard.DBSystemKey].AsString(), + standard.DBSystemCassandra.Value.AsString(), + ) + assert.Equal(t, "127.0.0.1", span.Attributes[standard.NetPeerIPKey].AsString()) + assert.Equal(t, int32(9042), span.Attributes[standard.NetPeerPortKey].AsInt32()) + assert.Contains(t, span.Attributes, cassVersionKey) + assert.Contains(t, span.Attributes, cassHostIDKey) + assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) } // getCluster creates a gocql ClusterConfig with the appropriate @@ -379,12 +423,13 @@ func recordEqual(t *testing.T, expected testRecord, actual export.Record) { descriptor := actual.Descriptor() assert.Equal(t, expected.Name, descriptor.Name()) assert.Equal(t, expected.MeterName, descriptor.InstrumentationName()) + require.Len(t, actual.Labels().ToSlice(), len(expected.Labels)) for _, label := range expected.Labels { actualValue, ok := actual.Labels().Value(label.Key) assert.True(t, ok) assert.NotNil(t, actualValue) // Can't test equality of host id - if label.Key != cassHostIDKey { + if label.Key != cassHostIDKey && label.Key != cassVersionKey { assert.Equal(t, label.Value, actualValue) } else { assert.NotEmpty(t, actualValue) @@ -442,6 +487,7 @@ func beforeAll() { } cluster.Keyspace = keyspace + cluster.Timeout = time.Second * 2 session, err = cluster.CreateSession() if err != nil { log.Fatal(err) @@ -460,6 +506,7 @@ func afterEach() { cluster := gocql.NewCluster("localhost") cluster.Consistency = gocql.LocalQuorum cluster.Keyspace = keyspace + cluster.Timeout = time.Second * 2 session, err := cluster.CreateSession() if err != nil { log.Fatalf("failed to connect to database during afterEach, %v", err) diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index 21820af2504..40205a86d52 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -27,28 +27,16 @@ var ( // iQueryCount is the number of queries executed. iQueryCount metric.Int64Counter - // iQueryErrors is the number of errors encountered when - // executing queries. - iQueryErrors metric.Int64Counter - // iQueryRows is the number of rows returned by a query. iQueryRows metric.Int64ValueRecorder // iBatchCount is the number of batch queries executed. iBatchCount metric.Int64Counter - // iBatchErrors is the number of errors encountered when - // executing batch queries. - iBatchErrors metric.Int64Counter - // iConnectionCount is the number of connections made // with the traced session. iConnectionCount metric.Int64Counter - // iConnectErrors is the number of errors encountered - // when making connections with the current traced session. - iConnectErrors metric.Int64Counter - // iLatency is the sum of attempt latencies. iLatency metric.Int64ValueRecorder ) @@ -56,53 +44,44 @@ var ( // InstrumentWithProvider will recreate instruments using a meter // from the given provider p. func InstrumentWithProvider(p metric.Provider) { - defer func() { - if recovered := recover(); recovered != nil { - log.Print("failed to create meter. metrics are not being recorded") - } - }() - meter := metric.Must(p.Meter("github.com/gocql/gocql")) - - iQueryCount = meter.NewInt64Counter( - "cassandra.queries", - metric.WithDescription("Number of queries executed"), - ) - - iQueryErrors = meter.NewInt64Counter( - "cassandra.query.errors", - metric.WithDescription("Number of errors encountered when executing queries"), - ) - - iQueryRows = meter.NewInt64ValueRecorder( - "cassandra.rows", + meter := p.Meter("github.com/gocql/gocql") + var err error + + if iQueryCount, err = meter.NewInt64Counter( + "db.cassandra.queries", + metric.WithDescription("Number queries executed"), + ); err != nil { + log.Printf("failed to create iQueryCount instrument, %v", err) + } + + if iQueryRows, err = meter.NewInt64ValueRecorder( + "db.cassandra.rows", metric.WithDescription("Number of rows returned from query"), - ) + ); err != nil { + log.Printf("failed to create iQueryRows instrument, %v", err) + } - iBatchCount = meter.NewInt64Counter( - "cassandra.batch.queries", + if iBatchCount, err = meter.NewInt64Counter( + "db.cassandra.batch.queries", metric.WithDescription("Number of batch queries executed"), - ) + ); err != nil { + log.Printf("failed to create iBatchCount instrument, %v", err) + } - iBatchErrors = meter.NewInt64Counter( - "cassandra.batch.errors", - metric.WithDescription("Number of errors encountered when executing batch queries"), - ) - - iConnectionCount = meter.NewInt64Counter( - "cassandra.connections", + if iConnectionCount, err = meter.NewInt64Counter( + "db.cassandra.connections", metric.WithDescription("Number of connections created"), - ) - - iConnectErrors = meter.NewInt64Counter( - "cassandra.connect.errors", - metric.WithDescription("Number of errors encountered when creating connections"), - ) + ); err != nil { + log.Printf("failed to create iConnectionCount instrument, %v", err) + } - iLatency = meter.NewInt64ValueRecorder( - "cassandra.latency", + if iLatency, err = meter.NewInt64ValueRecorder( + "db.cassandra.latency", metric.WithDescription("Sum of latency to host in milliseconds"), metric.WithUnit(unit.Milliseconds), - ) + ); err != nil { + log.Printf("failed to create iLatency instrument, %v", err) + } } func init() { diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 050f4a59fc2..d12d4baba44 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -16,13 +16,13 @@ package gocql import ( "context" - "strings" + "log" + "net" "time" "github.com/gocql/gocql" "go.opentelemetry.io/otel/api/kv" - "go.opentelemetry.io/otel/api/metric" "go.opentelemetry.io/otel/api/trace" ) @@ -86,47 +86,52 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq host := observedQuery.Host keyspace := observedQuery.Keyspace - attributes := append( - defaultAttributes(host), + attributes := includeKeyValues(host, + cassKeyspace(keyspace), cassStatement(observedQuery.Statement), cassRowsReturned(observedQuery.Rows), cassQueryAttempts(observedQuery.Metrics.Attempts), - cassQueryAttemptNum(observedQuery.Attempt), - cassKeyspace(keyspace), ) ctx, span := o.cfg.Tracer.Start( ctx, - cassQueryName, + observedQuery.Statement, trace.WithStartTime(observedQuery.Start), trace.WithAttributes(attributes...), ) if observedQuery.Err != nil { span.SetAttributes(cassErrMsg(observedQuery.Err.Error())) - recordError(ctx, iQueryErrors, keyspace, host) + iQueryCount.Add( + ctx, + 1, + includeKeyValues(host, + cassKeyspace(keyspace), + cassErrMsg(observedQuery.Err.Error()), + )..., + ) + } else { + iQueryCount.Add( + ctx, + 1, + includeKeyValues(host, + cassKeyspace(keyspace), + cassStatement(observedQuery.Statement), + )..., + ) } span.End(trace.WithEndTime(observedQuery.End)) - queryLabels := append( - defaultMetricLabels(keyspace, host), - cassStatement(observedQuery.Statement), - ) - iQueryCount.Add( - ctx, - 1, - queryLabels..., - ) iQueryRows.Record( ctx, int64(observedQuery.Rows), - defaultMetricLabels(keyspace, host)..., + includeKeyValues(host, cassKeyspace(keyspace))..., ) iLatency.Record( ctx, nanoToMilliseconds(observedQuery.Metrics.TotalLatency), - defaultMetricLabels(keyspace, host)..., + includeKeyValues(host, cassKeyspace(keyspace))..., ) } @@ -140,10 +145,11 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq if o.cfg.InstrumentBatch { host := observedBatch.Host keyspace := observedBatch.Keyspace - attributes := append( - defaultAttributes(host), - cassBatchQueries(len(observedBatch.Statements)), + + attributes := includeKeyValues(host, cassKeyspace(keyspace), + cassBatchQueryOperation(), + cassBatchQueries(len(observedBatch.Statements)), ) ctx, span := o.cfg.Tracer.Start( @@ -155,20 +161,28 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq if observedBatch.Err != nil { span.SetAttributes(cassErrMsg(observedBatch.Err.Error())) - recordError(ctx, iBatchErrors, keyspace, host) + iBatchCount.Add( + ctx, + 1, + includeKeyValues(host, + cassKeyspace(keyspace), + cassErrMsg(observedBatch.Err.Error()), + )..., + ) + } else { + iBatchCount.Add( + ctx, + 1, + includeKeyValues(host, cassKeyspace(keyspace))..., + ) } span.End(trace.WithEndTime(observedBatch.End)) - iBatchCount.Add( - ctx, - 1, - defaultMetricLabels(observedBatch.Keyspace, observedBatch.Host)..., - ) iLatency.Record( ctx, nanoToMilliseconds(observedBatch.Metrics.TotalLatency), - defaultMetricLabels(keyspace, host)..., + includeKeyValues(host, cassKeyspace(keyspace))..., ) } @@ -181,8 +195,8 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { if o.cfg.InstrumentConnect { host := observedConnect.Host - hostname := getHost(host.HostnameAndPort()) - attributes := defaultAttributes(observedConnect.Host) + + attributes := includeKeyValues(host, cassConnectOperation()) _, span := o.cfg.Tracer.Start( o.ctx, @@ -193,22 +207,20 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne if observedConnect.Err != nil { span.SetAttributes(cassErrMsg(observedConnect.Err.Error())) - iConnectErrors.Add( + iConnectionCount.Add( + o.ctx, + 1, + includeKeyValues(host, cassErrMsg(observedConnect.Err.Error()))..., + ) + } else { + iConnectionCount.Add( o.ctx, 1, - cassHost(hostname), - cassHostID(host.HostID()), + includeKeyValues(host)..., ) } span.End(trace.WithEndTime(observedConnect.End)) - - iConnectionCount.Add( - o.ctx, - 1, - cassHost(hostname), - cassHostID(host.HostID()), - ) } if o.observer != nil { @@ -218,46 +230,39 @@ func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne // ------------------------------------------ Private Functions -// getHost returns the hostname as a string. -// gocql.HostInfo.HostnameAndPort() returns a string -// formatted like host:port. This function returns the host. -func getHost(hostPort string) string { - idx := strings.Index(hostPort, ":") - host := hostPort[0:idx] - return host -} - -// defaultAttributes creates an array of KeyValue pairs that are -// attributes for all gocql spans. -func defaultAttributes(host *gocql.HostInfo) []kv.KeyValue { - hostnameAndPort := host.HostnameAndPort() - return []kv.KeyValue{ +// includeKeyValues is a convenience function for adding multiple attributes/labels to a +// span or instrument. By default, this function includes connection-level attributes, +// (as per the semantic conventions) which have been made standard for all spans and metrics +// generated by this instrumentation integration. +func includeKeyValues(host *gocql.HostInfo, values ...kv.KeyValue) []kv.KeyValue { + connectionLevelAttributes := []kv.KeyValue{ + cassDBSystem(), + hostOrIP(host.HostnameAndPort()), + cassPeerPort(host.Port()), cassVersion(host.Version().String()), - cassHost(getHost(hostnameAndPort)), - cassPort(host.Port()), - cassHostState(host.State().String()), cassHostID(host.HostID()), + cassHostState(host.State().String()), } + return append(connectionLevelAttributes, values...) } -// defaultMetricLabels returns an array of the default labels added to metrics. -func defaultMetricLabels(keyspace string, host *gocql.HostInfo) []kv.KeyValue { - return []kv.KeyValue{ - cassHostID(host.HostID()), - cassKeyspace(keyspace), +// hostOrIP returns a KeyValue pair for the hostname +// retrieved from gocql.HostInfo.HostnameAndPort(). If the hostname +// is returned as a resolved IP address (as is the case for localhost), +// then the KeyValue will have the key net.peer.ip. +// If the hostname is the proper DNS name, then the key will be net.peer.name. +func hostOrIP(hostnameAndPort string) kv.KeyValue { + hostname, _, err := net.SplitHostPort(hostnameAndPort) + if err != nil { + log.Printf("failed to parse hostname from port, %v", err) } + if parse := net.ParseIP(hostname); parse != nil { + return cassPeerIP(parse.String()) + } + return cassPeerName(hostname) } // nanoToMilliseconds converts nanoseconds to milliseconds. func nanoToMilliseconds(ns int64) int64 { return ns / int64(time.Millisecond) } - -func recordError(ctx context.Context, counter metric.Int64Counter, keyspace string, host *gocql.HostInfo) { - labels := append(defaultMetricLabels(keyspace, host), cassHostState(host.State().String())) - counter.Add( - ctx, - 1, - labels..., - ) -} From b3da6e07824b9ee73e925fe1bb7a61684ed51520 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Fri, 24 Jul 2020 23:02:28 +0000 Subject: [PATCH 21/24] Addressed PR feedback by removing constructor functions that take a config struct --- .../github.com/gocql/gocql/README.md | 12 --- .../github.com/gocql/gocql/config.go | 85 +++++++++---------- .../github.com/gocql/gocql/example/go.mod | 1 - .../github.com/gocql/gocql/gocql.go | 22 +++-- .../github.com/gocql/gocql/observer.go | 72 +++++----------- 5 files changed, 81 insertions(+), 111 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index 36fc34026fe..753ca7fddd7 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -31,18 +31,6 @@ func main() { } ``` -In addition to using the convenience function, you can also manually set observers: - -```go -host := "localhost" -cluster := gocql.NewCluster(host) -cluster.QueryObserver = otelGocql.NewQueryObserver(nil, &OtelConfig{ - Tracer: global.Tracer("github.com/gocql/gocql"), - InstrumentQuery: true, -}) -session, err := cluster.CreateSession() -``` - You can customize instrumentation by passing any of the following options to `NewSessionWithTracing`: | Function | Description | diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index 039c03a67b0..b546856d15b 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -24,23 +24,30 @@ import ( // TracedSessionConfig provides configuration for sessions // created with NewSessionWithTracing. type TracedSessionConfig struct { - otelConfig *OtelConfig - queryObserver gocql.QueryObserver - batchObserver gocql.BatchObserver - connectObserver gocql.ConnectObserver + tracer trace.Tracer + instrumentQuery bool + instrumentBatch bool + instrumentConnect bool + queryObserver gocql.QueryObserver + batchObserver gocql.BatchObserver + connectObserver gocql.ConnectObserver } -// OtelConfig provides OpenTelemetry configuration. -type OtelConfig struct { - Tracer trace.Tracer - InstrumentQuery bool - InstrumentBatch bool - InstrumentConnect bool +// TracedSessionOption applies a configuration option to +// the given TracedSessionConfig. +type TracedSessionOption interface { + Apply(*TracedSessionConfig) } -// TracedSessionOption is a function type that applies +// TracedSessionOptionFunc is a function type that applies // a particular configuration to the traced session in question. -type TracedSessionOption func(*TracedSessionConfig) +type TracedSessionOptionFunc func(*TracedSessionConfig) + +// Apply will apply the TracedSessionOptionFunc to c, the given +// TracedSessionConfig. +func (o TracedSessionOptionFunc) Apply(c *TracedSessionConfig) { + o(c) +} // ------------------------------------------ TracedSessionOptions @@ -48,83 +55,75 @@ type TracedSessionOption func(*TracedSessionConfig) // there is an existing QueryObserver that you would like called. It will be called after the // OpenTelemetry implementation, if it is not nil. Defaults to nil. func WithQueryObserver(observer gocql.QueryObserver) TracedSessionOption { - return func(cfg *TracedSessionConfig) { + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { cfg.queryObserver = observer - } + }) } // WithBatchObserver sets an additional BatchObserver to the session configuration. Use this if // there is an existing BatchObserver that you would like called. It will be called after the // OpenTelemetry implementation, if it is not nil. Defaults to nil. func WithBatchObserver(observer gocql.BatchObserver) TracedSessionOption { - return func(cfg *TracedSessionConfig) { + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { cfg.batchObserver = observer - } + }) } // WithConnectObserver sets an additional ConnectObserver to the session configuration. Use this if // there is an existing ConnectObserver that you would like called. It will be called after the // OpenTelemetry implementation, if it is not nil. Defaults to nil. func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { - return func(cfg *TracedSessionConfig) { + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { cfg.connectObserver = observer - } + }) } -// ------------------------------------------ Otel Options - // WithTracer will set tracer to be the tracer used to create spans // for query, batch query, and connection instrumentation. // Defaults to global.Tracer("github.com/gocql/gocql"). func WithTracer(tracer trace.Tracer) TracedSessionOption { - return func(c *TracedSessionConfig) { - c.otelConfig.Tracer = tracer - } + return TracedSessionOptionFunc(func(c *TracedSessionConfig) { + c.tracer = tracer + }) } // WithQueryInstrumentation will enable and disable instrumentation of // queries. Defaults to enabled. func WithQueryInstrumentation(enabled bool) TracedSessionOption { - return func(cfg *TracedSessionConfig) { - cfg.otelConfig.InstrumentQuery = enabled - } + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { + cfg.instrumentQuery = enabled + }) } // WithBatchInstrumentation will enable and disable insturmentation of // batch queries. Defaults to enabled. func WithBatchInstrumentation(enabled bool) TracedSessionOption { - return func(cfg *TracedSessionConfig) { - cfg.otelConfig.InstrumentBatch = enabled - } + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { + cfg.instrumentBatch = enabled + }) } // WithConnectInstrumentation will enable and disable instrumentation of // connection attempts. Defaults to enabled. func WithConnectInstrumentation(enabled bool) TracedSessionOption { - return func(cfg *TracedSessionConfig) { - cfg.otelConfig.InstrumentConnect = enabled - } + return TracedSessionOptionFunc(func(cfg *TracedSessionConfig) { + cfg.instrumentConnect = enabled + }) } // ------------------------------------------ Private Functions func configure(options ...TracedSessionOption) *TracedSessionConfig { config := &TracedSessionConfig{ - otelConfig: otelConfiguration(), + tracer: global.Tracer("github.com/gocql/gocql"), + instrumentQuery: true, + instrumentBatch: true, + instrumentConnect: true, } for _, apply := range options { - apply(config) + apply.Apply(config) } return config } - -func otelConfiguration() *OtelConfig { - return &OtelConfig{ - Tracer: global.Tracer("github.com/gocql/gocql"), - InstrumentQuery: true, - InstrumentBatch: true, - InstrumentConnect: true, - } -} diff --git a/instrumentation/github.com/gocql/gocql/example/go.mod b/instrumentation/github.com/gocql/gocql/example/go.mod index c0351d7469a..3e092b71f45 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.mod +++ b/instrumentation/github.com/gocql/gocql/example/go.mod @@ -13,5 +13,4 @@ require ( google.golang.org/protobuf v1.25.0 // indirect ) -// TODO: remove replace go.opentelemetry.io/contrib/github.com/gocql/gocql => ../ diff --git a/instrumentation/github.com/gocql/gocql/gocql.go b/instrumentation/github.com/gocql/gocql/gocql.go index 1e8a59ffc5a..1dfa14c08fb 100644 --- a/instrumentation/github.com/gocql/gocql/gocql.go +++ b/instrumentation/github.com/gocql/gocql/gocql.go @@ -25,11 +25,21 @@ import ( // You may use additional observers and disable specific tracing using the provided `TracedSessionOption`s. func NewSessionWithTracing(ctx context.Context, cluster *gocql.ClusterConfig, options ...TracedSessionOption) (*gocql.Session, error) { config := configure(options...) - otelConfig := config.otelConfig - - cluster.QueryObserver = NewQueryObserver(config.queryObserver, otelConfig) - cluster.BatchObserver = NewBatchObserver(config.batchObserver, otelConfig) - cluster.ConnectObserver = NewConnectObserver(ctx, config.connectObserver, otelConfig) - + cluster.QueryObserver = &OTelQueryObserver{ + enabled: config.instrumentQuery, + observer: config.queryObserver, + tracer: config.tracer, + } + cluster.BatchObserver = &OTelBatchObserver{ + enabled: config.instrumentBatch, + observer: config.batchObserver, + tracer: config.tracer, + } + cluster.ConnectObserver = &OTelConnectObserver{ + ctx: ctx, + enabled: config.instrumentConnect, + observer: config.connectObserver, + tracer: config.tracer, + } return cluster.CreateSession() } diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index d12d4baba44..019c993024c 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -26,63 +26,36 @@ import ( "go.opentelemetry.io/otel/api/trace" ) -// OtelQueryObserver implements the gocql.QueryObserver interface +// OTelQueryObserver implements the gocql.QueryObserver interface // to provide instrumentation to gocql queries. -type OtelQueryObserver struct { +type OTelQueryObserver struct { + enabled bool observer gocql.QueryObserver - cfg *OtelConfig + tracer trace.Tracer } -// OtelBatchObserver implements the gocql.BatchObserver interface +// OTelBatchObserver implements the gocql.BatchObserver interface // to provide instrumentation to gocql batch queries. -type OtelBatchObserver struct { +type OTelBatchObserver struct { + enabled bool observer gocql.BatchObserver - cfg *OtelConfig + tracer trace.Tracer } -// OtelConnectObserver implements the gocql.ConnectObserver interface +// OTelConnectObserver implements the gocql.ConnectObserver interface // to provide instrumentation to connection attempts made by the session. -type OtelConnectObserver struct { - observer gocql.ConnectObserver - cfg *OtelConfig +type OTelConnectObserver struct { ctx context.Context -} - -// ----------------------------------------- Constructor Functions - -// NewQueryObserver creates a QueryObserver that provides OpenTelemetry -// instrumentation for queries. -func NewQueryObserver(observer gocql.QueryObserver, cfg *OtelConfig) gocql.QueryObserver { - return &OtelQueryObserver{ - observer, - cfg, - } -} - -// NewBatchObserver creates a BatchObserver that provides OpenTelemetry instrumentation for -// batch queries. -func NewBatchObserver(observer gocql.BatchObserver, cfg *OtelConfig) gocql.BatchObserver { - return &OtelBatchObserver{ - observer, - cfg, - } -} - -// NewConnectObserver creates a ConnectObserver that provides OpenTelemetry instrumentation for -// connection attempts. -func NewConnectObserver(ctx context.Context, observer gocql.ConnectObserver, cfg *OtelConfig) gocql.ConnectObserver { - return &OtelConnectObserver{ - observer, - cfg, - ctx, - } + enabled bool + observer gocql.ConnectObserver + tracer trace.Tracer } // ------------------------------------------ Observer Functions // ObserveQuery is called once per query, and provides instrumentation for it. -func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { - if o.cfg.InstrumentQuery { +func (o *OTelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocql.ObservedQuery) { + if o.enabled { host := observedQuery.Host keyspace := observedQuery.Keyspace @@ -93,7 +66,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq cassQueryAttempts(observedQuery.Metrics.Attempts), ) - ctx, span := o.cfg.Tracer.Start( + ctx, span := o.tracer.Start( ctx, observedQuery.Statement, trace.WithStartTime(observedQuery.Start), @@ -107,6 +80,7 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq 1, includeKeyValues(host, cassKeyspace(keyspace), + cassStatement(observedQuery.Statement), cassErrMsg(observedQuery.Err.Error()), )..., ) @@ -141,8 +115,8 @@ func (o *OtelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq } // ObserveBatch is called once per batch query, and provides instrumentation for it. -func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { - if o.cfg.InstrumentBatch { +func (o *OTelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocql.ObservedBatch) { + if o.enabled { host := observedBatch.Host keyspace := observedBatch.Keyspace @@ -152,7 +126,7 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq cassBatchQueries(len(observedBatch.Statements)), ) - ctx, span := o.cfg.Tracer.Start( + ctx, span := o.tracer.Start( ctx, cassBatchQueryName, trace.WithStartTime(observedBatch.Start), @@ -192,13 +166,13 @@ func (o *OtelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq } // ObserveConnect is called once per connection attempt, and provides instrumentation for it. -func (o *OtelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { - if o.cfg.InstrumentConnect { +func (o *OTelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConnect) { + if o.enabled { host := observedConnect.Host attributes := includeKeyValues(host, cassConnectOperation()) - _, span := o.cfg.Tracer.Start( + _, span := o.tracer.Start( o.ctx, cassConnectName, trace.WithStartTime(observedConnect.Start), From f12726b6c70dfe841c38ab324237872a590b9632 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Wed, 29 Jul 2020 21:21:15 +0000 Subject: [PATCH 22/24] fix: address pr feedback by setting meter name to package name --- instrumentation/github.com/gocql/gocql/README.md | 2 +- instrumentation/github.com/gocql/gocql/config.go | 4 ++-- instrumentation/github.com/gocql/gocql/gocql_test.go | 12 ++++++------ instrumentation/github.com/gocql/gocql/instrument.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index 753ca7fddd7..f713e3b0adf 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -38,7 +38,7 @@ You can customize instrumentation by passing any of the following options to `Ne | `WithQueryObserver(gocql.QueryObserver)` | Specify an additional QueryObserver to be called. | | `WithBatchObserver(gocql.BatchObserver)` | Specify an additional BatchObserver to be called. | | `WithConnectObserver(gocql.ConnectObserver)` | Specify an additional ConnectObserver to be called. | -| `WithTracer(trace.Tracer)` | The tracer to be used to create spans for the gocql session. If not specified, `global.Tracer("github.com/gocql/gocql")` will be used. | +| `WithTracer(trace.Tracer)` | The tracer to be used to create spans for the gocql session. If not specified, `global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql")` will be used. | | `WithQueryInstrumentation(bool)` | To enable/disable tracing and metrics for queries. | | `WithBatchInstrumentation(bool)` | To enable/disable tracing and metrics for batch queries. | | `WithConnectInstrumentation(bool)` | To enable/disable tracing and metrics for new connections. | diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index b546856d15b..0881e78d9c9 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -80,7 +80,7 @@ func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { // WithTracer will set tracer to be the tracer used to create spans // for query, batch query, and connection instrumentation. -// Defaults to global.Tracer("github.com/gocql/gocql"). +// Defaults to global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql"). func WithTracer(tracer trace.Tracer) TracedSessionOption { return TracedSessionOptionFunc(func(c *TracedSessionConfig) { c.tracer = tracer @@ -115,7 +115,7 @@ func WithConnectInstrumentation(enabled bool) TracedSessionOption { func configure(options ...TracedSessionOption) *TracedSessionConfig { config := &TracedSessionConfig{ - tracer: global.Tracer("github.com/gocql/gocql"), + tracer: global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql"), instrumentQuery: true, instrumentBatch: true, instrumentConnect: true, diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 3134f495911..5aa6e240d5d 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -153,7 +153,7 @@ func TestQuery(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.queries", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -168,7 +168,7 @@ func TestQuery(t *testing.T) { }, { Name: "db.cassandra.rows", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -182,7 +182,7 @@ func TestQuery(t *testing.T) { }, { Name: "db.cassandra.latency", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -269,7 +269,7 @@ func TestBatch(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.batch.queries", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -283,7 +283,7 @@ func TestBatch(t *testing.T) { }, { Name: "db.cassandra.latency", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -350,7 +350,7 @@ func TestConnection(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.connections", - MeterName: "github.com/gocql/gocql", + MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index 40205a86d52..e43bfb658db 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -44,7 +44,7 @@ var ( // InstrumentWithProvider will recreate instruments using a meter // from the given provider p. func InstrumentWithProvider(p metric.Provider) { - meter := p.Meter("github.com/gocql/gocql") + meter := p.Meter("go.opentelemetry.io/contrib/github.com/gocql/gocql") var err error if iQueryCount, err = meter.NewInt64Counter( From e61e7500c0b61fff0bd255ab9cf573d7d1b7741d Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Wed, 29 Jul 2020 22:09:24 +0000 Subject: [PATCH 23/24] fix: add spankindclient to spans --- instrumentation/github.com/gocql/gocql/gocql_test.go | 2 ++ instrumentation/github.com/gocql/gocql/observer.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 5aa6e240d5d..1970828094e 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -26,6 +26,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/api/standard" + "go.opentelemetry.io/otel/api/trace" "go.opentelemetry.io/otel/sdk/metric/controller/push" "go.opentelemetry.io/otel/sdk/metric/selector/simple" @@ -398,6 +399,7 @@ func assertConnectionLevelAttributes(t *testing.T, span *mocktracer.Span) { assert.Contains(t, span.Attributes, cassVersionKey) assert.Contains(t, span.Attributes, cassHostIDKey) assert.Equal(t, "up", strings.ToLower(span.Attributes[cassHostStateKey].AsString())) + assert.Equal(t, trace.SpanKindClient, span.Kind) } // getCluster creates a gocql ClusterConfig with the appropriate diff --git a/instrumentation/github.com/gocql/gocql/observer.go b/instrumentation/github.com/gocql/gocql/observer.go index 019c993024c..30693e4bb7c 100644 --- a/instrumentation/github.com/gocql/gocql/observer.go +++ b/instrumentation/github.com/gocql/gocql/observer.go @@ -71,6 +71,7 @@ func (o *OTelQueryObserver) ObserveQuery(ctx context.Context, observedQuery gocq observedQuery.Statement, trace.WithStartTime(observedQuery.Start), trace.WithAttributes(attributes...), + trace.WithSpanKind(trace.SpanKindClient), ) if observedQuery.Err != nil { @@ -131,6 +132,7 @@ func (o *OTelBatchObserver) ObserveBatch(ctx context.Context, observedBatch gocq cassBatchQueryName, trace.WithStartTime(observedBatch.Start), trace.WithAttributes(attributes...), + trace.WithSpanKind(trace.SpanKindClient), ) if observedBatch.Err != nil { @@ -177,6 +179,7 @@ func (o *OTelConnectObserver) ObserveConnect(observedConnect gocql.ObservedConne cassConnectName, trace.WithStartTime(observedConnect.Start), trace.WithAttributes(attributes...), + trace.WithSpanKind(trace.SpanKindClient), ) if observedConnect.Err != nil { From 6a000df4e9221e9d479a404a51134a5fd4360342 Mon Sep 17 00:00:00 2001 From: reggiemcdonald Date: Thu, 30 Jul 2020 00:53:33 +0000 Subject: [PATCH 24/24] fix: address pr feedback by correcting package name --- instrumentation/github.com/gocql/gocql/README.md | 4 ++-- instrumentation/github.com/gocql/gocql/cass.go | 3 +++ instrumentation/github.com/gocql/gocql/config.go | 4 ++-- .../github.com/gocql/gocql/example/client.go | 4 ++-- .../github.com/gocql/gocql/example/go.mod | 6 +++--- instrumentation/github.com/gocql/gocql/go.mod | 2 +- instrumentation/github.com/gocql/gocql/gocql_test.go | 12 ++++++------ instrumentation/github.com/gocql/gocql/instrument.go | 2 +- 8 files changed, 20 insertions(+), 17 deletions(-) diff --git a/instrumentation/github.com/gocql/gocql/README.md b/instrumentation/github.com/gocql/gocql/README.md index f713e3b0adf..1c9ca0b9843 100644 --- a/instrumentation/github.com/gocql/gocql/README.md +++ b/instrumentation/github.com/gocql/gocql/README.md @@ -11,7 +11,7 @@ import ( "context" "github.com/gocql/gocql" - otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" + otelGocql "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" ) func main() { @@ -38,7 +38,7 @@ You can customize instrumentation by passing any of the following options to `Ne | `WithQueryObserver(gocql.QueryObserver)` | Specify an additional QueryObserver to be called. | | `WithBatchObserver(gocql.BatchObserver)` | Specify an additional BatchObserver to be called. | | `WithConnectObserver(gocql.ConnectObserver)` | Specify an additional ConnectObserver to be called. | -| `WithTracer(trace.Tracer)` | The tracer to be used to create spans for the gocql session. If not specified, `global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql")` will be used. | +| `WithTracer(trace.Tracer)` | The tracer to be used to create spans for the gocql session. If not specified, `global.Tracer("go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql")` will be used. | | `WithQueryInstrumentation(bool)` | To enable/disable tracing and metrics for queries. | | `WithBatchInstrumentation(bool)` | To enable/disable tracing and metrics for batch queries. | | `WithConnectInstrumentation(bool)` | To enable/disable tracing and metrics for new connections. | diff --git a/instrumentation/github.com/gocql/gocql/cass.go b/instrumentation/github.com/gocql/gocql/cass.go index 81e94071bf1..d626a23480f 100644 --- a/instrumentation/github.com/gocql/gocql/cass.go +++ b/instrumentation/github.com/gocql/gocql/cass.go @@ -52,6 +52,9 @@ const ( // Static span names cassBatchQueryName = "Batch Query" cassConnectName = "New Connection" + + // instrumentationName is the name of the instrumentation package. + instrumentationName = "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" ) // ------------------------------------------ Connection-level Attributes diff --git a/instrumentation/github.com/gocql/gocql/config.go b/instrumentation/github.com/gocql/gocql/config.go index 0881e78d9c9..c761c9aefe2 100644 --- a/instrumentation/github.com/gocql/gocql/config.go +++ b/instrumentation/github.com/gocql/gocql/config.go @@ -80,7 +80,7 @@ func WithConnectObserver(observer gocql.ConnectObserver) TracedSessionOption { // WithTracer will set tracer to be the tracer used to create spans // for query, batch query, and connection instrumentation. -// Defaults to global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql"). +// Defaults to global.Tracer("go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql"). func WithTracer(tracer trace.Tracer) TracedSessionOption { return TracedSessionOptionFunc(func(c *TracedSessionConfig) { c.tracer = tracer @@ -115,7 +115,7 @@ func WithConnectInstrumentation(enabled bool) TracedSessionOption { func configure(options ...TracedSessionOption) *TracedSessionConfig { config := &TracedSessionConfig{ - tracer: global.Tracer("go.opentelemetry.io/contrib/github.com/gocql/gocql"), + tracer: global.Tracer(instrumentationName), instrumentQuery: true, instrumentBatch: true, instrumentConnect: true, diff --git a/instrumentation/github.com/gocql/gocql/example/client.go b/instrumentation/github.com/gocql/gocql/example/client.go index 7e828c98702..4c89dff68f8 100644 --- a/instrumentation/github.com/gocql/gocql/example/client.go +++ b/instrumentation/github.com/gocql/gocql/example/client.go @@ -38,7 +38,7 @@ import ( "github.com/gocql/gocql" - otelGocql "go.opentelemetry.io/contrib/github.com/gocql/gocql" + otelGocql "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql" "go.opentelemetry.io/otel/api/global" "go.opentelemetry.io/otel/exporters/metric/prometheus" zipkintrace "go.opentelemetry.io/otel/exporters/trace/zipkin" @@ -55,7 +55,7 @@ func main() { initDb() ctx, span := global.Tracer( - "go.opentelemetry.io/contrib/github.com/gocql/gocql/example", + "go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql/example", ).Start(context.Background(), "begin example") cluster := getCluster() diff --git a/instrumentation/github.com/gocql/gocql/example/go.mod b/instrumentation/github.com/gocql/gocql/example/go.mod index 3e092b71f45..4e9858fcd44 100644 --- a/instrumentation/github.com/gocql/gocql/example/go.mod +++ b/instrumentation/github.com/gocql/gocql/example/go.mod @@ -1,11 +1,11 @@ -module go.opentelemetry.io/contrib/github.com/gocql/gocql/example +module go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql/example go 1.14 require ( github.com/DataDog/sketches-go v0.0.1 // indirect github.com/gocql/gocql v0.0.0-20200624222514-34081eda590e - go.opentelemetry.io/contrib/github.com/gocql/gocql v0.0.0 + go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql v0.0.0 go.opentelemetry.io/otel v0.9.0 go.opentelemetry.io/otel/exporters/metric/prometheus v0.9.0 go.opentelemetry.io/otel/exporters/trace/zipkin v0.9.0 @@ -13,4 +13,4 @@ require ( google.golang.org/protobuf v1.25.0 // indirect ) -replace go.opentelemetry.io/contrib/github.com/gocql/gocql => ../ +replace go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql => ../ diff --git a/instrumentation/github.com/gocql/gocql/go.mod b/instrumentation/github.com/gocql/gocql/go.mod index d1bbbb2a9a5..ce71beee7a1 100644 --- a/instrumentation/github.com/gocql/gocql/go.mod +++ b/instrumentation/github.com/gocql/gocql/go.mod @@ -1,4 +1,4 @@ -module go.opentelemetry.io/contrib/github.com/gocql/gocql +module go.opentelemetry.io/contrib/instrumentation/github.com/gocql/gocql go 1.14 diff --git a/instrumentation/github.com/gocql/gocql/gocql_test.go b/instrumentation/github.com/gocql/gocql/gocql_test.go index 1970828094e..5e8d15771db 100644 --- a/instrumentation/github.com/gocql/gocql/gocql_test.go +++ b/instrumentation/github.com/gocql/gocql/gocql_test.go @@ -154,7 +154,7 @@ func TestQuery(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.queries", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -169,7 +169,7 @@ func TestQuery(t *testing.T) { }, { Name: "db.cassandra.rows", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -183,7 +183,7 @@ func TestQuery(t *testing.T) { }, { Name: "db.cassandra.latency", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -270,7 +270,7 @@ func TestBatch(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.batch.queries", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -284,7 +284,7 @@ func TestBatch(t *testing.T) { }, { Name: "db.cassandra.latency", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), @@ -351,7 +351,7 @@ func TestConnection(t *testing.T) { expected := []testRecord{ { Name: "db.cassandra.connections", - MeterName: "go.opentelemetry.io/contrib/github.com/gocql/gocql", + MeterName: instrumentationName, Labels: []kv.KeyValue{ cassDBSystem(), cassPeerIP("127.0.0.1"), diff --git a/instrumentation/github.com/gocql/gocql/instrument.go b/instrumentation/github.com/gocql/gocql/instrument.go index e43bfb658db..bbc13762956 100644 --- a/instrumentation/github.com/gocql/gocql/instrument.go +++ b/instrumentation/github.com/gocql/gocql/instrument.go @@ -44,7 +44,7 @@ var ( // InstrumentWithProvider will recreate instruments using a meter // from the given provider p. func InstrumentWithProvider(p metric.Provider) { - meter := p.Meter("go.opentelemetry.io/contrib/github.com/gocql/gocql") + meter := p.Meter(instrumentationName) var err error if iQueryCount, err = meter.NewInt64Counter(