Skip to content

Commit

Permalink
Merge branch 'main' into dario.castane/go-124-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio authored Dec 17, 2024
2 parents 0e76e64 + 5a8a82c commit 6d786ca
Show file tree
Hide file tree
Showing 66 changed files with 2,028 additions and 185 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/apps/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/DataDog/dd-trace-go/.github/workflows/apps

go 1.23.3

require (
github.com/Masterminds/semver/v3 v3.3.1
github.com/stretchr/testify v1.10.0
golang.org/x/mod v0.22.0
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 16 additions & 0 deletions .github/workflows/apps/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1 h1:ZIRxAKlr3xr6xbMUDs3IDa6xq+ISv9zxyjaDCfwDjMY=
gopkg.in/DataDog/dd-trace-go.v1 v1.70.1/go.mod h1:PMOSkeY4VfXiuPvGodeNLCZCFYU2VfOvjVI6cX5bGrc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
153 changes: 153 additions & 0 deletions .github/workflows/apps/latest_major_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// 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 2024 Datadog, Inc.

package main

import (
"encoding/json"
"fmt"
"sort"
"github.com/Masterminds/semver/v3"
"golang.org/x/mod/modfile"
"net/http"
"os"
"regexp"
"strings"
)

type Tag struct {
Name string
}

func getLatestMajorVersion(repo string) (string, error) {
// Get latest major version available for repo from github.
const apiURL = "https://api.github.com/repos/%s/tags"
url := fmt.Sprintf(apiURL, repo)

resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("failed to fetch tags: %s", resp.Status)
}

var tags []struct {
Name string `json:"name"`
}

if err := json.NewDecoder(resp.Body).Decode(&tags); err != nil {
return "", err
}
latestByMajor := make(map[int]*semver.Version)

for _, tag := range tags {
v, err := semver.NewVersion(tag.Name)
if err != nil {
continue // Skip invalid versions
}

if v.Prerelease() != "" {
continue // Ignore pre-release versions
}

major := int(v.Major())
if current, exists := latestByMajor[major]; !exists || v.GreaterThan(current) {
latestByMajor[major] = v
}
}

var latestMajor *semver.Version
for _, v := range latestByMajor {
if latestMajor == nil || v.Major() > latestMajor.Major() {
latestMajor = v
}
}

if latestMajor != nil {
return fmt.Sprintf("v%d", latestMajor.Major()), nil
}

return "", fmt.Errorf("no valid versions found")

}

func main() {

data, err := os.ReadFile("integration_go.mod")
if err != nil {
fmt.Println("Error reading integration_go.mod:", err)
return
}

modFile, err := modfile.Parse("integration_go.mod", data, nil)
if err != nil {
fmt.Println("Error parsing integration_go.mod:", err)
return
}

latestMajor := make(map[string]*semver.Version)

// Match on versions with /v{major}
versionRegex := regexp.MustCompile(`^(?P<module>.+?)/v(\d+)$`)

// Iterate over the required modules and update latest major version if necessary
for _, req := range modFile.Require {
module := req.Mod.Path

if match := versionRegex.FindStringSubmatch(module); match != nil {
url := match[1] // base module URL (e.g., github.com/foo)
majorVersionStr := "v" + match[2] // Create semantic version string (e.g., "v2")

moduleName := strings.TrimPrefix(strings.TrimSpace(url), "github.com/")

// Parse the semantic version
majorVersion, err := semver.NewVersion(majorVersionStr)
if err != nil {
fmt.Printf("Skip invalid version for module %s: %v\n", module, err)
continue
}

if existing, ok := latestMajor[moduleName]; !ok || majorVersion.GreaterThan(existing) {
latestMajor[moduleName] = majorVersion
}
}
}

// Output latest major version that we support.
// Check if a new major version in Github is available that we don't support.
// If so, output that a new latest is available.

// Sort the output
modules := make([]string, 0, len(latestMajor))
for module := range latestMajor {
modules = append(modules, module)
}
sort.Strings(modules)

for _, module := range modules {
major := latestMajor[module]

latestVersion, err := getLatestMajorVersion(module) // latest version available
if err != nil {
fmt.Printf("Error fetching latest version for module '%s': %v\n", module, err)
continue
}

latestVersionParsed, err := semver.NewVersion(latestVersion)
if err != nil {
fmt.Printf("Error parsing latest version '%s' for module '%s': %v\n", latestVersion, module, err)
continue
}

fmt.Printf("Latest DD major version of %s: %d\n", module, major.Major())
if major.LessThan(latestVersionParsed) {
fmt.Printf("New latest major version of %s available: %d\n", module, latestVersionParsed.Major())
}

}
}
3 changes: 3 additions & 0 deletions .github/workflows/appsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ on:
merge_group:
push:
branches: release-v*
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'

