Skip to content

Commit

Permalink
Merge branch 'main' into khanayan123/update-otel-env-metric-tag-names
Browse files Browse the repository at this point in the history
  • Loading branch information
khanayan123 authored Jun 27, 2024
2 parents 04e1195 + 27d60de commit 0ab5295
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 170 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/appsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
strategy:
matrix:
runs-on: [ macos-12, macos-14 ] # oldest and newest macos runners available - macos-14 mainly is here to cover the fact it is an ARM machine
go-version: [ "1.22", "1.21", "1.20" ]
go-version: [ "1.22", "1.21" ]
fail-fast: true # saving some CI time - macos runners too long to get
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -124,9 +124,6 @@ jobs:
run: |
set -euxo pipefail
cgocheck="GOEXPERIMENT=cgocheck2"
if [[ "$(go version)" =~ go1.20 ]]; then
cgocheck="GODEBUG=cgocheck=2"
fi
for cgo in "0" "1"; do
for appsec_enabled_env in "" "DD_APPSEC_ENABLED=true" "DD_APPSEC_ENABLED=false"; do
for cgocheck_env in "" "$cgocheck"; do
Expand Down Expand Up @@ -190,14 +187,9 @@ jobs:
needs: go-mod-caching
strategy:
matrix:
go-version: [ "1.22", "1.21", "1.20" ]
distribution: [ bookworm, bullseye, buster, alpine ]
go-version: [ "1.22", "1.21" ]
distribution: [ bookworm, bullseye, alpine ]
platform: [ linux/amd64, linux/arm64 ]
exclude:
- go-version: "1.21"
distribution: buster
- go-version: "1.22"
distribution: buster

fail-fast: false
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main-branch-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
unit-integration-tests:
strategy:
matrix:
go-version: ["1.20", "1.21", "1.22"]
go-version: [ "1.21", "1.22" ]
fail-fast: false
uses: ./.github/workflows/unit-integration-tests.yml
with:
Expand All @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
runs-on: [ macos-latest, windows-latest, ubuntu-latest ]
go-version: ["1.20", "1.21", "1.22"]
go-version: [ "1.21", "1.22" ]
fail-fast: false
uses: ./.github/workflows/multios-unit-tests.yml
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multios-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ env:

jobs:
test-multi-os:
runs-on: "${{ (inputs.go-version == '1.20' && inputs.runs-on == 'windows-latest') && 'windows-2019' || inputs.runs-on }}"
runs-on: "${{ inputs.runs-on }}"
env:
REPORT: gotestsum-report.xml # path to where test results will be saved
DD_APPSEC_WAF_TIMEOUT: 1h
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/parametric-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.20"
go-version: "oldstable"

- name: Build runner
uses: ./.github/actions/install_runner
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
name: PR Unit and Integration Tests
uses: ./.github/workflows/unit-integration-tests.yml
with:
go-version: "1.20"
go-version: "1.21"
ref: ${{ github.ref }}
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-go@v3
with:
go-version: "stable"
go-version: "1.21"
cache: true
- name: go mod tidy
run: |-
Expand All @@ -99,7 +99,7 @@ jobs:
matrix:
# TODO: cross-compilation from/to different hardware architectures once
# github provides native ARM runners.
go: [ "1.20", "1.21", "1.22" ]
go: [ "1.21", "1.22" ]
build-env: [ alpine, bookworm, bullseye ]
build-with-cgo: [ 0, 1 ]
deployment-env: [ alpine, debian11, debian12, al2, al2023, busybox, scratch ]
Expand Down
38 changes: 14 additions & 24 deletions .gitlab/macrobenchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ variables:
GO_PROF_APP_BUILD_VARIANT: "candidate"
DD_TRACE_GO_VERSION: "latest"

LOAD_TESTS: io-bound,cpu-bound,cgo-cpu-bound,cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

# Workaround: Currently we're not running the benchmarks on every PR, but GitHub still shows them as pending.
# By marking the benchmarks as allow_failure, this should go away. (This workaround should be removed once the
# benchmarks get changed to run on every PR)
allow_failure: true

go122-baseline:
extends: .benchmarks
variables:
Expand All @@ -44,8 +47,7 @@ go122-baseline:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-only-trace:
extends: .benchmarks
variables:
Expand All @@ -55,8 +57,7 @@ go122-only-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-only-profile:
extends: .benchmarks
variables:
Expand All @@ -66,8 +67,7 @@ go122-only-profile:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-profile-trace:
extends: .benchmarks
variables:
Expand All @@ -77,8 +77,7 @@ go122-profile-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -88,8 +87,7 @@ go122-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go122-profile-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -99,8 +97,7 @@ go122-profile-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.22.1"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-baseline:
extends: .benchmarks
variables:
Expand All @@ -110,8 +107,7 @@ go120-baseline:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-only-trace:
extends: .benchmarks
variables:
Expand All @@ -121,8 +117,7 @@ go120-only-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-only-profile:
extends: .benchmarks
variables:
Expand All @@ -132,8 +127,7 @@ go120-only-profile:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-profile-trace:
extends: .benchmarks
variables:
Expand All @@ -143,8 +137,7 @@ go120-profile-trace:
ENABLE_APPSEC: "false"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -154,8 +147,7 @@ go120-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"

