Skip to content

Commit

Permalink
Merge branch 'v1' into alex.normand/sql-commenter-proof-of-concept
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-normand committed May 5, 2022
2 parents 00c4644 + 1c53df5 commit 137c3dd
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 214 deletions.
55 changes: 7 additions & 48 deletions .circleci/config.yml
@@ -1,48 +1,15 @@
version: 2.1

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

jobs:
go1_12-build:
# Validate that the core builds with go1.12
parameters:
build_tags:
description: "go build tags used to compile"
default: ""
type: string
goflags:
description: "extra goflags to pass to go test"
default: ""
type: string
docker:
- image: circleci/golang:1.12
environment:
GOPATH: "/home/circleci/go"
working_directory: /home/circleci/dd-trace-go.v1
environment:
# Go 1.12 doesn't have the proxy turned on by default but we need it to
# fetch some dependencies that aren't handled by fetching directly
# (such as github.com/go-chi/chi/v4@v4.0.0-rc1)
GOPROXY: "https://proxy.golang.org"
steps:
- checkout

- run:
name: build
command: |
# Fixes fatal: unable to access 'https://gopkg.in/yaml.v3/': server certificate verification failed. CAfile: none CRLfile: none
# See https://github.com/DataDog/dd-trace-go/pull/1029
sudo apt update && sudo apt install ca-certificates libgnutls30 -y
go build -v -tags "<< parameters.build_tags >>" ./ddtrace/... ./profiler/... ./internal/appsec/...
metadata:
<<: *plain-go114
<<: *plain-go116

steps:
- checkout
Expand Down Expand Up @@ -79,7 +46,7 @@ jobs:
go run checkcopyright.go
lint:
<<: *plain-go114
<<: *plain-go116

steps:
- checkout
Expand Down Expand Up @@ -123,7 +90,7 @@ jobs:
environment: # environment variables for the build itself
TEST_RESULTS: /tmp/test-results # path to where test results will be saved
DD_APPSEC_WAF_TIMEOUT: 1s
<<: *plain-go114
<<: *plain-go116

steps:
- checkout
Expand Down Expand Up @@ -171,7 +138,7 @@ jobs:
DD_APPSEC_WAF_TIMEOUT: 1s
working_directory: /home/circleci/dd-trace-go.v1
docker:
- image: circleci/golang:1.14
- image: circleci/golang:1.16
environment:
GOPATH: "/home/circleci/go"
- image: cassandra:3.7
Expand Down Expand Up @@ -334,6 +301,7 @@ jobs:
name: Testing outlier google.golang.org/api
command: |
go get google.golang.org/grpc@v1.29.0 # https://github.com/grpc/grpc-go/issues/3726
go mod tidy # Go1.16 doesn't update the sum file correctly after the go get, this tidy fixes it
go test -v ./contrib/google.golang.org/api/...
- run:
Expand Down Expand Up @@ -368,10 +336,6 @@ workflows:
version: 2
build-and-test:
jobs:
- go1_12-build:
matrix:
parameters:
build_tags: [ "", "appsec" ]
- metadata
- lint
- test-core:
Expand All @@ -391,11 +355,6 @@ workflows:
only:
- v1
jobs:
- go1_12-build:
matrix:
parameters:
build_tags: [ "", "appsec" ]
goflags: [ "-race" ]
- test-core:
matrix:
parameters:
Expand Down
47 changes: 43 additions & 4 deletions README.md
Expand Up @@ -19,14 +19,53 @@ go get gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux

If you installed more packages than you intended, you can use `go mod tidy` to remove any unused packages.

Requires:
### Documentation