env:
DD_APPSEC_WAF_TIMEOUT: 1m
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
type: string
push:
branches: [ main, master ]
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:
push:
branches:
- main
- release-v*
- release-v*
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'
schedule:
- cron: '00 00 * * *'
workflow_dispatch:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/main-branch-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ on:
branches:
- main
- release-v*
tags:
- "**"
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'

concurrency:
group: ${{ github.ref }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/orchestrion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
push:
branches:
- release-v*
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'

permissions: read-all

Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/outdated-integrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Outdated Integrations
on:
schedule:
- cron: "0 0 * * 0" # Runs every Sunday at midnight UTC
workflow_dispatch:

concurrency:
# Automatically cancel previous runs if a new one is triggered to conserve resources.
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Find new major versions for the contrib package dependencies
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
pull-requests: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- run: go get github.com/Masterminds/semver/v3

- run: go run .github/workflows/apps/latest_major_version.go > latests.txt

- run: git diff

- name: Create Pull Request
id: pr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: "upgrade-latest-major-version"
commit-message: "Update latests file"
base: main
title: "chore: update latest majors"
labels: changelog/no-changelog
body: "Auto-generated PR from Outdated Integrations workflow to update latests major versions"
5 changes: 3 additions & 2 deletions .github/workflows/parametric-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ on:
branches:
- main
- release-v*
tags:
- "**"
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'
pull_request:
branches:
- "**"
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
push:
branches:
- 'mq-working-branch-**'
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'

concurrency:
group: ${{ github.ref }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ on:
branches:
- main
- release-v*
tags:
- '**'
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'
schedule: # nightly
- cron: "0 0 * * *"
workflow_dispatch: {} # manually
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/system-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ on:
branches:
- main
- release-v*
tags:
- "**"
tags-ignore:
- 'contrib/**'
- 'instrumentation/**'
pull_request:
branches:
- "**"
Expand Down
8 changes: 8 additions & 0 deletions contrib/IBM/sarama.v1/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
// kafka supports headers, so try to extract a span context
carrier := NewConsumerMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
next := tracer.StartSpan(cfg.consumerSpanName, opts...)
Expand Down Expand Up @@ -298,6 +302,10 @@ func startProducerSpan(cfg *config, version sarama.KafkaVersion, msg *sarama.Pro
}
// if there's a span context in the headers, use that as the parent
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span := tracer.StartSpan(cfg.producerSpanName, opts...)
Expand Down
8 changes: 8 additions & 0 deletions contrib/Shopify/sarama/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func WrapPartitionConsumer(pc sarama.PartitionConsumer, opts ...Option) sarama.P
// kafka supports headers, so try to extract a span context
carrier := NewConsumerMessageCarrier(msg)
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
next := tracer.StartSpan(cfg.consumerSpanName, opts...)
Expand Down Expand Up @@ -301,6 +305,10 @@ func startProducerSpan(cfg *config, version sarama.KafkaVersion, msg *sarama.Pro
}
// if there's a span context in the headers, use that as the parent
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span := tracer.StartSpan(cfg.producerSpanName, opts...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func TraceReceiveFunc(s Subscription, opts ...Option) func(ctx context.Context,
if cfg.measured {
opts = append(opts, tracer.Measured())
}
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := parentSpanCtx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
span, ctx := tracer.StartSpanFromContext(ctx, cfg.receiveSpanName, opts...)
if msg.DeliveryAttempt != nil {
span.SetTag("delivery_attempt", *msg.DeliveryAttempt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func (tr *KafkaTracer) StartConsumeSpan(msg Message) ddtrace.Span {
// kafka supports headers, so try to extract a span context
carrier := MessageCarrier{msg: msg}
if spanctx, err := tracer.Extract(carrier); err == nil {
// If there are span links as a result of context extraction, add them as a StartSpanOption
if linksCtx, ok := spanctx.(ddtrace.SpanContextWithLinks); ok && linksCtx.SpanLinks() != nil {
opts = append(opts, tracer.WithSpanLinks(linksCtx.SpanLinks()))
}
opts = append(opts, tracer.ChildOf(spanctx))
}
span, _ := tracer.StartSpanFromContext(tr.ctx, tr.consumerSpanName, opts...)
Expand Down
Loading

0 comments on commit 6d786ca

Please sign in to comment.