Skip to content

Commit

Permalink
Merge branch 'v1' into feature/contrib-sql-conn-trace
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgajg1134 committed Jan 31, 2022
2 parents 2fc5290 + 7105d69 commit caf0d63
Show file tree
Hide file tree
Showing 320 changed files with 7,892 additions and 689 deletions.
25 changes: 17 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: 2

plain-go113: &plain-go113
plain-go114: &plain-go114
working_directory: /home/circleci/dd-trace-go.v1
docker:
- image: circleci/golang:1.13
- image: circleci/golang:1.14
environment:
GOPATH: "/home/circleci/go"

Expand All @@ -24,7 +24,7 @@ jobs:
go build ./ddtrace/... ./profiler/...
metadata:
<<: *plain-go113
<<: *plain-go114

steps:
- checkout
Expand All @@ -40,7 +40,7 @@ jobs:
go run checkcopyright.go
lint:
<<: *plain-go113
<<: *plain-go114

steps:
- checkout
Expand All @@ -62,19 +62,24 @@ jobs:
test-core:
resource_class: xlarge
<<: *plain-go113
<<: *plain-go114

steps:
- checkout
- run:
name: Testing
command: go test -v -race `go list ./... | grep -v /contrib/`
command: go test -v -race -coverprofile=coverage.txt -covermode=atomic `go list ./... | grep -v /contrib/`

