Skip to content

Commit 2ee9460

Browse files
authored
Merge branch 'main' into push-ulqypuyoyylv
2 parents 4084af3 + 466aad1 commit 2ee9460

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2398
-397
lines changed

.github/workflows/all-green.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ jobs:
2121
with:
2222
initial-delay-seconds: "1000" # smoke tests takes approx 20 mn to finish
2323
max-retries: "60"
24+
ignored-name-patterns: |
25+
devflow/merge
26+
27+
# Reason for ignored-name-patterns:
28+
#
29+
# * devflow/merge: technical job used by the merge queue, do not remove it.

MIGRATING.md

Lines changed: 140 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
This document outlines migrating from an older version of the Datadog tracer (v1.x.x) to v2.
44

5-
Datadog's v2 version of the Go tracer provides a huge refactor of our API, moving away from interfaces to provide flexibility in future works, isolating our integrations to prevent false-positives from security scanners, and enforcing proper library patterns to prevent misuse. This update is the result of continuous feedback from customers, the community, as well as our extensive internal usage.
5+
Datadog's v2 version of the Go tracer provides a significant refactor of our API, moving away from interfaces to provide flexibility in future works, isolating our integrations to prevent false-positives from security scanners, and enforcing proper library patterns to prevent misuse. This update is the result of continuous feedback from customers, the community, as well as our extensive internal usage, introducing better maintainability, simplified APIs, and unlocking performance benefits.
66

