diff --git a/.jenkins.yml b/.jenkins.yml index 6635c050f..bdc4bfea7 100644 --- a/.jenkins.yml +++ b/.jenkins.yml @@ -1,12 +1,6 @@ GO_VERSION: - stable - "1.x" - - "1.8.x" - - "1.9.x" - - "1.10.x" - - "1.11.x" - - "1.12.x" - - "1.13.x" - - "1.14.x" - "1.15.x" - "1.16.x" + - "1.17.x" diff --git a/Jenkinsfile b/Jenkinsfile index a39e20af0..524316c4e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -113,7 +113,6 @@ pipeline { deleteDir() unstash 'source' dir("${BASE_DIR}"){ - sh script: './scripts/jenkins/before_install.sh', label: 'Install dependencies' sh script: './scripts/jenkins/docker-test.sh', label: 'Docker tests' } } @@ -150,7 +149,6 @@ pipeline { deleteDir() unstash 'source' dir("${BASE_DIR}"){ - sh script: './scripts/jenkins/before_install.sh', label: 'Install dependencies' sh script: './scripts/jenkins/bench.sh', label: 'Benchmarking' sendBenchmarks(file: 'build/bench.out', index: 'benchmark-go') } @@ -200,9 +198,6 @@ pipeline { retry(3) { deleteDir() unstash 'source' - dir("${BASE_DIR}"){ - sh script: './scripts/jenkins/before_install.sh', label: 'Install dependencies' - } } retry(3) { dir("${BASE_DIR}"){ @@ -297,9 +292,6 @@ def generateStep(version){ retry(3) { deleteDir() unstash 'source' - dir("${BASE_DIR}"){ - sh script: './scripts/jenkins/before_install.sh', label: 'Install dependencies' - } } retry(3) { dir("${BASE_DIR}"){ diff --git a/Makefile b/Makefile index e388088b1..9fb58f03b 100644 --- a/Makefile +++ b/Makefile @@ -8,37 +8,28 @@ check: precheck check-modules test precheck: check-goimports check-lint check-vanity-import check-vet check-dockerfile-testing check-licenses model/marshal_fastjson.go scripts/Dockerfile-testing .PHONY: check-goimports -.PHONY: check-dockerfile-testing -.PHONY: check-lint -.PHONY: check-licenses -.PHONY: check-modules -.PHONY: check-vanity-import -ifeq ($(shell go run ./scripts/mingoversion.go -print 1.12),true) check-goimports: sh scripts/check_goimports.sh +.PHONY: check-dockerfile-testing check-dockerfile-testing: go run ./scripts/gendockerfile.go -d +.PHONY: check-lint check-lint: sh scripts/check_lint.sh +.PHONY: check-licenses check-licenses: go run github.com/elastic/go-licenser -d $(patsubst %,-exclude %,$(GO_LICENSER_EXCLUDE)) . +.PHONY: check-modules check-modules: go run scripts/genmod/main.go -check . +.PHONY: check-vanity-import check-vanity-import: sh scripts/check_vanity.sh -else -check-goimports: -check-dockerfile-testing: -check-lint: -check-licenses: -check-modules: -check-vanity-import: -endif .PHONY: check-vet check-vet: diff --git a/README.md b/README.md index 010dc1652..fa20944ad 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ go get -u go.elastic.co/apm ## Requirements -Tested with Go 1.8+ on Linux, Windows and MacOS. +Tested with Go 1.15+ on Linux, Windows and MacOS. Requires [APM Server](https://github.com/elastic/apm-server) v6.5 or newer. diff --git a/apmtest/debug.go b/apmtest/debug.go index 00cc5d255..d133475c0 100644 --- a/apmtest/debug.go +++ b/apmtest/debug.go @@ -21,12 +21,12 @@ import ( "bytes" "fmt" "io" + "math" "sort" "text/tabwriter" "time" "unicode/utf8" - "go.elastic.co/apm/internal/apmmath" "go.elastic.co/apm/model" ) @@ -81,13 +81,13 @@ func WriteTraceWaterfall(w io.Writer, tx model.Transaction, spans []model.Span) }) for _, span := range spans { - pos := int(apmmath.Round( + pos := int(math.Round( float64(time.Time(span.Timestamp).Sub(time.Time(tx.Timestamp))) / float64(maxDuration) * float64(maxWidth), )) tDur := time.Duration(span.Duration * float64(time.Millisecond)) dur := float64(tDur) / float64(maxDuration) - width := int(apmmath.Round(dur * float64(maxWidth))) + width := int(math.Round(dur * float64(maxWidth))) if width == int(maxWidth) { width = int(maxWidth) - 1 } diff --git a/breakdown_internal_test.go b/breakdown_internal_test.go index 9181d9d0b..20f244e85 100644 --- a/breakdown_internal_test.go +++ b/breakdown_internal_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apm import ( diff --git a/error_go113_test.go b/error_go113_test.go deleted file mode 100644 index 7654da63e..000000000 --- a/error_go113_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.13 -// +build go1.13 - -package apm_test - -import ( - "fmt" - "testing" - - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "go.elastic.co/apm/transport/transporttest" -) - -func TestErrorCauseUnwrap(t *testing.T) { - err := fmt.Errorf("%w", errors.New("cause")) - - tracer, recorder := transporttest.NewRecorderTracer() - defer tracer.Close() - tracer.NewError(err).Send() - tracer.Flush(nil) - - payloads := recorder.Payloads() - require.Len(t, payloads.Errors, 1) - assert.Equal(t, "TestErrorCauseUnwrap", payloads.Errors[0].Culprit) - - require.Len(t, payloads.Errors[0].Exception.Cause, 1) - assert.Equal(t, "cause", payloads.Errors[0].Exception.Cause[0].Message) -} diff --git a/error_test.go b/error_test.go index 421f20948..5ff5c3ab6 100644 --- a/error_test.go +++ b/error_test.go @@ -555,6 +555,22 @@ func TestErrorCauseCycle(t *testing.T) { assert.Equal(t, "errorslice", payloads.Errors[0].Exception.Cause[0].Cause[0].Message) } +func TestErrorCauseUnwrap(t *testing.T) { + err := fmt.Errorf("%w", errors.New("cause")) + + tracer, recorder := transporttest.NewRecorderTracer() + defer tracer.Close() + tracer.NewError(err).Send() + tracer.Flush(nil) + + payloads := recorder.Payloads() + require.Len(t, payloads.Errors, 1) + assert.Equal(t, "TestErrorCauseUnwrap", payloads.Errors[0].Culprit) + + require.Len(t, payloads.Errors[0].Exception.Cause, 1) + assert.Equal(t, "cause", payloads.Errors[0].Exception.Cause[0].Message) +} + func assertErrorTransactionSampled(t *testing.T, e model.Error, sampled bool) { assert.Equal(t, &sampled, e.Transaction.Sampled) if sampled { diff --git a/internal/apmgodog/suitecontext_test.go b/internal/apmgodog/suitecontext_test.go index 82a557ffe..b6c58b2fe 100644 --- a/internal/apmgodog/suitecontext_test.go +++ b/internal/apmgodog/suitecontext_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmgodog_test import ( diff --git a/internal/apmgodog/testmain_test.go b/internal/apmgodog/testmain_test.go index c53263d9c..b646bcd78 100644 --- a/internal/apmgodog/testmain_test.go +++ b/internal/apmgodog/testmain_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmgodog_test import ( diff --git a/internal/apmmath/round_go10.go b/internal/apmmath/round_go10.go deleted file mode 100644 index 9cacc1803..000000000 --- a/internal/apmmath/round_go10.go +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmmath - -import "math" - -// Round is the current math.Round implementation for >= Go1.10. -func Round(x float64) float64 { - return math.Round(x) -} diff --git a/internal/apmmath/round_go9.go b/internal/apmmath/round_go9.go deleted file mode 100644 index 111317d7f..000000000 --- a/internal/apmmath/round_go9.go +++ /dev/null @@ -1,34 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmmath - -import "math" - -// Round Implementation of math.Round for Go < 1.10. -// -// Code shamelessly copied from pkg/math. -func Round(x float64) float64 { - t := math.Trunc(x) - if math.Abs(x-t) >= 0.5 { - return t + math.Copysign(1, x) - } - return t -} diff --git a/internal/apmstrings/concat10.go b/internal/apmstrings/concat10.go deleted file mode 100644 index 8f6105402..000000000 --- a/internal/apmstrings/concat10.go +++ /dev/null @@ -1,38 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmstrings - -import "strings" - -// Concat concatenates all the string arguments efficiently. -func Concat(elements ...string) string { - var builder strings.Builder - var length int - for i := range elements { - length += len(elements[i]) - } - builder.Grow(length) - - for i := range elements { - builder.WriteString(elements[i]) - } - return builder.String() -} diff --git a/internal/apmstrings/concat10_test.go b/internal/apmstrings/concat10_test.go deleted file mode 100644 index ebb719830..000000000 --- a/internal/apmstrings/concat10_test.go +++ /dev/null @@ -1,60 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmstrings - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestConcat(t *testing.T) { - type args struct { - elements []string - } - tests := []struct { - expect string - elements []string - }{ - {elements: []string{"a", "b", "c"}, expect: "abc"}, - {elements: []string{"Calls to ", "redis"}, expect: "Calls to redis"}, - } - for i, test := range tests { - t.Run(fmt.Sprint(i), func(t *testing.T) { - assert.Equal(t, test.expect, Concat(test.elements...), i) - }) - } -} - -var benchRes string - -func BenchmarkConcat(b *testing.B) { - elements := map[bool][]string{ - true: {"Calls to ", "redis"}, - false: {"Calls to ", "verylongservicenamewegothere"}, - } - b.ResetTimer() - b.ReportAllocs() - for i := 0; i < b.N; i++ { - benchRes = Concat(elements[i%2 == 0]...) - } -} diff --git a/internal/apmstrings/concat9.go b/internal/apmstrings/concat9.go deleted file mode 100644 index 74f288657..000000000 --- a/internal/apmstrings/concat9.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmstrings - -import ( - "bytes" -) - -// Concat concatenates all the string arguments efficiently. -func Concat(elements ...string) string { - var buf bytes.Buffer - var length int - for i := range elements { - length += len(elements[i]) - } - buf.Grow(length) - - for i := range elements { - buf.WriteString(elements[i]) - } - return buf.String() - -} diff --git a/model/marshal_fastjson.go b/model/marshal_fastjson.go index d646f6a97..6b763d309 100644 --- a/model/marshal_fastjson.go +++ b/model/marshal_fastjson.go @@ -1094,35 +1094,35 @@ func (v *Error) MarshalFastJSON(w *fastjson.Writer) error { func (v *ErrorTransaction) MarshalFastJSON(w *fastjson.Writer) error { w.RawByte('{') first := true - if v.Sampled != nil { - const prefix = ",\"sampled\":" + if v.Name != "" { + const prefix = ",\"name\":" if first { first = false w.RawString(prefix[1:]) } else { w.RawString(prefix) } - w.Bool(*v.Sampled) + w.String(v.Name) } - if v.Type != "" { - const prefix = ",\"type\":" + if v.Sampled != nil { + const prefix = ",\"sampled\":" if first { first = false w.RawString(prefix[1:]) } else { w.RawString(prefix) } - w.String(v.Type) + w.Bool(*v.Sampled) } - if v.Name != "" { - const prefix = ",\"name\":" + if v.Type != "" { + const prefix = ",\"type\":" if first { first = false w.RawString(prefix[1:]) } else { w.RawString(prefix) } - w.String(v.Name) + w.String(v.Type) } w.RawByte('}') return nil diff --git a/module/apmawssdkgo/session_test.go b/module/apmawssdkgo/session_test.go index cc0cdbb07..f46d935c0 100644 --- a/module/apmawssdkgo/session_test.go +++ b/module/apmawssdkgo/session_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmawssdkgo // import "go.elastic.co/apm/module/apmawssdkgo" import ( diff --git a/module/apmawssdkgo/sns_test.go b/module/apmawssdkgo/sns_test.go index 4b2189095..e834f4ea4 100644 --- a/module/apmawssdkgo/sns_test.go +++ b/module/apmawssdkgo/sns_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmawssdkgo // import "go.elastic.co/apm/module/apmawssdkgo" import ( diff --git a/module/apmawssdkgo/sqs_test.go b/module/apmawssdkgo/sqs_test.go index f346fd3ef..e66778b68 100644 --- a/module/apmawssdkgo/sqs_test.go +++ b/module/apmawssdkgo/sqs_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmawssdkgo // import "go.elastic.co/apm/module/apmawssdkgo" import ( diff --git a/module/apmazure/blob.go b/module/apmazure/blob.go index 53f420380..633a9c29a 100644 --- a/module/apmazure/blob.go +++ b/module/apmazure/blob.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure // import "go.elastic.co/apm/module/apmazure" import ( diff --git a/module/apmazure/blob_test.go b/module/apmazure/blob_test.go index 379103a54..243465a2d 100644 --- a/module/apmazure/blob_test.go +++ b/module/apmazure/blob_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure import ( diff --git a/module/apmazure/file.go b/module/apmazure/file.go index 7bf7cf001..16a38efd1 100644 --- a/module/apmazure/file.go +++ b/module/apmazure/file.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure // import "go.elastic.co/apm/module/apmazure" import ( diff --git a/module/apmazure/file_test.go b/module/apmazure/file_test.go index 692ecbc7c..7b187d6c8 100644 --- a/module/apmazure/file_test.go +++ b/module/apmazure/file_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure import ( diff --git a/module/apmazure/queue.go b/module/apmazure/queue.go index 111731906..b9ab93e2c 100644 --- a/module/apmazure/queue.go +++ b/module/apmazure/queue.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure // import "go.elastic.co/apm/module/apmazure" import ( diff --git a/module/apmazure/queue_test.go b/module/apmazure/queue_test.go index 281105450..27c0f7530 100644 --- a/module/apmazure/queue_test.go +++ b/module/apmazure/queue_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure // import "go.elastic.co/apm/module/apmazure" import ( diff --git a/module/apmazure/storage.go b/module/apmazure/storage.go index 4cd7b8f63..af1ea97cf 100644 --- a/module/apmazure/storage.go +++ b/module/apmazure/storage.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmazure // import "go.elastic.co/apm/module/apmazure" import ( diff --git a/module/apmchiv5/middleware.go b/module/apmchiv5/middleware.go index 9924f2b6e..5b9357c1f 100644 --- a/module/apmchiv5/middleware.go +++ b/module/apmchiv5/middleware.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmchiv5 // import "go.elastic.co/apm/module/apmchiv5" import ( diff --git a/module/apmchiv5/middleware_test.go b/module/apmchiv5/middleware_test.go index 6d126cf39..3f8d7f7ad 100644 --- a/module/apmchiv5/middleware_test.go +++ b/module/apmchiv5/middleware_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmchiv5_test import ( diff --git a/module/apmechov4/doc.go b/module/apmechov4/doc.go index dbc79fc1f..5ecfdb689 100644 --- a/module/apmechov4/doc.go +++ b/module/apmechov4/doc.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - // Package apmechov4 provides middleware for the version 4 of Echo framework, // for tracing HTTP requests. package apmechov4 // import "go.elastic.co/apm/module/apmechov4" diff --git a/module/apmechov4/example_test.go b/module/apmechov4/example_test.go index f56dd3ead..9ab511be0 100644 --- a/module/apmechov4/example_test.go +++ b/module/apmechov4/example_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmechov4_test import ( diff --git a/module/apmechov4/middleware.go b/module/apmechov4/middleware.go index 6fc74ac1b..cf9a11422 100644 --- a/module/apmechov4/middleware.go +++ b/module/apmechov4/middleware.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmechov4 // import "go.elastic.co/apm/module/apmechov4" import ( diff --git a/module/apmechov4/middleware_test.go b/module/apmechov4/middleware_test.go index 92633d79b..276a086c6 100644 --- a/module/apmechov4/middleware_test.go +++ b/module/apmechov4/middleware_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmechov4_test import ( diff --git a/module/apmelasticsearch/internal/integration/doc.go b/module/apmelasticsearch/internal/integration/doc.go index d9d8af496..e48ab53a2 100644 --- a/module/apmelasticsearch/internal/integration/doc.go +++ b/module/apmelasticsearch/internal/integration/doc.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - // Package integration holds integration tests for apmelasticsearch. // // This exists as a separate module to avoid adding unnecessary diff --git a/module/apmelasticsearch/internal/integration/elastic_integration_test.go b/module/apmelasticsearch/internal/integration/elastic_integration_test.go index 36925155b..0b179f865 100644 --- a/module/apmelasticsearch/internal/integration/elastic_integration_test.go +++ b/module/apmelasticsearch/internal/integration/elastic_integration_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package integration_test import ( diff --git a/module/apmelasticsearch/internal/integration/olivere_integration_test.go b/module/apmelasticsearch/internal/integration/olivere_integration_test.go index 9c1cf92a8..83ea4569b 100644 --- a/module/apmelasticsearch/internal/integration/olivere_integration_test.go +++ b/module/apmelasticsearch/internal/integration/olivere_integration_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package integration_test import ( diff --git a/module/apmelasticsearch/requestname.go b/module/apmelasticsearch/requestname.go index dcb6da446..27dd297db 100644 --- a/module/apmelasticsearch/requestname.go +++ b/module/apmelasticsearch/requestname.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmelasticsearch // import "go.elastic.co/apm/module/apmelasticsearch" import ( diff --git a/module/apmelasticsearch/requestname_go19.go b/module/apmelasticsearch/requestname_go19.go deleted file mode 100644 index 8b20cdd8e..000000000 --- a/module/apmelasticsearch/requestname_go19.go +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmelasticsearch // import "go.elastic.co/apm/module/apmelasticsearch" - -import ( - "fmt" - "net/http" - "strings" -) - -func requestName(req *http.Request) string { - return fmt.Sprintf("Elasticsearch: %s %s", req.Method, strings.TrimLeft(req.URL.Path, "/")) -} diff --git a/module/apmfasthttp/closer.go b/module/apmfasthttp/closer.go index 8918092ce..1c732c42a 100644 --- a/module/apmfasthttp/closer.go +++ b/module/apmfasthttp/closer.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfasthttp/context.go b/module/apmfasthttp/context.go index e1d840190..fff4063ff 100644 --- a/module/apmfasthttp/context.go +++ b/module/apmfasthttp/context.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfasthttp/recovery.go b/module/apmfasthttp/recovery.go index d8cbae898..b453c6ad2 100644 --- a/module/apmfasthttp/recovery.go +++ b/module/apmfasthttp/recovery.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfasthttp/server.go b/module/apmfasthttp/server.go index 815e02e89..03fb8786b 100644 --- a/module/apmfasthttp/server.go +++ b/module/apmfasthttp/server.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfasthttp/server_test.go b/module/apmfasthttp/server_test.go index 5367e5f7e..8c0894fe7 100644 --- a/module/apmfasthttp/server_test.go +++ b/module/apmfasthttp/server_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp_test import ( diff --git a/module/apmfasthttp/types.go b/module/apmfasthttp/types.go index d5da642b7..b32286a63 100644 --- a/module/apmfasthttp/types.go +++ b/module/apmfasthttp/types.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfasthttp/utils.go b/module/apmfasthttp/utils.go index 8708c2275..1e0a2f985 100644 --- a/module/apmfasthttp/utils.go +++ b/module/apmfasthttp/utils.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.12 -// +build go1.12 - package apmfasthttp // import "go.elastic.co/apm/module/apmfasthttp" import ( diff --git a/module/apmfiber/middleware.go b/module/apmfiber/middleware.go index d63bba0c9..7423deaac 100644 --- a/module/apmfiber/middleware.go +++ b/module/apmfiber/middleware.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmfiber // import "go.elastic.co/apm/module/apmfiber" import ( diff --git a/module/apmfiber/middleware_test.go b/module/apmfiber/middleware_test.go index 901e0dcb7..64e981ec6 100644 --- a/module/apmfiber/middleware_test.go +++ b/module/apmfiber/middleware_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.13 -// +build go1.13 - package apmfiber_test import ( diff --git a/module/apmgin/middleware.go b/module/apmgin/middleware.go index 0fd7873ff..b7835958e 100644 --- a/module/apmgin/middleware.go +++ b/module/apmgin/middleware.go @@ -56,6 +56,12 @@ func Middleware(engine *gin.Engine, o ...Option) gin.HandlerFunc { return m.handle } +type middleware struct { + engine *gin.Engine + tracer *apm.Tracer + requestIgnorer apmhttp.RequestIgnorerFunc +} + func (m *middleware) handle(c *gin.Context) { if !m.tracer.Recording() || m.requestIgnorer(c.Request) { c.Next() @@ -98,6 +104,13 @@ func (m *middleware) handle(c *gin.Context) { c.Next() } +func (m *middleware) getRequestName(c *gin.Context) string { + if fullPath := c.FullPath(); fullPath != "" { + return c.Request.Method + " " + fullPath + } + return apmhttp.UnknownRouteRequestName(c.Request) +} + func setContext(ctx *apm.Context, c *gin.Context, body *apm.BodyCapturer) { ctx.SetFramework("gin", gin.Version) ctx.SetHTTPRequest(c.Request) diff --git a/module/apmgin/middleware_go110.go b/module/apmgin/middleware_go110.go deleted file mode 100644 index 2c8b7bf91..000000000 --- a/module/apmgin/middleware_go110.go +++ /dev/null @@ -1,41 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmgin // import "go.elastic.co/apm/module/apmgin" - -import ( - "github.com/gin-gonic/gin" - - "go.elastic.co/apm" - "go.elastic.co/apm/module/apmhttp" -) - -type middleware struct { - engine *gin.Engine - tracer *apm.Tracer - requestIgnorer apmhttp.RequestIgnorerFunc -} - -func (m *middleware) getRequestName(c *gin.Context) string { - if fullPath := c.FullPath(); fullPath != "" { - return c.Request.Method + " " + fullPath - } - return apmhttp.UnknownRouteRequestName(c.Request) -} diff --git a/module/apmgin/middleware_go18.go b/module/apmgin/middleware_go18.go deleted file mode 100644 index 16decde59..000000000 --- a/module/apmgin/middleware_go18.go +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmgin // import "go.elastic.co/apm/module/apmgin" - -import ( - "sync" - - "github.com/gin-gonic/gin" - - "go.elastic.co/apm" - "go.elastic.co/apm/module/apmhttp" -) - -type middleware struct { - engine *gin.Engine - tracer *apm.Tracer - requestIgnorer apmhttp.RequestIgnorerFunc - - setRouteMapOnce sync.Once - routeMap map[string]map[string]routeInfo -} - -type routeInfo struct { - transactionName string // e.g. "GET /foo" -} - -func (m *middleware) getRequestName(c *gin.Context) string { - // NOTE(axw) this implementation exists for older versions of Go (<1.10) - // which cannot use the version of Gin with `c.FullPath`. This is broken - // when the same handler is used for multiple routes. - m.setRouteMapOnce.Do(func() { - routes := m.engine.Routes() - rm := make(map[string]map[string]routeInfo) - for _, r := range routes { - mm := rm[r.Method] - if mm == nil { - mm = make(map[string]routeInfo) - rm[r.Method] = mm - } - mm[r.Handler] = routeInfo{ - transactionName: r.Method + " " + r.Path, - } - } - m.routeMap = rm - }) - if routeInfo, ok := m.routeMap[c.Request.Method][c.HandlerName()]; ok { - return routeInfo.transactionName - } - return apmhttp.UnknownRouteRequestName(c.Request) -} diff --git a/module/apmgin/middleware_test.go b/module/apmgin/middleware_test.go index 5d792e7a9..a29c4ce28 100644 --- a/module/apmgin/middleware_test.go +++ b/module/apmgin/middleware_test.go @@ -23,8 +23,6 @@ import ( "log" "net/http" "net/http/httptest" - "runtime" - "strings" "testing" "go.elastic.co/apm" @@ -73,13 +71,6 @@ func TestMiddlewareHTTPSuite(t *testing.T) { } func TestMiddlewareMultipleSameHandler(t *testing.T) { - runtimeVersion := runtime.Version() - switch { - case strings.HasPrefix(runtimeVersion, "go1.8"), - strings.HasPrefix(runtimeVersion, "go1.9"): - t.Skipf("Go %s implementation is broken", runtimeVersion) - } - debugOutput.Reset() do := func(url, method, targetTransactionName string) { diff --git a/module/apmgocql/apmgocql_test.go b/module/apmgocql/apmgocql_test.go index fb00febcc..c91a82255 100644 --- a/module/apmgocql/apmgocql_test.go +++ b/module/apmgocql/apmgocql_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgocql_test import ( diff --git a/module/apmgocql/doc.go b/module/apmgocql/doc.go index 693aee4ec..f9115342d 100644 --- a/module/apmgocql/doc.go +++ b/module/apmgocql/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - // Package apmgocql provides an observer for tracing gocql (Cassandra) query spans. package apmgocql // import "go.elastic.co/apm/module/apmgocql" diff --git a/module/apmgocql/observer.go b/module/apmgocql/observer.go index 8d7717980..f597e802f 100644 --- a/module/apmgocql/observer.go +++ b/module/apmgocql/observer.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgocql // import "go.elastic.co/apm/module/apmgocql" import ( diff --git a/module/apmgocql/signature.go b/module/apmgocql/signature.go index 8b4ab2359..542906e3f 100644 --- a/module/apmgocql/signature.go +++ b/module/apmgocql/signature.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgocql // import "go.elastic.co/apm/module/apmgocql" import ( diff --git a/module/apmgocql/signature_test.go b/module/apmgocql/signature_test.go index f246f35a2..5425c1f0b 100644 --- a/module/apmgocql/signature_test.go +++ b/module/apmgocql/signature_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgocql import ( diff --git a/module/apmgokit/grpc_test.go b/module/apmgokit/grpc_test.go index 225ef055f..2ce00d3a2 100644 --- a/module/apmgokit/grpc_test.go +++ b/module/apmgokit/grpc_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgokit_test import ( diff --git a/module/apmgopg/doc.go b/module/apmgopg/doc.go index 7ba9a1902..5fddc23e2 100644 --- a/module/apmgopg/doc.go +++ b/module/apmgopg/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - // Package apmgopg provides wrappers for tracing go-pg operations. package apmgopg // import "go.elastic.co/apm/module/apmgopg" diff --git a/module/apmgopg/hook.go b/module/apmgopg/hook.go index 2b52fd33b..ad2ce8f44 100644 --- a/module/apmgopg/hook.go +++ b/module/apmgopg/hook.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgopg // import "go.elastic.co/apm/module/apmgopg" import ( diff --git a/module/apmgopg/hook_test.go b/module/apmgopg/hook_test.go index 0f9ca995a..818578629 100644 --- a/module/apmgopg/hook_test.go +++ b/module/apmgopg/hook_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgopg_test import ( diff --git a/module/apmgopgv10/hook.go b/module/apmgopgv10/hook.go index 69547c27a..b655f3b90 100644 --- a/module/apmgopgv10/hook.go +++ b/module/apmgopgv10/hook.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmgopgv10 // import "go.elastic.co/apm/module/apmgopgv10" import ( diff --git a/module/apmgopgv10/hook_test.go b/module/apmgopgv10/hook_test.go index 82fa57810..79d1e2e4f 100644 --- a/module/apmgopgv10/hook_test.go +++ b/module/apmgopgv10/hook_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmgopgv10_test import ( diff --git a/module/apmgoredis/client.go b/module/apmgoredis/client.go index 59b3a6c2f..1766af3e0 100644 --- a/module/apmgoredis/client.go +++ b/module/apmgoredis/client.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgoredis // import "go.elastic.co/apm/module/apmgoredis" import ( diff --git a/module/apmgoredis/client_test.go b/module/apmgoredis/client_test.go index cc4398f93..d08d6f1c8 100644 --- a/module/apmgoredis/client_test.go +++ b/module/apmgoredis/client_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgoredis_test import ( diff --git a/module/apmgoredis/doc.go b/module/apmgoredis/doc.go index 79777d467..f4933e301 100644 --- a/module/apmgoredis/doc.go +++ b/module/apmgoredis/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - // Package apmgoredis provides helpers for tracing github.com/go-redis/redis client operations as spans. package apmgoredis // import "go.elastic.co/apm/module/apmgoredis" diff --git a/module/apmgoredis/integration_test.go b/module/apmgoredis/integration_test.go index c64c2e1fa..c004b2b80 100644 --- a/module/apmgoredis/integration_test.go +++ b/module/apmgoredis/integration_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgoredis_test import ( diff --git a/module/apmgoredisv8/doc.go b/module/apmgoredisv8/doc.go index 3f586a613..d707c519a 100644 --- a/module/apmgoredisv8/doc.go +++ b/module/apmgoredisv8/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - // Package apmgoredisv8 provides helpers for tracing github.com/go-redis/redis/v8 client operations as spans. package apmgoredisv8 // import "go.elastic.co/apm/module/apmgoredisv8" diff --git a/module/apmgoredisv8/hook.go b/module/apmgoredisv8/hook.go index 907c0610c..7afbe61cc 100644 --- a/module/apmgoredisv8/hook.go +++ b/module/apmgoredisv8/hook.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgoredisv8 // import "go.elastic.co/apm/module/apmgoredisv8" import ( diff --git a/module/apmgoredisv8/hook_test.go b/module/apmgoredisv8/hook_test.go index 0769e1194..8973669a2 100644 --- a/module/apmgoredisv8/hook_test.go +++ b/module/apmgoredisv8/hook_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmgoredisv8_test import ( diff --git a/module/apmgorm/apmgorm_test.go b/module/apmgorm/apmgorm_test.go index 5e77ad2b1..dde4f0ca5 100644 --- a/module/apmgorm/apmgorm_test.go +++ b/module/apmgorm/apmgorm_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgorm_test import ( diff --git a/module/apmgorm/context.go b/module/apmgorm/context.go index 3eee146d3..607c5a2af 100644 --- a/module/apmgorm/context.go +++ b/module/apmgorm/context.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgorm // import "go.elastic.co/apm/module/apmgorm" import ( diff --git a/module/apmgorm/doc.go b/module/apmgorm/doc.go index e547589a7..4be2ce883 100644 --- a/module/apmgorm/doc.go +++ b/module/apmgorm/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - // Package apmgorm provides wrappers for tracing GORM operations. package apmgorm // import "go.elastic.co/apm/module/apmgorm" diff --git a/module/apmgorm/open.go b/module/apmgorm/open.go index 70d8b5591..1862d4d62 100644 --- a/module/apmgorm/open.go +++ b/module/apmgorm/open.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgorm // import "go.elastic.co/apm/module/apmgorm" import ( diff --git a/module/apmgormv2/apmgorm_test.go b/module/apmgormv2/apmgorm_test.go index 9704764b4..78c73ad67 100644 --- a/module/apmgormv2/apmgorm_test.go +++ b/module/apmgormv2/apmgorm_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmgormv2_test import ( diff --git a/module/apmgormv2/driver/mysql/init.go b/module/apmgormv2/driver/mysql/init.go index e693d2b22..e06de297a 100644 --- a/module/apmgormv2/driver/mysql/init.go +++ b/module/apmgormv2/driver/mysql/init.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - // Package apmmysql imports the gorm mysql dialect package, // and also registers the mysql driver with apmsql. package apmmysql // import "go.elastic.co/apm/module/apmgormv2/driver/mysql" diff --git a/module/apmgormv2/driver/postgres/init.go b/module/apmgormv2/driver/postgres/init.go index 6543c656c..d8b8e2b84 100644 --- a/module/apmgormv2/driver/postgres/init.go +++ b/module/apmgormv2/driver/postgres/init.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - // Package apmpostgres imports the gorm mysql dialect package, // and also registers the mysql driver with apmsql. package apmpostgres // import "go.elastic.co/apm/module/apmgormv2/driver/postgres" diff --git a/module/apmgormv2/driver/sqlite/init.go b/module/apmgormv2/driver/sqlite/init.go index 712fbafec..845b53d2d 100644 --- a/module/apmgormv2/driver/sqlite/init.go +++ b/module/apmgormv2/driver/sqlite/init.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - // Package apmsqlite imports the gorm sqlite dialect package, // and also registers the sqlite3 driver with apmsql. package apmsqlite // import "go.elastic.co/apm/module/apmgormv2/driver/sqlite" diff --git a/module/apmgrpc/client.go b/module/apmgrpc/client.go index fcd56a0e5..0b7870be3 100644 --- a/module/apmgrpc/client.go +++ b/module/apmgrpc/client.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc // import "go.elastic.co/apm/module/apmgrpc" import ( diff --git a/module/apmgrpc/client_test.go b/module/apmgrpc/client_test.go index 45f925a10..a94432cdb 100644 --- a/module/apmgrpc/client_test.go +++ b/module/apmgrpc/client_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc_test import ( diff --git a/module/apmgrpc/doc.go b/module/apmgrpc/doc.go index b0393fe80..60353e93b 100644 --- a/module/apmgrpc/doc.go +++ b/module/apmgrpc/doc.go @@ -15,8 +15,5 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - // Package apmgrpc provides interceptors for tracing gRPC. package apmgrpc // import "go.elastic.co/apm/module/apmgrpc" diff --git a/module/apmgrpc/ignorer.go b/module/apmgrpc/ignorer.go index a2a9004df..8a4711579 100644 --- a/module/apmgrpc/ignorer.go +++ b/module/apmgrpc/ignorer.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc // import "go.elastic.co/apm/module/apmgrpc" import ( diff --git a/module/apmgrpc/ignorer_test.go b/module/apmgrpc/ignorer_test.go index fb221cabe..f3e06cb7e 100644 --- a/module/apmgrpc/ignorer_test.go +++ b/module/apmgrpc/ignorer_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc_test import ( diff --git a/module/apmgrpc/internal/testservice/testservice.pb.go b/module/apmgrpc/internal/testservice/testservice.pb.go index 86418b1fb..4adce6031 100644 --- a/module/apmgrpc/internal/testservice/testservice.pb.go +++ b/module/apmgrpc/internal/testservice/testservice.pb.go @@ -18,9 +18,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // source: testservice.proto -//go:build go1.9 -// +build go1.9 - package testservice // import "go.elastic.co/apm/module/apmgrpc/internal/testservice" import ( diff --git a/module/apmgrpc/packages.go b/module/apmgrpc/packages.go index fa91a5167..4f4a01893 100644 --- a/module/apmgrpc/packages.go +++ b/module/apmgrpc/packages.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc // import "go.elastic.co/apm/module/apmgrpc" import "go.elastic.co/apm/stacktrace" diff --git a/module/apmgrpc/server.go b/module/apmgrpc/server.go index 21d234c46..4dba32f35 100644 --- a/module/apmgrpc/server.go +++ b/module/apmgrpc/server.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc // import "go.elastic.co/apm/module/apmgrpc" import ( diff --git a/module/apmgrpc/server_test.go b/module/apmgrpc/server_test.go index 958483227..de7fc01e4 100644 --- a/module/apmgrpc/server_test.go +++ b/module/apmgrpc/server_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmgrpc_test import ( diff --git a/module/apmhttp/client_go112_test.go b/module/apmhttp/client_go112_test.go deleted file mode 100644 index 7f2cec8dc..000000000 --- a/module/apmhttp/client_go112_test.go +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.12 -// +build go1.12 - -package apmhttp_test - -import ( - "net/http" - "testing" - - "github.com/stretchr/testify/assert" - - "go.elastic.co/apm/module/apmhttp" -) - -func TestClientCloseIdleConnections(t *testing.T) { - var closed bool - transport := &idleConnectionsCloser{ - RoundTripper: http.DefaultTransport, - closeIdleConnections: func() { - closed = true - }, - } - client := &http.Client{ - Transport: apmhttp.WrapRoundTripper(transport), - } - client.CloseIdleConnections() - assert.True(t, closed) -} - -type idleConnectionsCloser struct { - http.RoundTripper - closeIdleConnections func() -} - -func (c *idleConnectionsCloser) CloseIdleConnections() { - c.closeIdleConnections() -} diff --git a/module/apmhttp/client_test.go b/module/apmhttp/client_test.go index 2a5f6d682..df5dc16c4 100644 --- a/module/apmhttp/client_test.go +++ b/module/apmhttp/client_test.go @@ -370,6 +370,30 @@ func TestWithClientSpanType(t *testing.T) { assert.Equal(t, "cache", span.Type) } +func TestClientCloseIdleConnections(t *testing.T) { + var closed bool + transport := &idleConnectionsCloser{ + RoundTripper: http.DefaultTransport, + closeIdleConnections: func() { + closed = true + }, + } + client := &http.Client{ + Transport: apmhttp.WrapRoundTripper(transport), + } + client.CloseIdleConnections() + assert.True(t, closed) +} + +type idleConnectionsCloser struct { + http.RoundTripper + closeIdleConnections func() +} + +func (c *idleConnectionsCloser) CloseIdleConnections() { + c.closeIdleConnections() +} + func mustGET(ctx context.Context, url string, o ...apmhttp.ClientOption) (statusCode int, responseBody string) { client := apmhttp.WrapClient(http.DefaultClient, o...) resp, err := ctxhttp.Get(ctx, client, url) diff --git a/module/apmhttp/handler_http2_test.go b/module/apmhttp/handler_http2_test.go index 5bf6c34e5..89c19f505 100644 --- a/module/apmhttp/handler_http2_test.go +++ b/module/apmhttp/handler_http2_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmhttp_test import ( diff --git a/module/apmhttp/requestname.go b/module/apmhttp/requestname.go index 13e9b7dc4..492e11e09 100644 --- a/module/apmhttp/requestname.go +++ b/module/apmhttp/requestname.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmhttp // import "go.elastic.co/apm/module/apmhttp" import ( diff --git a/module/apmhttp/requestname_go19.go b/module/apmhttp/requestname_go19.go deleted file mode 100644 index 1958a31da..000000000 --- a/module/apmhttp/requestname_go19.go +++ /dev/null @@ -1,47 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmhttp // import "go.elastic.co/apm/module/apmhttp" - -import "net/http" - -// UnknownRouteRequestName returns the transaction name for the server request, req, -// when the route could not be determined. -func UnknownRouteRequestName(req *http.Request) string { - return req.Method + " unknown route" -} - -// ServerRequestName returns the transaction name for the server request, req. -func ServerRequestName(req *http.Request) string { - buf := make([]byte, len(req.Method)+len(req.URL.Path)+1) - n := copy(buf, req.Method) - buf[n] = ' ' - copy(buf[n+1:], req.URL.Path) - return string(buf) -} - -// ClientRequestName returns the span name for the client request, req. -func ClientRequestName(req *http.Request) string { - buf := make([]byte, len(req.Method)+len(req.URL.Host)+1) - n := copy(buf, req.Method) - buf[n] = ' ' - copy(buf[n+1:], req.URL.Host) - return string(buf) -} diff --git a/module/apmmongo/monitor.go b/module/apmmongo/monitor.go index 2c14890b2..00cae6f01 100644 --- a/module/apmmongo/monitor.go +++ b/module/apmmongo/monitor.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmmongo // import "go.elastic.co/apm/module/apmmongo" import ( diff --git a/module/apmmongo/monitor_benchmark_test.go b/module/apmmongo/monitor_benchmark_test.go index 0741459f0..c13612c8b 100644 --- a/module/apmmongo/monitor_benchmark_test.go +++ b/module/apmmongo/monitor_benchmark_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmmongo_test import ( diff --git a/module/apmmongo/monitor_integration_test.go b/module/apmmongo/monitor_integration_test.go index 7ad2a9c91..e90ece91e 100644 --- a/module/apmmongo/monitor_integration_test.go +++ b/module/apmmongo/monitor_integration_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmmongo_test import ( diff --git a/module/apmmongo/monitor_test.go b/module/apmmongo/monitor_test.go index 8959fd4a6..7acb7e4d9 100644 --- a/module/apmmongo/monitor_test.go +++ b/module/apmmongo/monitor_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.10 -// +build go1.10 - package apmmongo_test import ( diff --git a/module/apmrestfulv3/filter.go b/module/apmrestfulv3/filter.go index 41f09a904..a785425e6 100644 --- a/module/apmrestfulv3/filter.go +++ b/module/apmrestfulv3/filter.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmrestfulv3 // import "go.elastic.co/apm/module/apmrestfulv3" import ( diff --git a/module/apmrestfulv3/filter_example_test.go b/module/apmrestfulv3/filter_example_test.go index c176897ac..250ebc475 100644 --- a/module/apmrestfulv3/filter_example_test.go +++ b/module/apmrestfulv3/filter_example_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmrestfulv3_test import ( diff --git a/module/apmrestfulv3/filter_test.go b/module/apmrestfulv3/filter_test.go index 9bbfc6a59..313778916 100644 --- a/module/apmrestfulv3/filter_test.go +++ b/module/apmrestfulv3/filter_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmrestfulv3_test import ( diff --git a/module/apmrestfulv3/route.go b/module/apmrestfulv3/route.go index ee7779564..4d01901d3 100644 --- a/module/apmrestfulv3/route.go +++ b/module/apmrestfulv3/route.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmrestfulv3 // import "go.elastic.co/apm/module/apmrestfulv3" import ( diff --git a/module/apmrestfulv3/route_test.go b/module/apmrestfulv3/route_test.go index 31ee659a5..1924bbad2 100644 --- a/module/apmrestfulv3/route_test.go +++ b/module/apmrestfulv3/route_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.11 -// +build go1.11 - package apmrestfulv3 import ( diff --git a/module/apmsql/apmsql_go110_test.go b/module/apmsql/apmsql_go110_test.go deleted file mode 100644 index ef7eb9609..000000000 --- a/module/apmsql/apmsql_go110_test.go +++ /dev/null @@ -1,50 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmsql_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "go.elastic.co/apm/apmtest" - "go.elastic.co/apm/module/apmsql" -) - -func TestConnect(t *testing.T) { - db, err := apmsql.Open("sqlite3", ":memory:") - require.NoError(t, err) - defer db.Close() - - // Note: only in Go 1.10 do we have context during connection. - - _, spans, _ := apmtest.WithTransaction(func(ctx context.Context) { - err := db.PingContext(ctx) - assert.NoError(t, err) - }) - require.Len(t, spans, 2) - assert.Equal(t, "connect", spans[0].Name) - assert.Equal(t, "connect", spans[0].Action) - assert.Equal(t, "ping", spans[1].Name) - assert.Equal(t, "ping", spans[1].Action) -} diff --git a/module/apmsql/apmsql_test.go b/module/apmsql/apmsql_test.go index 286d99e8e..af9eda6ad 100644 --- a/module/apmsql/apmsql_test.go +++ b/module/apmsql/apmsql_test.go @@ -326,6 +326,22 @@ func TestContextCanceled(t *testing.T) { assert.Len(t, errors, 0) // no "context canceled" errors reported } +func TestConnect(t *testing.T) { + db, err := apmsql.Open("sqlite3", ":memory:") + require.NoError(t, err) + defer db.Close() + + _, spans, _ := apmtest.WithTransaction(func(ctx context.Context) { + err := db.PingContext(ctx) + assert.NoError(t, err) + }) + require.Len(t, spans, 2) + assert.Equal(t, "connect", spans[0].Name) + assert.Equal(t, "connect", spans[0].Action) + assert.Equal(t, "ping", spans[1].Name) + assert.Equal(t, "ping", spans[1].Action) +} + type sqlite3TestDriver struct { sqlite3.SQLiteDriver } diff --git a/module/apmsql/conn.go b/module/apmsql/conn.go index 4ab61bc5b..b06028cc8 100644 --- a/module/apmsql/conn.go +++ b/module/apmsql/conn.go @@ -25,6 +25,8 @@ import ( "go.elastic.co/apm" ) +var _ driver.Validator = (*conn)(nil) + func newConn(in driver.Conn, d *tracingDriver, dsnInfo DSNInfo) driver.Conn { conn := &conn{Conn: in, driver: d} conn.dsnInfo = dsnInfo @@ -36,8 +38,8 @@ func newConn(in driver.Conn, d *tracingDriver, dsnInfo DSNInfo) driver.Conn { conn.execer, _ = in.(driver.Execer) conn.execerContext, _ = in.(driver.ExecerContext) conn.connBeginTx, _ = in.(driver.ConnBeginTx) - conn.connGo110.init(in) - conn.connGo115.init(in) + conn.sessionResetter, _ = in.(driver.SessionResetter) + conn.validator, _ = in.(driver.Validator) if in, ok := in.(driver.ConnBeginTx); ok { return &connBeginTx{conn, in} } @@ -46,8 +48,6 @@ func newConn(in driver.Conn, d *tracingDriver, dsnInfo DSNInfo) driver.Conn { type conn struct { driver.Conn - connGo110 - connGo115 driver *tracingDriver dsnInfo DSNInfo @@ -59,6 +59,8 @@ type conn struct { execer driver.Execer execerContext driver.ExecerContext connBeginTx driver.ConnBeginTx + sessionResetter driver.SessionResetter + validator driver.Validator } func (c *conn) startStmtSpan(ctx context.Context, stmt, spanType string) (*apm.Span, context.Context) { @@ -206,6 +208,20 @@ func (c *conn) CheckNamedValue(nv *driver.NamedValue) error { return checkNamedValue(nv, c.namedValueChecker) } +func (c *conn) ResetSession(ctx context.Context) error { + if c.sessionResetter != nil { + return c.sessionResetter.ResetSession(ctx) + } + return nil +} + +func (c *conn) IsValid() bool { + if c.validator != nil { + return c.validator.IsValid() + } + return true +} + type connBeginTx struct { *conn connBeginTx driver.ConnBeginTx diff --git a/module/apmsql/conn_go110.go b/module/apmsql/conn_go110.go deleted file mode 100644 index 2774ba7fe..000000000 --- a/module/apmsql/conn_go110.go +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import ( - "context" - "database/sql/driver" -) - -// Support for Conn interfaces introduced in Go 1.10 and later. -type connGo110 struct { - sessionResetter driver.SessionResetter -} - -func (c *connGo110) init(in driver.Conn) { - c.sessionResetter, _ = in.(driver.SessionResetter) -} - -func (c *connGo110) ResetSession(ctx context.Context) error { - if c.sessionResetter != nil { - return c.sessionResetter.ResetSession(ctx) - } - return nil -} diff --git a/module/apmsql/conn_go115.go b/module/apmsql/conn_go115.go deleted file mode 100644 index 4436edcb4..000000000 --- a/module/apmsql/conn_go115.go +++ /dev/null @@ -1,43 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.15 -// +build go1.15 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import ( - "database/sql/driver" -) - -var _ driver.Validator = (*conn)(nil) - -// Support for Conn interfaces introduced in Go 1.15 and later. -type connGo115 struct { - validator driver.Validator -} - -func (c *connGo115) init(in driver.Conn) { - c.validator, _ = in.(driver.Validator) -} - -func (c *connGo115) IsValid() bool { - if c.validator != nil { - return c.validator.IsValid() - } - return true -} diff --git a/module/apmsql/conn_pre_go110.go b/module/apmsql/conn_pre_go110.go deleted file mode 100644 index 75503adfa..000000000 --- a/module/apmsql/conn_pre_go110.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.10 -// +build !go1.10 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import "database/sql/driver" - -type connGo110 struct{} - -func (connGo110) init(in driver.Conn) {} diff --git a/module/apmsql/conn_pre_go115.go b/module/apmsql/conn_pre_go115.go deleted file mode 100644 index 23a7b958c..000000000 --- a/module/apmsql/conn_pre_go115.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.15 -// +build !go1.15 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import "database/sql/driver" - -type connGo115 struct{} - -func (connGo115) init(in driver.Conn) {} diff --git a/module/apmsql/driver.go b/module/apmsql/driver.go index a5b28ddbd..3759923a4 100644 --- a/module/apmsql/driver.go +++ b/module/apmsql/driver.go @@ -18,11 +18,13 @@ package apmsql // import "go.elastic.co/apm/module/apmsql" import ( + "context" "database/sql" "database/sql/driver" "fmt" "sync" + "go.elastic.co/apm" "go.elastic.co/apm/sqlutil" ) @@ -145,6 +147,11 @@ func (d *tracingDriver) querySignature(query string) string { return QuerySignature(query) } +// Unwrap returns the wrapped database/sql/driver.Driver. +func (d *tracingDriver) Unwrap() driver.Driver { + return d.Driver +} + func (d *tracingDriver) Open(name string) (driver.Conn, error) { conn, err := d.Driver.Open(name) if err != nil { @@ -153,7 +160,44 @@ func (d *tracingDriver) Open(name string) (driver.Conn, error) { return newConn(conn, d, d.dsnParser(name)), nil } -// Unwrap returns the wrapped database/sql/driver.Driver. -func (d *tracingDriver) Unwrap() driver.Driver { - return d.Driver +func (d *tracingDriver) OpenConnector(name string) (driver.Connector, error) { + if dc, ok := d.Driver.(driver.DriverContext); ok { + oc, err := dc.OpenConnector(name) + if err != nil { + return nil, err + } + return &driverConnector{oc.Connect, d, name}, nil + } + connect := func(context.Context) (driver.Conn, error) { + return d.Driver.Open(name) + } + return &driverConnector{connect, d, name}, nil +} + +type driverConnector struct { + connect func(context.Context) (driver.Conn, error) + driver *tracingDriver + name string +} + +func (d *driverConnector) Connect(ctx context.Context) (driver.Conn, error) { + span, ctx := apm.StartSpan(ctx, "connect", d.driver.connectSpanType) + defer span.End() + dsnInfo := d.driver.dsnParser(d.name) + if !span.Dropped() { + span.Context.SetDatabase(apm.DatabaseSpanContext{ + Instance: dsnInfo.Database, + Type: "sql", + User: dsnInfo.User, + }) + } + conn, err := d.connect(ctx) + if err != nil { + return nil, err + } + return newConn(conn, d.driver, dsnInfo), nil +} + +func (d *driverConnector) Driver() driver.Driver { + return d.driver } diff --git a/module/apmsql/driver_go110.go b/module/apmsql/driver_go110.go deleted file mode 100644 index 6575f28d4..000000000 --- a/module/apmsql/driver_go110.go +++ /dev/null @@ -1,70 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build go1.10 -// +build go1.10 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import ( - "context" - "database/sql/driver" - - "go.elastic.co/apm" -) - -func (d *tracingDriver) OpenConnector(name string) (driver.Connector, error) { - if dc, ok := d.Driver.(driver.DriverContext); ok { - oc, err := dc.OpenConnector(name) - if err != nil { - return nil, err - } - return &driverConnector{oc.Connect, d, name}, nil - } - connect := func(context.Context) (driver.Conn, error) { - return d.Driver.Open(name) - } - return &driverConnector{connect, d, name}, nil -} - -type driverConnector struct { - connect func(context.Context) (driver.Conn, error) - driver *tracingDriver - name string -} - -func (d *driverConnector) Connect(ctx context.Context) (driver.Conn, error) { - span, ctx := apm.StartSpan(ctx, "connect", d.driver.connectSpanType) - defer span.End() - dsnInfo := d.driver.dsnParser(d.name) - if !span.Dropped() { - span.Context.SetDatabase(apm.DatabaseSpanContext{ - Instance: dsnInfo.Database, - Type: "sql", - User: dsnInfo.User, - }) - } - conn, err := d.connect(ctx) - if err != nil { - return nil, err - } - return newConn(conn, d.driver, dsnInfo), nil -} - -func (d *driverConnector) Driver() driver.Driver { - return d.driver -} diff --git a/module/apmsql/pgxv4/doc.go b/module/apmsql/pgxv4/doc.go index d8a5cf4d6..6b687e67d 100644 --- a/module/apmsql/pgxv4/doc.go +++ b/module/apmsql/pgxv4/doc.go @@ -17,8 +17,4 @@ // Package apmpgxv4 registers the "postgres" driver with // apmsql, so that you can trace pgx/v4 database connections. - -//go:build go1.14 -// +build go1.14 - package apmpgxv4 // import "go.elastic.co/apm/module/apmsql/pgxv4" diff --git a/module/apmsql/pgxv4/init.go b/module/apmsql/pgxv4/init.go index edc597d52..a9f351424 100644 --- a/module/apmsql/pgxv4/init.go +++ b/module/apmsql/pgxv4/init.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmpgxv4 // import "go.elastic.co/apm/module/apmsql/pgxv4" import ( diff --git a/module/apmsql/pgxv4/pq_test.go b/module/apmsql/pgxv4/pq_test.go index 2c7d2ff4d..941632d53 100644 --- a/module/apmsql/pgxv4/pq_test.go +++ b/module/apmsql/pgxv4/pq_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.14 -// +build go1.14 - package apmpgxv4_test import ( diff --git a/module/apmsql/stmt_pre_go19.go b/module/apmsql/stmt_pre_go19.go deleted file mode 100644 index 175b4b43a..000000000 --- a/module/apmsql/stmt_pre_go19.go +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build !go1.9 -// +build !go1.9 - -package apmsql // import "go.elastic.co/apm/module/apmsql" - -import "database/sql/driver" - -type stmtGo19 struct{} - -func (stmtGo19) init(in driver.Stmt) {} diff --git a/module/apmzap/core.go b/module/apmzap/core.go index 4a8b74631..33383f190 100644 --- a/module/apmzap/core.go +++ b/module/apmzap/core.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmzap // import "go.elastic.co/apm/module/apmzap" import ( diff --git a/module/apmzap/core_test.go b/module/apmzap/core_test.go index 19ca81d23..6f7f6a7d9 100644 --- a/module/apmzap/core_test.go +++ b/module/apmzap/core_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmzap_test import ( diff --git a/module/apmzap/fields.go b/module/apmzap/fields.go index 54720d6f8..2f6b986fd 100644 --- a/module/apmzap/fields.go +++ b/module/apmzap/fields.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmzap // import "go.elastic.co/apm/module/apmzap" import ( diff --git a/module/apmzap/fields_test.go b/module/apmzap/fields_test.go index 338d93dae..405ff2458 100644 --- a/module/apmzap/fields_test.go +++ b/module/apmzap/fields_test.go @@ -15,9 +15,6 @@ // specific language governing permissions and limitations // under the License. -//go:build go1.9 -// +build go1.9 - package apmzap_test import ( diff --git a/sampler.go b/sampler.go index 25f02c84e..0dfdd5882 100644 --- a/sampler.go +++ b/sampler.go @@ -23,8 +23,6 @@ import ( "math/big" "github.com/pkg/errors" - - "go.elastic.co/apm/internal/apmmath" ) // Sampler provides a means of sampling transactions. @@ -128,5 +126,5 @@ func roundSampleRate(r float64) float64 { if r > 0 && r < 0.0001 { r = 0.0001 } - return apmmath.Round(r*10000) / 10000 + return math.Round(r*10000) / 10000 } diff --git a/scripts/before_install.sh b/scripts/before_install.sh deleted file mode 100755 index 362d71a70..000000000 --- a/scripts/before_install.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail - -if (go run scripts/mingoversion.go 1.11 &>/dev/null); then - exit -fi - -# Pin various dependencies for old Go versions. - -function pin() { - repo=$1 - commit=$2 - orgdir=$(dirname "${GOPATH}/src/$repo") - projname=$(basename "$repo") - if [ $# -eq 3 ]; then - url=$3 - else - url="https://$repo" - fi - mkdir -p "$orgdir" - (cd "$orgdir" && git clone "$url" "$projname" && cd $projname && git checkout $commit) -} - -# Go 1.8-1.10 -pin go.uber.org/multierr v1.6.0 https://github.com/uber-go/multierr -pin github.com/astaxie/beego v1.11.1 -pin github.com/stretchr/testify v1.4.0 -pin github.com/elastic/go-sysinfo v1.3.0 -pin google.golang.org/grpc v1.30.0 https://github.com/grpc/grpc-go -pin github.com/jinzhu/gorm v1.9.16 -pin github.com/ugorji/go v1.1.10 -pin github.com/go-chi/chi v1.5.1 -pin github.com/prometheus/client_golang v1.1.0 -pin github.com/emicklei/go-restful v2.9.6 -pin github.com/go-sql-driver/mysql v1.4.1 -pin golang.org/x/net 5f58ad60dda6 https://github.com/golang/net -pin github.com/santhosh-tekuri/jsonschema v4.0.0 -pin go.uber.org/zap v1.16.0 https://github.com/uber-go/zap -pin github.com/mattn/go-sqlite3 2b780b4a7fb3 -pin github.com/olivere/elastic v7.0.29 - -# Go 1.8-1.9 -if (! go run scripts/mingoversion.go 1.10 &>/dev/null); then - pin github.com/gocql/gocql 16cf9ea1b3e2 - pin github.com/labstack/echo v4.1.9 - pin github.com/lib/pq v1.0.0 - pin github.com/gin-gonic/gin v1.3.0 -else - pin github.com/gin-gonic/gin v1.5.0 # Use gin v1.5.0 for 1.10 only -fi - -# Go 1.8 only. -if (! go run scripts/mingoversion.go 1.9 &>/dev/null); then - pin github.com/golang/protobuf v1.3.5 - pin golang.org/x/sys fc99dfbffb4e https://go.googlesource.com/sys -fi diff --git a/scripts/jenkins/before_install.sh b/scripts/jenkins/before_install.sh deleted file mode 100755 index ab277ef80..000000000 --- a/scripts/jenkins/before_install.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -euxo pipefail - -source ./scripts/jenkins/setenv.sh -./scripts/before_install.sh diff --git a/scripts/jenkins/setenv.sh b/scripts/jenkins/setenv.sh index aa5929d99..dbc29cb02 100755 --- a/scripts/jenkins/setenv.sh +++ b/scripts/jenkins/setenv.sh @@ -5,11 +5,8 @@ set -euxo pipefail echo "Installing ${GO_VERSION} with gimme." eval "$(curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | GIMME_GO_VERSION=${GO_VERSION} bash)" -# Install tools used only in CI using a local go.mod file when using Go 1.14+. -GO_GET_FLAGS= -if [ "$(go run ./scripts/mingoversion.go -print 1.14)" = "true" ]; then - GO_GET_FLAGS="-modfile=$PWD/scripts/jenkins/jenkins.go.mod" -fi +# Install tools used only in CI using a local go.mod file. +GO_GET_FLAGS="-modfile=$PWD/scripts/jenkins/jenkins.go.mod" go get $GO_GET_FLAGS -v github.com/jstemmer/go-junit-report go get $GO_GET_FLAGS -v github.com/t-yuki/gocover-cobertura diff --git a/scripts/mingoversion.go b/scripts/mingoversion.go deleted file mode 100644 index 231aa5ffd..000000000 --- a/scripts/mingoversion.go +++ /dev/null @@ -1,93 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you 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. - -//go:build ignore -// +build ignore - -package main - -import ( - "flag" - "fmt" - "os" - "regexp" - "runtime" - "strconv" -) - -var ( - printFlag = flag.Bool("print", false, "Print true or false, and always exit with 0 except in case of usage errors") -) - -func main() { - flag.Parse() - if flag.NArg() == 0 { - fmt.Fprintf(os.Stderr, "Usage: %s \n", os.Args) - os.Exit(2) - } - - re := regexp.MustCompile(`^(?:go)?(\d+).(\d+)(?:\.(\d+))?$`) - arg := flag.Arg(0) - argSubmatch := re.FindStringSubmatch(arg) - if argSubmatch == nil { - fmt.Fprintln(os.Stderr, "Invalid minimum-version: expected x.y or x.y.z") - os.Exit(2) - } - - runtimeVersion := runtime.Version() - goSubmatch := re.FindStringSubmatch(runtimeVersion) - if goSubmatch == nil { - fmt.Fprintln(os.Stderr, "Failed to parse runtime.Version(%s)", runtimeVersion) - os.Exit(3) - } - - result := true - minVersion := makeInts(argSubmatch[1:]) - goVersion := makeInts(goSubmatch[1:]) - for i := range minVersion { - n := goVersion[i] - minVersion[i] - if n < 0 { - if *printFlag { - result = false - } else { - fmt.Fprintf(os.Stderr, "%s < %s\n", runtimeVersion, arg) - os.Exit(1) - } - } - if n > 0 { - break - } - } - if *printFlag { - fmt.Println(result) - } -} - -func makeInts(s []string) []int { - ints := make([]int, len(s)) - for i, s := range s { - if s == "" { - s = "0" - } - n, err := strconv.Atoi(s) - if err != nil { - panic(err) - } - ints[i] = n - } - return ints -} diff --git a/span_compressed.go b/span_compressed.go index ad2fef93c..ab9ca54d9 100644 --- a/span_compressed.go +++ b/span_compressed.go @@ -18,10 +18,10 @@ package apm // import "go.elastic.co/apm" import ( + "strings" "sync/atomic" "time" - "go.elastic.co/apm/internal/apmstrings" "go.elastic.co/apm/model" ) @@ -261,7 +261,12 @@ func (s *SpanData) setCompressedSpanName() { return } service := s.Context.destinationService.Resource - s.Name = apmstrings.Concat(compressedSpanSameKindName, service) + + var builder strings.Builder + builder.Grow(len(compressedSpanSameKindName) + len(service)) + builder.WriteString(compressedSpanSameKindName) + builder.WriteString(service) + s.Name = builder.String() } type compressedSpan struct {