- run:
name: Upload coverage report to Codecov
command: bash <(curl -s https://codecov.io/bash)


test-contrib:
resource_class: xlarge
working_directory: /home/circleci/dd-trace-go.v1
docker:
- image: circleci/golang:1.13
- image: circleci/golang:1.14
environment:
GOPATH: "/home/circleci/go"
- image: cassandra:3.7
Expand Down Expand Up @@ -183,12 +188,16 @@ jobs:
- run:
name: Testing
command: |
INTEGRATION=1 go test -v -race `go list ./contrib/... | grep -v -e grpc.v12 -e google.golang.org/api`
INTEGRATION=1 go test -v -race -coverprofile=coverage.txt -covermode=atomic `go list ./contrib/... | grep -v -e grpc.v12 -e google.golang.org/api`
go get google.golang.org/grpc@v1.29.0 # https://github.com/grpc/grpc-go/issues/3726
go test -v ./contrib/google.golang.org/api/...
go get google.golang.org/grpc@v1.2.0
go test -v ./contrib/google.golang.org/grpc.v12/...
- run:
name: Upload coverage report to Codecov
command: bash <(curl -s https://codecov.io/bash)

workflows:
version: 2
build-and-test:
Expand Down
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,28 @@ Fixes #113
```
Please apply the same logic for Pull Requests and Issues: start with the package name, followed by a colon and a description of the change, just like
the official [Go language](https://github.com/golang/go/pulls).

### Style guidelines

A set of [Style guidelines](https://github.com/DataDog/dd-trace-go/wiki/Style-guidelines) was added to our Wiki. Please spend some time browsing it.
It will help tremendously in avoiding comments and speeding up the PR process.

### Go Modules

This repository currently takes an [idiosyncratic approach](https://github.com/DataDog/dd-trace-go/issues/810) to using Go modules which means that you should not commit modified versions of the `go.mod` or `go.sum` files.

The following git command can be used to permanently ignore modifications to these files:

```
git update-index --assume-unchanged go.*
```

If you need to undo this for any reason, you can run:

```
git update-index --no-assume-unchanged go.*
```

### Milestones

The maintainers of this repository assign milestones to pull requests to classify them. `Triage` indicates that it is yet to be decided which version the change will go into. Pull requests that are ready get the upcoming release version assigned.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![CircleCI](https://circleci.com/gh/DataDog/dd-trace-go/tree/v1.svg?style=svg)](https://circleci.com/gh/DataDog/dd-trace-go/tree/v1)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/gopkg.in/DataDog/dd-trace-go.v1/ddtrace)
[![codecov](https://codecov.io/gh/DataDog/dd-trace-go/branch/v1/graph/badge.svg?token=jGG20Xhv8i)](https://codecov.io/gh/DataDog/dd-trace-go)

### Installing

Expand Down
5 changes: 2 additions & 3 deletions checkcopyright.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

// +build ignore

Expand All @@ -16,12 +16,11 @@ import (
"os"
"path/filepath"
"strings"
"time"
)

func main() {
var missing bool
copyrightText := []byte(fmt.Sprintf("// Copyright 2016-%s Datadog, Inc.", time.Now().Format("2006")))
copyrightText := []byte(fmt.Sprintf("// Copyright 2016 Datadog, Inc."))
if err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion checkmilestone.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

// +build ignore

Expand Down
30 changes: 30 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
comment: false

coverage:
status:
project:
default: false
core:
target: 80%
flags:
- core
contrib:
target: 75%
flags:
- contrib
patch:
default:
target: 100%

flags:
core:
paths:
- ddtrace/*
- internal/*
- profiler/*
contrib:
paths:
- contrib/*

github_checks:
annotations: false
2 changes: 1 addition & 1 deletion contrib/Shopify/sarama/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package sarama_test

Expand Down
2 changes: 1 addition & 1 deletion contrib/Shopify/sarama/headers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package sarama

Expand Down
2 changes: 1 addition & 1 deletion contrib/Shopify/sarama/option.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package sarama

Expand Down
5 changes: 4 additions & 1 deletion contrib/Shopify/sarama/sarama.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

// Package sarama provides functions to trace the Shopify/sarama package (https://github.com/Shopify/sarama).
package sarama // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama"
Expand Down Expand Up @@ -36,6 +36,7 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Partition Consumer: %#v", cfg)
wrapped := &partitionConsumer{
PartitionConsumer: pc,
messages: make(chan *sarama.ConsumerMessage),
Expand Down Expand Up @@ -143,6 +144,7 @@ func WrapSyncProducer(saramaConfig *sarama.Config, producer sarama.SyncProducer,
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Sync Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
}
Expand Down Expand Up @@ -186,6 +188,7 @@ func WrapAsyncProducer(saramaConfig *sarama.Config, p sarama.AsyncProducer, opts
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/Shopify/sarama: Wrapping Async Producer: %#v", cfg)
if saramaConfig == nil {
saramaConfig = sarama.NewConfig()
saramaConfig.Version = sarama.V0_11_0_0
Expand Down
2 changes: 1 addition & 1 deletion contrib/Shopify/sarama/sarama_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package sarama

Expand Down
21 changes: 14 additions & 7 deletions contrib/aws/aws-sdk-go/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

// Package aws provides functions to trace aws/aws-sdk-go (https://github.com/aws/aws-sdk-go).
package aws // import "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go/aws"
Expand All @@ -10,18 +10,20 @@ import (
"math"
"strconv"

"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"

"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"

"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
)

const (
tagAWSAgent = "aws.agent"
tagAWSOperation = "aws.operation"
tagAWSRegion = "aws.region"
tagAWSAgent = "aws.agent"
tagAWSOperation = "aws.operation"
tagAWSRegion = "aws.region"
tagAWSRetryCount = "aws.retry_count"
)

type handlers struct {
Expand All @@ -35,6 +37,7 @@ func WrapSession(s *session.Session, opts ...Option) *session.Session {
for _, opt := range opts {
opt(cfg)
}
log.Debug("contrib/aws/aws-sdk-go/aws: Wrapping Session: %#v", cfg)
h := &handlers{cfg: cfg}
s = s.Copy()
s.Handlers.Send.PushFrontNamed(request.NamedHandler{
Expand All @@ -49,6 +52,9 @@ func WrapSession(s *session.Session, opts ...Option) *session.Session {
}

func (h *handlers) Send(req *request.Request) {
if req.RetryCount != 0 {
return
}
opts := []ddtrace.StartSpanOption{
tracer.SpanType(ext.SpanTypeHTTP),
tracer.ServiceName(h.serviceName(req)),
Expand All @@ -71,6 +77,7 @@ func (h *handlers) Complete(req *request.Request) {
if !ok {
return
}
span.SetTag(tagAWSRetryCount, req.RetryCount)
if req.HTTPResponse != nil {
span.SetTag(ext.HTTPCode, strconv.Itoa(req.HTTPResponse.StatusCode))
}
Expand Down
36 changes: 35 additions & 1 deletion contrib/aws/aws-sdk-go/aws/aws_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package aws

import (
"context"
"errors"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/s3"
Expand Down Expand Up @@ -142,3 +144,35 @@ func TestAnalyticsSettings(t *testing.T) {
assertRate(t, mt, 0.23, WithAnalyticsRate(0.23))
})
}

func TestRetries(t *testing.T) {
cfg := aws.NewConfig().
WithRegion("us-west-2").
WithDisableSSL(true).
WithCredentials(credentials.AnonymousCredentials)

session := WrapSession(session.Must(session.NewSession(cfg)))
expectedError := errors.New("an error")
session.Handlers.Send.PushBack(func(r *request.Request) {
r.Error = expectedError
r.Retryable = aws.Bool(true)
})

mt := mocktracer.Start()
defer mt.Stop()

ctx := context.Background()
s3api := s3.New(session)
req, _ := s3api.GetObjectRequest(&s3.GetObjectInput{
Bucket: aws.String("BUCKET"),
Key: aws.String("KEY"),
})
req.SetContext(ctx)
err := req.Send()

assert.Equal(t, 3, req.RetryCount)
assert.Same(t, expectedError, err)
assert.Len(t, mt.OpenSpans(), 0)
assert.Len(t, mt.FinishedSpans(), 1)
assert.Equal(t, mt.FinishedSpans()[0].Tag(tagAWSRetryCount), 3)
}
2 changes: 1 addition & 1 deletion contrib/aws/aws-sdk-go/aws/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package aws_test

Expand Down
2 changes: 1 addition & 1 deletion contrib/aws/aws-sdk-go/aws/option.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package aws

Expand Down
2 changes: 1 addition & 1 deletion contrib/bradfitz/gomemcache/memcache/example_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.
// Copyright 2016 Datadog, Inc.

package memcache_test

Expand Down

0 comments on commit caf0d63

Please sign in to comment.