77
As is common and recommended in the Go community, the best way to approach migrating to this new API is by using the [gradual code repair](https://talks.golang.org/2016/refactor.article) method. We have done the same internally and it has worked just great! For this exact reason we have provided a new, [semver](https://semver.org/) friendly import path to help with using both tracers in parallel, without conflict, for the duration of the migration. This new path is `github.com/DataDog/dd-trace-go/v2`.
88

99
We have also provided a new migration tool to help with the most essential changes made in v2, which you can read about [here](./tools/v2fix/README.md).
1010

11-
Our [godoc page](https://godoc.org/github.com/DataDog/dd-trace-go/v2/ddtrace) should deem helpful during this process. We also have the [official documentation](https://docs.datadoghq.com/tracing/setup/go/), which contains a couple of examples.
11+
Our [godoc page](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace) should be helpful during this process. We also have the [official documentation](https://docs.datadoghq.com/tracing/setup/go/), which contains a couple of examples.
1212

1313
This document will further outline some _before_ and _after_ examples.
1414

@@ -28,7 +28,7 @@ import "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
2828

2929
It is important to note that when using our contrib libraries, import URLs may be impacted differently. This will be covered in the next section:
3030

31-
## Independent Contrib Packages
31+
### Independent Contrib Packages
3232

3333
This version upgrade comes with a large overhaul of what was previously one single package that held all of our integrations. In v2, we introduce independent packages for each of our contribs, which will prevent false-positives in security scanners that were caused by indirect dependencies. As a result, importing contribs will also change. Before:
3434

@@ -59,18 +59,48 @@ var sp *tracer.Span = tracer.StartSpan("opname")
5959
var ctx *tracer.SpanContext = sp.Context()
6060
```
6161

62-
## WithService()
62+
### Deprecated ddtrace interfaces
6363

64-
The previously deprecated `tracer.WithServiceName()` has been fully removed and replaced with the method `tracer.WithService()`. If you would like to specify a service name upon starting the tracer, you would have before:
64+
All the interfaces in `ddtrace` have been removed in favor of struct types, except for `SpanContext`. The new types have moved into `ddtrace/tracer`.
65+
66+
### Deprecated constants and options
67+
68+
The following constants and functions have been removed:
69+
70+
* `ddtrace/ext.AppTypeWeb`
71+
* `ddtrace/ext.CassandraQuery`
72+
* `ddtrace/ext.CassandraBatch`
73+
* `ddtrace/tracer.WithPrioritySampling`; priority sampling is enabled by default.
74+
* `ddtrace/tracer.WithHTTPRoundTripper`; use `WithHTTPClient` instead.
75+
76+
### StartChild
77+
78+
Child spans can be started with StartChild rather than ChildOf. Before:
6579

6680
```go
67-
tracer.Start(tracer.WithServiceName("service"))
81+
import "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
82+
83+
func main() {
84+
tracer.Start()
85+
defer tracer.Stop()
86+
87+
parent := tracer.StartSpan("op").Context()
88+
child := tracer.StartSpan("op", tracer.ChildOf(parent))
89+
}
6890
```
6991

70-
After:
92+
Becomes:
7193

7294
```go
73-
tracer.Start(tracer.WithService("service"))
95+
import "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"
96+
97+
func main() {
98+
tracer.Start()
99+
defer tracer.Stop()
100+
101+
parent := tracer.StartSpan("op")
102+
child := parent.StartChild("op")
103+
}
74104
```
75105

76106
## Trace IDs
@@ -90,9 +120,108 @@ fmt.Printf("traceID: %s\n", sp.Context().TraceID()) //recommended for using 128-
90120
fmt.Printf("traceID: %d\n", sp.Context().TraceIDLower()) // for maintaining old behavior with 64-bit IDs
91121
```
92122

93-
## Further reading
123+
## Span Links API
124+
125+
`Span.AddSpanLink` has been renamed to `Span.AddLink`.
126+
127+
## WithService
128+
129+
The previously deprecated `tracer.WithServiceName()` has been fully removed and replaced with the method `tracer.WithService()`. If you would like to specify a service name upon starting the tracer, you would have before:
130+
131+
```go
132+
tracer.Start(tracer.WithServiceName("service"))
133+
```
134+
135+
After:
136+
137+
```go
138+
tracer.Start(tracer.WithService("service"))
139+
```
140+
141+
## NewStartSpanConfig, WithStartSpanConfig & WithFinishConfig
142+
143+
These functional options for `ddtrace/tracer.Tracer.StartSpan` and `ddtrace/tracer.Span.Finish` reduces the number of calls (in functional option form) in hot loops by giving the freedom to prepare a common span configuration in hot paths.
144+
145+
Before:
146+
147+
```go
148+
var err error
149+
span := tracer.StartSpan(
150+
"operation",
151+
ChildOf(parent.Context()),
152+
Measured(),
153+
ResourceName("resource"),
154+
ServiceName(service),
155+
SpanType(ext.SpanTypeWeb),
156+
Tag("key", "value"),
157+
)
158+
defer span.Finish(tracer.NoDebugStack())
159+
```
160+
161+
After:
162+
163+
```go
164+
cfg := tracer.NewStartSpanConfig(
165+
tracer.ChildOf(parent.Context()),
166+
tracer.Measured(),
167+
tracer.ResourceName("resource"),
168+
tracer.ServiceName(service),
169+
tracer.SpanType(ext.SpanTypeWeb),
170+
tracer.Tag("key", "value"),
171+
)
172+
finishCfg := &FinishConfig{
173+
NoDebugStack: true,
174+
}
175+
// [...]
176+
// Reuse the configuration in your hot path:
177+
span := tracer.StartSpan("operation", tracer.WithStartSpanConfig(cfg))
178+
defer span.Finish(tracer.WithFinishConfig(finishCfg))
179+
```
180+
181+
## Sampling API simplified
182+
183+
The following functions have been removed in favour of `SpanSamplingRules` and `TraceSamplingRules`:
184+
185+
* `NameRule`
186+
* `NameServiceRule`
187+
* `RateRule`
188+
* `ServiceRule`
189+
* `SpanNameServiceMPSRule`
190+
* `SpanNameServiceRule`
191+
* `SpanTagsResourceRule`
192+
* `TagsResourceRule`
193+
194+
Also, `ext.SamplingPriority` tag is deprecated. Use `ext.ManualKeep` and `ext.ManualDrop` instead.
195+
196+
## Contrib API
197+
198+
A support package to create contribs without depending on internal packages is available in `instrumentation`. Please refer to [`instrumentation` godoc page](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/instrumentation) and existing contribs for more detail.
199+
200+
## Updated User Monitoring SDK for Appsec
201+
202+
`appsec` package offers a new API for user monitoring; essentially deprecating login success & failure event functions, replacing them with versions that accept a `login` field, which is to be used by user monitoring rules (ATO monitoring & protection). Before:
203+
204+
```go
205+
appsec.TrackUserLoginSuccessEvent(...)
206+
appsec.TrackUserLoginFailureEvent(...)
207+
```
208+
209+
Becomes:
210+
211+
```go
212+
appsec.TrackUserLoginSuccess(...)
213+
appsec.TrackUserLoginFailure(...)
214+
```
215+
216+
## API Security sampling
217+
218+
The API Security sampler now takes decisions specific to a given endpoint (method + route + response status code) instead of using a simplistic sampling rate. This allows for improved coverage and accuracy of schema extraction as part of API Security.
219+
220+
## Opentracing deprecation
221+
222+
`opentracer` is in "Maintenance" mode and limited support was offered in `v1`. We recommend to use OpenTelemetry or ddtrace/tracer directly. For additional details, please see our [Support Policy](https://github.com/DataDog/dd-trace-go?tab=readme-ov-file#go-support-policy).
94223

95-
The new version of the tracer also comes with a lot of new features, such as support for distributed tracing and distributed sampling priority.
224+
## Further reading
96225

97-
* package level documentation of the [`tracer` package](https://godoc.org/github.com/DataDog/dd-trace-go/v2/ddtrace/tracer) for a better overview.
226+
* package level documentation of the [`tracer` package](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace/tracer) for a better overview.
98227
* [official documentation](https://docs.datadoghq.com/tracing/setup/go/)

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Supported Versions
44

5-
Please see our [Support Policy](README.md#support-policy)
5+
Please see our [Support Policy](README.md#go-support-policy)
66

77
## Reporting a Vulnerability
88

contrib/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/DataDog/dd-trace-go/v2/contrib)
1+
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/contrib)
22

33
The purpose of these packages is to provide tracing on top of commonly used packages from the standard library as well as the
44
community in a "plug-and-play" manner. This means that by simply importing the appropriate path, functions are exposed having
@@ -34,7 +34,7 @@ Third, some guidelines to follow on naming functions:
3434

3535
* Use `WithService` instead of `WithServiceName` when setting the service name.
3636

37-
Each integration comes with a thorough documentation and usage examples. A good overview can be seen on our [godoc](https://godoc.org/github.com/DataDog/dd-trace-go/v2/contrib) page.
37+
Each integration comes with a thorough documentation and usage examples. A good overview can be seen on our [godoc](https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/contrib) page.
3838

3939
### Instrumentation telemetry
4040

contrib/gomodule/redigo/redigo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func withSpan(ctx context.Context, do func(commandName string, args ...interface
190190
span.SetTag(ext.ResourceName, commandName)
191191
} else {
192192
// When the command argument to the Do method is "", then the Do method will flush the output buffer
193-
// See https://godoc.org/github.com/gomodule/redigo/redis#hdr-Pipelining
193+
// See https://pkg.go.dev/github.com/gomodule/redigo/redis#hdr-Pipelining
194194
span.SetTag(ext.ResourceName, "redigo.Conn.Flush")
195195
}
196196
var b bytes.Buffer

contrib/graph-gophers/graphql-go/graphql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Package graphql provides functions to trace the graph-gophers/graphql-go package (https://github.com/graph-gophers/graphql-go).
77
//
88
// We use the tracing mechanism available in the
9-
// https://godoc.org/github.com/graph-gophers/graphql-go/trace subpackage.
9+
// https://pkg.go.dev/github.com/graph-gophers/graphql-go/trace subpackage.
1010
// Create a new Tracer with `NewTracer` and pass it as an additional option to
1111
// `MustParseSchema`.
1212
package graphql // import "github.com/DataDog/dd-trace-go/contrib/graph-gophers/graphql-go/v2"

ddtrace/ddtrace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Additionally, package "ext" provides a set of tag names and values specific to Datadog's APM product.
1010
//
1111
// To get started, visit the documentation for any of the packages you'd like to begin
12-
// with by accessing the subdirectories of this package: https://godoc.org/github.com/DataDog/dd-trace-go/v2/ddtrace#pkg-subdirectories.
12+
// with by accessing the subdirectories of this package: https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/ddtrace#pkg-subdirectories.
1313
package ddtrace // import "github.com/DataDog/dd-trace-go/v2/ddtrace"
1414

1515
// SpanContext represents a span state that can propagate to descendant spans

ddtrace/mocktracer/civisibilitymocktracer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ func (t *civisibilitymocktracer) TracerConf() tracer.TracerConf {
168168
func (t *civisibilitymocktracer) Submit(span *tracer.Span) {
169169
t.mock.Submit(span)
170170
}
171-
func (t *civisibilitymocktracer) SubmitChunk(chunk *tracer.Chunk) {
172-
t.real.SubmitChunk(chunk)
171+
func (t *civisibilitymocktracer) SubmitChunk(ch *tracer.Chunk) {
172+
if mtr, ok := t.real.(interface{ SubmitChunk(*tracer.Chunk) }); ok {
173+
mtr.SubmitChunk(ch)
174+
}
173175
}
174176

175177
// Flush forces a flush of both the mock tracer and the real tracer.

ddtrace/tracer/api.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,6 @@ type TextMapCarrier map[string]string
365365
func Extract(interface{}) (*SpanContext, error)
366366
func Flush()
367367
func Inject(*SpanContext, interface{}) (error)
368-
func NewChunk([]*Span, bool) (*Chunk)
369-
func NewUnstartedTracer(...StartOption) (Tracer, error)
370368
func SetUser(*Span, string, ...UserMonitoringOption)
371369
func Start(...StartOption) (error)
372370
func StartSpan(string, ...StartSpanOption) (*Span)
@@ -381,8 +379,6 @@ type Tracer interface {
381379
func Inject(*SpanContext, interface{}) (error)
382380
func StartSpan(string, ...StartSpanOption) (*Span)
383381
func Stop()
384-
func Submit(*Span)
385-
func SubmitChunk(*Chunk)
386382
func TracerConf() (TracerConf)
387383
}
388384

ddtrace/tracer/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,5 @@
106106
//
107107
// Some libraries and frameworks are supported out-of-the-box by using one
108108
// of our integrations. You can see a list of supported integrations here:
109-
// https://godoc.org/github.com/DataDog/dd-trace-go/v2/contrib
109+
// https://pkg.go.dev/github.com/DataDog/dd-trace-go/v2/contrib
110110
package tracer // import "github.com/DataDog/dd-trace-go/v2/ddtrace/tracer"

ddtrace/tracer/log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type startupInfo struct {
6262
PropagationStyleExtract string `json:"propagation_style_extract"` // Propagation style for extract
6363
TracingAsTransport bool `json:"tracing_as_transport"` // Whether the tracer is disabled and other products are using it as a transport
6464
DogstatsdAddr string `json:"dogstatsd_address"` // Destination of statsd payloads
65+
DataStreamsEnabled bool `json:"data_streams_enabled"` // Whether Data Streams is enabled
6566
}
6667

6768
// checkEndpoint tries to connect to the URL specified by endpoint.
@@ -114,7 +115,6 @@ func logStartup(t *tracer) {
114115
} else {
115116
agentURL = t.config.transport.endpoint()
116117
}
117-
118118
info := startupInfo{
119119
Date: time.Now().Format(time.RFC3339),
120120
OSName: osinfo.OSName(),
@@ -152,6 +152,7 @@ func logStartup(t *tracer) {
152152
PropagationStyleExtract: extractorNames,
153153
TracingAsTransport: t.config.tracingAsTransport,
154154
DogstatsdAddr: t.config.dogstatsdAddr,
155+
DataStreamsEnabled: t.config.dataStreamsMonitoringEnabled,
155156
}
156157
if _, _, err := samplingRulesFromEnv(); err != nil {
157158
info.SamplingRulesError = fmt.Sprintf("%s", err)

0 commit comments

Comments
 (0)