- [API](https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1/ddtrace)
- [Tracing Go Applications](https://docs.datadoghq.com/tracing/setup/go/)
- [Continuous Go Profiler](https://docs.datadoghq.com/tracing/profiler/enabling/go).
- If you are migrating from an older version of the tracer (e.g. 0.6.x) you may also find the [migration document](MIGRATING.md) we've put together helpful.

### Support Policy

Datadog APM for Go is built upon dependencies defined in specific versions of the host operating system, Go releases, and the Datadog Agent/API. For Go the two latest releases are [GA](#support-ga) supported and the version before that is in [Maintenance](#support-maintenance). We do make efforts to support older releases, but generally these releases are considered [Legacy](#support-legacy). This library only officially supports [first class ports](https://github.com/golang/go/wiki/PortingPolicy#first-class-ports) of Go.

| **Level** | **Support provided** |
|--------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <span id="support-ga">General Availability (GA)</span> | Full implementation of all features. Full support for new features, bug & security fixes. |
| <span id="support-maintenance">Maintenance</span> | Full implementation of existing features. May receive new features. Support for bug & security fixes only. |
| <span id="support-legacy">Legacy</span> | Legacy implementation. May have limited function, but no maintenance provided. [Contact our customer support team for special requests.](https://www.datadoghq.com/support/) |

### Supported Versions

| **Go Version** | **Support level** |
|----------------|-------------------------------------|
| 1.18 | [GA](#support-ga) |
| 1.17 | [GA](#support-ga) |
| 1.16 | [Maintenance](#support-maintenance) |

* Go >= 1.12
* Datadog's Trace Agent >= 5.21.1

### Documentation
#### Package Versioning

A **Minor** version change will be released whenever a new version of Go is released. At that time the newest version of Go is added to [GA](#support-ga), the second oldest supported version moved to [Maintenance](#support-maintenance) and the oldest previously supported version dropped to [Legacy](#support-legacy).
**For example**:
For a dd-trace-go version 1.37.*

| Go Version | Support |
|------------|-------------------------------------|
| 1.18 | [GA](#support-ga) |
| 1.17 | [GA](#support-ga) |
| 1.16 | [Maintenance](#support-maintenance) |

Then after Go 1.19 is released there will be a new dd-trace-go version 1.38.0 with support:

The API is documented on [godoc](https://godoc.org/gopkg.in/DataDog/dd-trace-go.v1/ddtrace) as well as Datadog's official documentation for [Tracing Go Applications](https://docs.datadoghq.com/tracing/setup/go/) and the [Continuous Go Profiler](https://docs.datadoghq.com/tracing/profiler/enabling/go). If you are migrating from an older version of the tracer (e.g. 0.6.x) you may also find the [migration document](MIGRATING.md) we've put together helpful.
| Go Version | Support |
|------------|-------------------------------------|
| 1.19 | [GA](#support-ga) |
| 1.18 | [GA](#support-ga) |
| 1.17 | [Maintenance](#support-maintenance) |
| 1.16 | [Legacy](#support-legacy) |

### Contributing

Expand Down
34 changes: 34 additions & 0 deletions contrib/sirupsen/logrus/example_test.go
@@ -0,0 +1,34 @@
// 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 2022 Datadog, Inc.

package logrus

import (
"context"
"os"
"time"

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

"github.com/sirupsen/logrus"
)

func ExampleHook() {
// Ensure your tracer is started and stopped
// Setup logrus, do this once at the beginning of your program
logrus.SetFormatter(&logrus.JSONFormatter{})
logrus.AddHook(&DDContextLogHook{})
logrus.SetOutput(os.Stdout)

span, sctx := tracer.StartSpanFromContext(context.Background(), "mySpan")
defer span.Finish()

// Pass the current span context to the logger (Time is set for consistency in output here)
cLog := logrus.WithContext(sctx).WithTime(time.Date(2000, 1, 1, 1, 1, 1, 0, time.UTC))
// Log as desired using the context-aware logger
cLog.Info("Completed some work!")
// Output:
// {"dd.span_id":0,"dd.trace_id":0,"level":"info","msg":"Completed some work!","time":"2000-01-01T01:01:01Z"}
}
32 changes: 32 additions & 0 deletions contrib/sirupsen/logrus/logrus.go
@@ -0,0 +1,32 @@
// 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 2022 Datadog, Inc.

// Package logrus provides a log/span correlation hook for the sirupsen/logrus package (https://github.com/sirupsen/logrus).
package logrus

import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"github.com/sirupsen/logrus"
)

// DDContextLogHook ensures that any span in the log context is correlated to log output.
type DDContextLogHook struct{}

// Levels implements logrus.Hook interface, this hook applies to all defined levels
func (d *DDContextLogHook) Levels() []logrus.Level {
return []logrus.Level{logrus.PanicLevel, logrus.FatalLevel, logrus.ErrorLevel, logrus.WarnLevel, logrus.InfoLevel, logrus.DebugLevel, logrus.TraceLevel}
}

// Fire implements logrus.Hook interface, attaches trace and span details found in entry context
func (d *DDContextLogHook) Fire(e *logrus.Entry) error {
span, found := tracer.SpanFromContext(e.Context)
if !found {
return nil
}
e.Data["dd.trace_id"] = span.Context().TraceID()
e.Data["dd.span_id"] = span.Context().SpanID()
return nil
}
31 changes: 31 additions & 0 deletions contrib/sirupsen/logrus/logrus_test.go
@@ -0,0 +1,31 @@
// 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 2022 Datadog, Inc.

package logrus

import (
"context"
"testing"

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

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func TestFire(t *testing.T) {
tracer.Start()
defer tracer.Stop()
_, sctx := tracer.StartSpanFromContext(context.Background(), "testSpan", tracer.WithSpanID(1234))

hook := &DDContextLogHook{}
e := logrus.NewEntry(logrus.New())
e.Context = sctx
err := hook.Fire(e)

assert.NoError(t, err)
assert.Equal(t, uint64(1234), e.Data["dd.trace_id"])
assert.Equal(t, uint64(1234), e.Data["dd.span_id"])
}
9 changes: 9 additions & 0 deletions ddtrace/tracer/tracer.go
Expand Up @@ -9,6 +9,7 @@ import (
gocontext "context"
"os"
"runtime/pprof"
rt "runtime/trace"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -544,3 +545,11 @@ func (t *tracer) sample(span *span) {
}
t.prioritySampling.apply(span)
}

func startExecutionTracerTask(name string) func() {
if !rt.IsEnabled() {
return func() {}
}
_, task := rt.NewTask(gocontext.TODO(), name)
return task.End
}
21 changes: 0 additions & 21 deletions ddtrace/tracer/tracer_go11.go

This file was deleted.

12 changes: 0 additions & 12 deletions ddtrace/tracer/tracer_nongo11.go

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
@@ -1,6 +1,6 @@
module gopkg.in/DataDog/dd-trace-go.v1

go 1.12
go 1.16

require (
cloud.google.com/go/pubsub v1.4.0
Expand Down Expand Up @@ -74,7 +74,7 @@ require (
github.com/philhofer/fwd v1.1.1 // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/segmentio/kafka-go v0.4.29
github.com/stretchr/objx v0.2.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/btree v1.1.0 // indirect
Expand Down

0 comments on commit 137c3dd

Please sign in to comment.