Skip to content

Commit

Permalink
Merge branch 'main' into shevchenko/sampling-by-metric-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
dianashevchenko authored Apr 18, 2024
2 parents cfb65e9 + af0486a commit 8908f62
Show file tree
Hide file tree
Showing 11 changed files with 1,350 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ jobs:
DD_APPSEC_WAF_TIMEOUT: 1h
run: go test $PACKAGES

go-mod-tidy:
# Run go mod tidy to ensure that all go.mod and go.sum files are up-to-date.
name: 'go mod tidy smoke test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-go@v3
with:
go-version: "stable"
cache: true
- name: go mod tidy
run: |-
find -name go.mod -execdir go mod tidy \;
git diff --exit-code
# TODO: macos setup requirements (xcode tools installation, etc.)
setup-requirements-linux:
# Build and deployment setup smoke test of linux containers built from the
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variables:
INDEX_FILE: index.txt
KUBERNETES_SERVICE_ACCOUNT_OVERWRITE: dd-trace-go
FF_USE_LEGACY_KUBERNETES_EXECUTION_STRATEGY: "true"
BENCHMARK_TARGETS: "BenchmarkStartRequestSpan|BenchmarkHttpServeTrace|BenchmarkTracerAddSpans|BenchmarkStartSpan|BenchmarkSingleSpanRetention|BenchmarkOTelApiWithCustomTags|BenchmarkInjectW3C|BenchmarkExtractW3C|BenchmarkPartialFlushing|BenchmarkGraphQL|BenchmarkSampleWAFContext"
BENCHMARK_TARGETS: "BenchmarkStartRequestSpan|BenchmarkHttpServeTrace|BenchmarkTracerAddSpans|BenchmarkStartSpan|BenchmarkSingleSpanRetention|BenchmarkOTelApiWithCustomTags|BenchmarkInjectW3C|BenchmarkExtractW3C|BenchmarkPartialFlushing|BenchmarkGraphQL|BenchmarkSampleWAFContext|BenchmarkCaptureStackTrace"

include:
- ".gitlab/benchmarks.yml"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require (
github.com/graphql-go/handler v0.2.3
github.com/hashicorp/consul/api v1.24.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7
github.com/hashicorp/vault/api v1.9.2
github.com/hashicorp/vault/sdk v0.9.2
github.com/jackc/pgx/v5 v5.5.4
Expand Down Expand Up @@ -180,7 +181,6 @@ require (
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
Expand Down
2 changes: 1 addition & 1 deletion internal/apps/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/apps/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo=
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
96 changes: 96 additions & 0 deletions internal/stacktrace/event.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// 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 Datadog, Inc.

//go:generate msgp -o event_msgp.go -tests=false

package stacktrace

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

"github.com/google/uuid"
"github.com/tinylib/msgp/msgp"
)

var _ msgp.Marshaler = (*Event)(nil)

type EventCategory string

const (
// ExceptionEvent is the event type for exception events
ExceptionEvent EventCategory = "exception"
// VulnerabilityEvent is the event type for vulnerability events
VulnerabilityEvent EventCategory = "vulnerability"
// ExploitEvent is the event type for exploit events
ExploitEvent EventCategory = "exploit"
)

// Event is the toplevel structure to contain a stacktrace and the additional information needed to correlate it with other data
type Event struct {
// Category is a well-known type of the event, not optional
Category EventCategory `msg:"-"`
// Type is a value event category specific, optional
Type string `msg:"type,omitempty"`
// Language is the language of the code that generated the event (set to "go" anyway here)
Language string `msg:"language,omitempty"`
// ID is the id of the event, optional for exceptions but mandatory for vulnerabilities and exploits to correlate with more data
ID string `msg:"id,omitempty"`
// Message is a generic message for the event
Message string `msg:"message,omitempty"`
// Frames is the stack trace of the event
Frames StackTrace `msg:"frames"`
}

// NewEvent creates a new stacktrace event with the given category, type and message
func NewEvent(eventCat EventCategory, eventType, message string) *Event {
return &Event{
Category: eventCat,
Type: eventType,
Language: "go",
Message: message,
Frames: SkipAndCapture(defaultCallerSkip),
}
}

// IDLink returns a UUID to link the stacktrace event with other data. NOT thread-safe
func (e *Event) IDLink() string {
if e.ID != "" {
newUUID, err := uuid.NewUUID()
if err != nil {
return ""
}

e.ID = newUUID.String()
}

return e.ID
}

// AddToSpan adds the event to the given span's root span as a tag if stacktrace collection is enabled
func AddToSpan(span ddtrace.Span, events ...*Event) {
if !Enabled() {
return
}

groupByCategory := map[EventCategory][]*Event{
ExceptionEvent: {},
VulnerabilityEvent: {},
ExploitEvent: {},
}

for _, event := range events {
groupByCategory[event.Category] = append(groupByCategory[event.Category], event)
}

type rooter interface {
Root() ddtrace.Span
}
if lrs, ok := span.(rooter); ok {
span = lrs.Root()
}

span.SetTag("_dd.stack", internal.MetaStructValue{Value: groupByCategory})
}
Loading

0 comments on commit 8908f62

Please sign in to comment.