go120-profile-trace-asm:
extends: .benchmarks
variables:
Expand All @@ -165,5 +157,3 @@ go120-profile-trace-asm:
ENABLE_APPSEC: "true"
DD_PROFILING_EXECUTION_TRACE_ENABLED: "false"
GO_VERSION: "1.20.14"
LOAD_TESTS: normal_operation_io-bound,high_load_io-bound|normal_operation_cpu-bound,high_load_cpu-bound|normal_operation_cgo-cpu-bound,high_load_cgo-cpu-bound|normal_operation_cpu-bound-x-client-ip-enabled,high_load_cpu-bound-x-client-ip-enabled
PARALLELIZE: "true"
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,9 @@ If you installed more packages than you intended, you can use `go mod tidy` to r
- [Application Security Monitoring](https://docs.datadoghq.com/security_platform/application_security/setup_and_configure/?code-lang=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
### Go 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. Not guaranteed to compile the latest version of dd-trace-go. [Contact our customer support team for special requests.](https://www.datadoghq.com/support/) |

### Supported Versions
<!-- NOTE: When updating the below section ensure you update the minimum supported version listed in the public docs here: https://docs.datadoghq.com/tracing/setup_overview/setup/go/?tab=containers#compatibility-requirements -->
| **Go Version** | **Support level** |
|----------------|-------------------------------------|
| 1.22 | [GA](#support-ga) |
| 1.21 | [GA](#support-ga) |
| 1.20 | [Maintenance](#support-maintenance) |

* Datadog's Trace Agent >= 5.21.1


#### 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:

| Go Version | Support |
|------------|-------------------------------------|
| 1.19 | [GA](#support-ga) |
| 1.18 | [GA](#support-ga) |
| 1.17 | [Maintenance](#support-maintenance) |
| 1.16 | [Legacy](#support-legacy) |
Datadog APM for Go is built upon dependencies defined in specific versions of the host operating system, Go releases, and the Datadog Agent/API. dd-trace-go supports the two latest releases of Go, matching the [official Go policy](https://go.dev/doc/devel/release#policy). This library only officially supports [first class ports](https://go.dev/wiki/PortingPolicy) of Go.

### Contributing

Expand Down
23 changes: 20 additions & 3 deletions contrib/99designs/gqlgen/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
const defaultServiceName = "graphql"

type config struct {
serviceName string
analyticsRate float64
tags map[string]interface{}
serviceName string
analyticsRate float64
withoutTraceIntrospectionQuery bool
withoutTraceTrivialResolvedFields bool
tags map[string]interface{}
}

// An Option configures the gqlgen integration.
Expand Down Expand Up @@ -51,6 +53,21 @@ func WithServiceName(name string) Option {
}
}

// WithoutTraceIntrospectionQuery skips creating spans for fields when the operation name is IntrospectionQuery.
func WithoutTraceIntrospectionQuery() Option {
return func(cfg *config) {
cfg.withoutTraceIntrospectionQuery = true
}
}

// WithoutTraceTrivialResolvedFields skips creating spans for fields that have a trivial resolver.
// For example, a field resolved from an object w/o requiring a custom method is considered trivial.
func WithoutTraceTrivialResolvedFields() Option {
return func(cfg *config) {
cfg.withoutTraceTrivialResolvedFields = true
}
}

// WithCustomTag will attach the value to the span tagged by the key.
func WithCustomTag(key string, value interface{}) Option {
return func(cfg *config) {
Expand Down
16 changes: 15 additions & 1 deletion contrib/99designs/gqlgen/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,18 @@ func (t *gqlTracer) InterceptOperation(ctx context.Context, next graphql.Operati

func (t *gqlTracer) InterceptField(ctx context.Context, next graphql.Resolver) (res any, err error) {
opCtx := graphql.GetOperationContext(ctx)
if t.cfg.withoutTraceIntrospectionQuery && opCtx.OperationName == "IntrospectionQuery" {
res, err = next(ctx)
return
}

fieldCtx := graphql.GetFieldContext(ctx)
isTrivial := !(fieldCtx.IsMethod || fieldCtx.IsResolver)
if t.cfg.withoutTraceTrivialResolvedFields && isTrivial {
res, err = next(ctx)
return
}

opts := make([]tracer.StartSpanOption, 0, 6+len(t.cfg.tags))
for k, v := range t.cfg.tags {
opts = append(opts, tracer.Tag(k, v))
Expand All @@ -153,15 +164,18 @@ func (t *gqlTracer) InterceptField(ctx context.Context, next graphql.Resolver) (
if !math.IsNaN(t.cfg.analyticsRate) {
opts = append(opts, tracer.Tag(ext.EventSampleRate, t.cfg.analyticsRate))
}

span, ctx := tracer.StartSpanFromContext(ctx, fieldOp, opts...)
defer func() { span.Finish(tracer.WithError(err)) }()

ctx, op := graphqlsec.StartResolveOperation(ctx, graphqlsec.FromContext[*types.ExecutionOperation](ctx), span, types.ResolveOperationArgs{
Arguments: fieldCtx.Args,
TypeName: fieldCtx.Object,
FieldName: fieldCtx.Field.Name,
Trivial: !(fieldCtx.IsMethod || fieldCtx.IsResolver), // TODO: Is this accurate?
Trivial: isTrivial,
})
defer func() { op.Finish(types.ResolveOperationRes{Data: res, Error: err}) }()

res, err = next(ctx)
return
}
Expand Down
Loading

0 comments on commit 0ab5295

Please sign in to comment.