Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[golang] switch go weblog to orchestrion #3555

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
365 changes: 305 additions & 60 deletions utils/build/docker/golang/app/go.mod

Large diffs are not rendered by default.

1,389 changes: 1,235 additions & 154 deletions utils/build/docker/golang/app/go.sum

Large diffs are not rendered by default.

17 changes: 5 additions & 12 deletions utils/build/docker/golang/app/net-http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"github.com/Shopify/sarama"

saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama"
"gopkg.in/DataDog/dd-trace-go.v1/datastreams"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
Expand All @@ -34,17 +34,12 @@ import (
oteltrace "go.opentelemetry.io/otel/trace"

"gopkg.in/DataDog/dd-trace-go.v1/appsec"
httptrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/net/http"
ddotel "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentelemetry"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
ddtracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

func main() {
ddtracer.Start()
defer ddtracer.Stop()

mux := httptrace.NewServeMux()
mux := http.NewServeMux()

mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// "/" is the default route when the others don't match
Expand Down Expand Up @@ -154,9 +149,8 @@ func main() {
return
}

client := httptrace.WrapClient(http.DefaultClient)
req, _ := http.NewRequestWithContext(r.Context(), http.MethodGet, url, nil)
res, err := client.Do(req)
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalln("client.Do", err)
}
Expand Down Expand Up @@ -285,6 +279,7 @@ func main() {
appsec.TrackCustomEvent(r.Context(), name, map[string]string{"metadata0": "value0", "metadata1": "value1"})
})

//orchestrion:ignore
mux.HandleFunc("/e2e_otel_span", func(w http.ResponseWriter, r *http.Request) {
parentName := r.URL.Query().Get("parentName")
childName := r.URL.Query().Get("childName")
Expand Down Expand Up @@ -332,6 +327,7 @@ func main() {
w.Write([]byte("OK"))
})

//orchestrion:ignore
mux.HandleFunc("/e2e_otel_span/mixed_contrib", func(w http.ResponseWriter, r *http.Request) {
parentName := r.URL.Query().Get("parentName")

Expand Down Expand Up @@ -607,8 +603,6 @@ func kafkaProduce(topic, message string) (int32, int64, error) {
}
defer producer.Close()

producer = saramatrace.WrapSyncProducer(cfg, producer, saramatrace.WithDataStreams())

msg := &sarama.ProducerMessage{
Topic: topic,
Partition: 0,
Expand All @@ -634,7 +628,6 @@ func kafkaConsume(topic string, timeout int64) (string, int, error) {
}
defer consumer.Close()

consumer = saramatrace.WrapConsumer(consumer, saramatrace.WithDataStreams())
partitionConsumer, err := consumer.ConsumePartition(topic, 0, sarama.OffsetOldest)
if err != nil {
return "", 0, err
Expand Down
24 changes: 24 additions & 0 deletions utils/build/docker/golang/app/orchestrion.tool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file was created by `orchestrion pin`, and is used to ensure the
// `go.mod` file contains the necessary entries to ensure repeatable builds when
// using `orchestrion`. It is also used to set up which integrations are enabled.

//go:build tools

//go:generate go run github.com/DataDog/orchestrion pin

package tools

// Imports in this file determine which tracer intergations are enabled in
// orchestrion. New integrations can be automatically discovered by running
// `orchestrion pin` again. You can also manually add new imports here to
// enable additional integrations. When doing so, you can run `orchestrion pin`
// to make sure manually added integrations are valid (i.e, the imported package
// includes a valid `orchestrion.yml` file).
import (
// Ensures `orchestrion` is present in `go.mod` so that builds are repeatable.
// Do not remove.
_ "github.com/DataDog/orchestrion"
// Provides integrations for essential `orchestrion` features. Most users
// should not remove this integration.
_ "github.com/DataDog/orchestrion/instrument" // integration
)
4 changes: 1 addition & 3 deletions utils/build/docker/golang/go.work
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
go 1.22.0

toolchain go1.22.4
go 1.22.9

use (
./app
Expand Down
5 changes: 3 additions & 2 deletions utils/build/docker/golang/go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-metrics v0.4.1 h1:hR91U9KYmb6bLBYLQjyM+3j+rcd/UhE+G78SFnF8gJA=
github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+3JqfkOG4=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
Expand Down Expand Up @@ -1952,6 +1953,7 @@ github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 h1:+n/aFZefKZp7spd8D
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible h1:aKW/4cBs+yK6gpqU3K/oIwk9Q/XICqd3zOX/UFuvqmk=
github.com/mistifyio/go-zfs v2.1.2-0.20190413222219-f784269be439+incompatible/go.mod h1:8AuVvqP/mXw1px98n46wfvcGfQ4ci2FwoAjKYxuo3Z4=
github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y=
github.com/mitchellh/cli v1.1.0 h1:tEElEatulEHDeedTxwckzyYMA5c86fbmNIUL1hBIiTg=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
Expand Down Expand Up @@ -2133,6 +2135,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1 h1:I2qBYMChEhIjOgazfJmV3/mZM256btk6wkCDRmW7JYs=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/pquerna/cachecontrol v0.0.0-20171018203845-0dec1b30a021 h1:0XM1XL/OFFJjXsYXlG30spTkV/E9+gmd5GD1w2HE8xM=
Expand Down Expand Up @@ -2345,8 +2348,6 @@ github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1S
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/vektah/gqlparser/v2 v2.5.16 h1:1gcmLTvs3JLKXckwCwlUagVn/IlV2bwqle0vJ0vy5p8=
github.com/vektah/gqlparser/v2 v2.5.16/go.mod h1:1lz1OeCqgQbQepsGxPVywrjdBHW2T08PUS3pJqepRww=
github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
Expand Down
8 changes: 7 additions & 1 deletion utils/build/docker/golang/net-http.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ COPY utils/build/docker/golang/app/go.mod utils/build/docker/golang/app/go.sum /
WORKDIR /app
RUN go mod download && go mod verify

RUN go install github.com/DataDog/orchestrion@main

# copy the app code
COPY utils/build/docker/golang/app /app

# download the proper tracer version
COPY utils/build/docker/golang/install_ddtrace.sh binaries* /binaries/
RUN /binaries/install_ddtrace.sh

RUN go build -v -tags appsec -o weblog ./net-http
ENV DD_ORCHESTRION_IS_GOMOD_VERSION=true

RUN orchestrion pin

RUN orchestrion go build -v -tags appsec -o weblog ./net-http

# ==============================================================================

Expand Down
Loading