From 9f90c25ad0b620e5fbe74f184bc767423d717273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Casta=C3=B1=C3=A9?= Date: Tue, 20 Aug 2024 09:44:03 +0200 Subject: [PATCH 01/13] feat: support instrumentation of `github.com/{Shopify,IBM}/sarama` (#216) ### What does this PR do? Adds support for instrumenting `github.com/Shopify/sarama` and `github.com/IBM/sarama`. Context propagation is handled in `WrapPartitionConsumer`, which is called by the wrapped consumer from `WrapConsumer`. ### Reviewer's Checklist - [ ] Changed code has unit tests for its functionality. --------- Co-authored-by: Romain Marcadier Co-authored-by: Romain Marcadier --- _integration-tests/go.mod | 14 ++ _integration-tests/go.sum | 45 ++++++ _integration-tests/tests/ibm_sarama/main.go | 141 ++++++++++++++++++ .../tests/shopify_sarama/main.go | 141 ++++++++++++++++++ _integration-tests/tests/suite.generated.go | 18 ++- go.mod | 14 ++ go.sum | 35 +++++ internal/injector/builtin/generated.go | 96 +++++++++++- internal/injector/builtin/generated_deps.go | 2 + .../testdata/client/ibm_sarama.go.snap | 45 ++++++ .../builtin/testdata/client/sarama.go.snap | 45 ++++++ .../testdata/client/shopify_sarama.go.snap | 45 ++++++ .../testdata/server/ibm_sarama.go.snap | 106 +++++++++++++ .../builtin/testdata/server/sarama.go.snap | 106 +++++++++++++ .../testdata/server/shopify_sarama.go.snap | 106 +++++++++++++ .../builtin/yaml/datastreams/ibm_sarama.yml | 79 ++++++++++ .../yaml/datastreams/shopify_sarama.yml | 79 ++++++++++ samples/client/ibm_sarama.go | 29 ++++ samples/client/shopify_sarama.go | 29 ++++ samples/go.mod | 13 ++ samples/go.sum | 35 +++++ samples/server/ibm_sarama.go | 60 ++++++++ samples/server/shopify_sarama.go | 60 ++++++++ 23 files changed, 1335 insertions(+), 8 deletions(-) create mode 100644 _integration-tests/tests/ibm_sarama/main.go create mode 100644 _integration-tests/tests/shopify_sarama/main.go create mode 100644 internal/injector/builtin/testdata/client/ibm_sarama.go.snap create mode 100644 internal/injector/builtin/testdata/client/sarama.go.snap create mode 100644 internal/injector/builtin/testdata/client/shopify_sarama.go.snap create mode 100644 internal/injector/builtin/testdata/server/ibm_sarama.go.snap create mode 100644 internal/injector/builtin/testdata/server/sarama.go.snap create mode 100644 internal/injector/builtin/testdata/server/shopify_sarama.go.snap create mode 100644 internal/injector/builtin/yaml/datastreams/ibm_sarama.yml create mode 100644 internal/injector/builtin/yaml/datastreams/shopify_sarama.yml create mode 100644 samples/client/ibm_sarama.go create mode 100644 samples/client/shopify_sarama.go create mode 100644 samples/server/ibm_sarama.go create mode 100644 samples/server/shopify_sarama.go diff --git a/_integration-tests/go.mod b/_integration-tests/go.mod index 987e4e0dc..74aacdd69 100644 --- a/_integration-tests/go.mod +++ b/_integration-tests/go.mod @@ -5,6 +5,8 @@ go 1.22.6 replace github.com/datadog/orchestrion => ../ require ( + github.com/IBM/sarama v1.43.3 + github.com/Shopify/sarama v1.38.1 github.com/aws/aws-sdk-go v1.55.5 github.com/datadog/orchestrion v0.7.3 github.com/dave/jennifer v1.7.0 @@ -25,6 +27,7 @@ require ( github.com/testcontainers/testcontainers-go v0.32.0 github.com/testcontainers/testcontainers-go/modules/mongodb v0.32.0 github.com/testcontainers/testcontainers-go/modules/redis v0.32.0 + github.com/testcontainers/testcontainers-go/modules/redpanda v0.32.0 github.com/testcontainers/testcontainers-go/modules/vault v0.32.0 github.com/xlab/treeprint v1.2.0 go.mongodb.org/mongo-driver v1.16.1 @@ -130,6 +133,9 @@ require ( github.com/docker/docker v27.1.2+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/eapache/go-resiliency v1.7.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect + github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect github.com/ebitengine/purego v0.7.1 // indirect github.com/emicklei/go-restful/v3 v3.12.1 // indirect @@ -190,12 +196,18 @@ require ( github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.6 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/hashicorp/vault/sdk v0.13.0 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/invopop/yaml v0.3.1 // indirect + github.com/jcmturner/aescts/v2 v2.0.0 // indirect + github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect + github.com/jcmturner/gofork v1.7.6 // indirect + github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect + github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jdkato/prose v1.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -252,10 +264,12 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect + github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/_integration-tests/go.sum b/_integration-tests/go.sum index c6f073466..54ee60712 100644 --- a/_integration-tests/go.sum +++ b/_integration-tests/go.sum @@ -98,12 +98,18 @@ github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/ github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= github.com/DataDog/sketches-go v1.4.6 h1:acd5fb+QdUzGrosfNLwrIhqyrbMORpvBy7mE+vHlT3I= github.com/DataDog/sketches-go v1.4.6/go.mod h1:7Y8GN8Jf66DLyDhc94zuWA3uHEt/7ttt8jHOBWWrSOg= +github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA= +github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ= github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/Microsoft/hcsshim v0.12.5 h1:bpTInLlDy/nDRWFVcefDZZ1+U8tS+rz3MxjKgu9boo0= github.com/Microsoft/hcsshim v0.12.5/go.mod h1:tIUGego4G1EN5Hb6KC90aDYiUI2dqLSTTOCjVNpOgZ8= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/Shopify/sarama v1.38.1 h1:lqqPUPQZ7zPqYlWpTh+LQ9bhYNu2xJL6k1SJN4WVe2A= +github.com/Shopify/sarama v1.38.1/go.mod h1:iwv9a67Ha8VNa+TifujYoWGxWnu2kNVAQdSdZ4X2o5g= +github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= +github.com/Shopify/toxiproxy/v2 v2.5.0/go.mod h1:yhM2epWtAmel9CB8r2+L+PCmhH6yH2pITaPAo7jxJl0= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= @@ -270,6 +276,12 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= +github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= +github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 h1:8EXxF+tCLqaVk8AOC29zl2mnhQjwyLxxOTuhUazWRsg= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4/go.mod h1:I5sHm0Y0T1u5YjlyqC5GVArM7aNZRUYtTjmJ8mPJFds= github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA= @@ -494,6 +506,8 @@ github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms= @@ -519,6 +533,9 @@ github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= github.com/hashicorp/go-sockaddr v1.0.6 h1:RSG8rKU28VTUTvEKghe5gIhIQpv8evvNpnDEyqO4u9I= github.com/hashicorp/go-sockaddr v1.0.6/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= @@ -550,6 +567,18 @@ github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= +github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= +github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= +github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= +github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg= +github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= +github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= +github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= +github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8= +github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= +github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= +github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jdkato/prose v1.2.1 h1:Fp3UnJmLVISmlc57BgKUzdjr0lOtjqTZicL3PaYy6cU= github.com/jdkato/prose v1.2.1/go.mod h1:AiRHgVagnEx2JbQRQowVBKjG0bcs/vtkGCH1dYAL1rA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -626,6 +655,8 @@ github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/mdelapenya/tlscert v0.1.0 h1:YTpF579PYUX475eOL+6zyEO3ngLTOUWck78NBuJVXaM= +github.com/mdelapenya/tlscert v0.1.0/go.mod h1:wrbyM/DwbFCeCeqdPX/8c6hNOqQgbf0rUDErE1uD+64= github.com/microsoft/go-mssqldb v0.21.0 h1:p2rpHIL7TlSv1QrbXJUAcbyRKnIT0C9rRkH2E4OjLn8= github.com/microsoft/go-mssqldb v0.21.0/go.mod h1:+4wZTUnz/SV6nffv+RRRB/ss8jPng5Sho2SmM1l2ts4= github.com/minio/highwayhash v1.0.3 h1:kbnuUMoHYyVl7szWjSxJnxw11k2U709jqFPPmIUyD6Q= @@ -712,6 +743,8 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 h1:jYi87L8j62qkXzaYHAQAhEapgukhenIMZRBKTNRLHJ4= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -726,6 +759,8 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:Om github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 h1:4+LEVOB87y175cLJC/mbsgKmoDOjrBldtXvioEy96WY= @@ -804,6 +839,8 @@ github.com/testcontainers/testcontainers-go/modules/mongodb v0.32.0 h1:DvmvHV1ir github.com/testcontainers/testcontainers-go/modules/mongodb v0.32.0/go.mod h1:z0ZvM2V2iThZGrzEN6sddJpvnGhJd6O1O0FTFoZXmpk= github.com/testcontainers/testcontainers-go/modules/redis v0.32.0 h1:HW5Qo9qfLi5iwfS7cbXwG6qe8ybXGePcgGPEmVlVDlo= github.com/testcontainers/testcontainers-go/modules/redis v0.32.0/go.mod h1:5kltdxVKZG0aP1iegeqKz4K8HHyP0wbkW5o84qLyMjY= +github.com/testcontainers/testcontainers-go/modules/redpanda v0.32.0 h1:YicRA+Up3fiI1Vwtaw6MbUPoZfUUySoma6cxmjOgkMo= +github.com/testcontainers/testcontainers-go/modules/redpanda v0.32.0/go.mod h1:4DNyEf4H091/q4qdXpVdxOne1EvvcFgNf7atLv3FqkU= github.com/testcontainers/testcontainers-go/modules/vault v0.32.0 h1:ae/zLTcf7is6m2kLAzOJmO5O2Dy/zZV/KZRx6Wx63bw= github.com/testcontainers/testcontainers-go/modules/vault v0.32.0/go.mod h1:IOiaemn5bDfDPa8120qECKKKtoOQqKaIKo9pW4bMMes= github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g= @@ -822,6 +859,12 @@ github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYg github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/twmb/franz-go v1.16.1 h1:rpWc7fB9jd7TgmCyfxzenBI+QbgS8ZfJOUQE+tzPtbE= +github.com/twmb/franz-go v1.16.1/go.mod h1:/pER254UPPGp/4WfGqRi+SIRGE50RSQzVubQp6+N4FA= +github.com/twmb/franz-go/pkg/kadm v1.11.0 h1:FfeWJ0qadntFpAcQt8JzNXW4dijjytZNLrzJuzzzuxA= +github.com/twmb/franz-go/pkg/kadm v1.11.0/go.mod h1:qrhkdH+SWS3ivmbqOgHbpgVHamhaKcjH0UM+uOp0M1A= +github.com/twmb/franz-go/pkg/kmsg v1.7.0 h1:a457IbvezYfA5UkiBvyV3zj0Is3y1i8EJgqjJYoij2E= +github.com/twmb/franz-go/pkg/kmsg v1.7.0/go.mod h1:se9Mjdt0Nwzc9lnjJ0HyDtLyBnaBDAd7pCje47OhSyw= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/urfave/cli/v2 v2.27.4 h1:o1owoI+02Eb+K107p27wEX9Bb8eqIoZCfLXloLUSWJ8= @@ -910,6 +953,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= @@ -996,6 +1040,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= diff --git a/_integration-tests/tests/ibm_sarama/main.go b/_integration-tests/tests/ibm_sarama/main.go new file mode 100644 index 000000000..89e363d5f --- /dev/null +++ b/_integration-tests/tests/ibm_sarama/main.go @@ -0,0 +1,141 @@ +// 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 2023-present Datadog, Inc. + +package ibm_sarama + +import ( + "context" + "testing" + "time" + + "orchestrion/integration/utils" + "orchestrion/integration/validator/trace" + + "github.com/IBM/sarama" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/redpanda" +) + +const ( + topic = "gotest" + partition = int32(0) +) + +type TestCase struct { + server *redpanda.Container + cfg *sarama.Config + addrs []string +} + +func (tc *TestCase) Setup(t *testing.T) { + var ( + err error + ctx = context.Background() + ) + tc.cfg = sarama.NewConfig() + tc.cfg.Version = sarama.V0_11_0_0 + tc.cfg.Producer.Return.Successes = true + + tc.server, err = redpanda.Run(ctx, + "docker.redpanda.com/redpandadata/redpanda:v24.2.1", + redpanda.WithAutoCreateTopics(), + testcontainers.WithLogger(testcontainers.TestLogger(t)), + utils.WithTestLogConsumer(t), + ) + if err != nil { + t.Skipf("Failed to start kafka test container: %v\n", err) + } + + addr, err := tc.server.KafkaSeedBroker(ctx) + require.NoError(t, err, "failed to get seed broker address") + + tc.addrs = []string{addr} +} + +func produceMessage(t *testing.T, addrs []string, cfg *sarama.Config) { + t.Helper() + + producer, err := sarama.NewSyncProducer(addrs, cfg) + require.NoError(t, err, "failed to create producer") + defer func() { assert.NoError(t, producer.Close(), "failed to close producer") }() + + _, _, err = producer.SendMessage(&sarama.ProducerMessage{ + Topic: topic, + Partition: partition, + Value: sarama.StringEncoder("Hello, World!"), + }) + require.NoError(t, err, "failed to send message") + _, _, err = producer.SendMessage(&sarama.ProducerMessage{ + Topic: topic, + Partition: partition, + Value: sarama.StringEncoder("Another message to avoid flaky tests"), + }) + require.NoError(t, err, "failed to send message") +} + +func consumeMessage(t *testing.T, addrs []string, cfg *sarama.Config) { + t.Helper() + + consumer, err := sarama.NewConsumer(addrs, cfg) + require.NoError(t, err, "failed to create consumer") + defer func() { assert.NoError(t, consumer.Close(), "failed to close consumer") }() + + partitionConsumer, err := consumer.ConsumePartition(topic, partition, sarama.OffsetOldest) + require.NoError(t, err, "failed to create partition consumer") + defer func() { assert.NoError(t, partitionConsumer.Close(), "failed to close partition consumer") }() + + expectedMessages := []string{"Hello, World!", "Another message to avoid flaky tests"} + for i := 0; i < len(expectedMessages); i++ { + select { + case msg := <-partitionConsumer.Messages(): + require.Equal(t, expectedMessages[i], string(msg.Value)) + case <-time.After(15 * time.Second): + t.Fatal("timed out waiting for message") + } + } +} + +func (tc *TestCase) Run(t *testing.T) { + produceMessage(t, tc.addrs, tc.cfg) + consumeMessage(t, tc.addrs, tc.cfg) +} + +func (tc *TestCase) Teardown(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + + require.NoError(t, tc.server.Terminate(ctx)) +} + +func (tc *TestCase) ExpectedTraces() trace.Spans { + return trace.Spans{ + { + Tags: map[string]any{ + "name": "kafka.produce", + "type": "queue", + "service": "kafka", + }, + Meta: map[string]any{ + "span.kind": "producer", + "component": "IBM/sarama", + }, + Children: trace.Spans{ + { + Tags: map[string]any{ + "name": "kafka.consume", + "type": "queue", + "service": "kafka", + }, + Meta: map[string]any{ + "span.kind": "consumer", + "component": "IBM/sarama", + }, + }, + }, + }, + } +} diff --git a/_integration-tests/tests/shopify_sarama/main.go b/_integration-tests/tests/shopify_sarama/main.go new file mode 100644 index 000000000..ff8d1450b --- /dev/null +++ b/_integration-tests/tests/shopify_sarama/main.go @@ -0,0 +1,141 @@ +// 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 2023-present Datadog, Inc. + +package shopify_sarama + +import ( + "context" + "testing" + "time" + + "orchestrion/integration/utils" + "orchestrion/integration/validator/trace" + + "github.com/Shopify/sarama" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/redpanda" +) + +const ( + topic = "gotest" + partition = int32(0) +) + +type TestCase struct { + server *redpanda.Container + cfg *sarama.Config + addrs []string +} + +func (tc *TestCase) Setup(t *testing.T) { + var ( + err error + ctx = context.Background() + ) + tc.cfg = sarama.NewConfig() + tc.cfg.Version = sarama.V0_11_0_0 + tc.cfg.Producer.Return.Successes = true + + tc.server, err = redpanda.Run(ctx, + "docker.redpanda.com/redpandadata/redpanda:v24.2.1", + redpanda.WithAutoCreateTopics(), + testcontainers.WithLogger(testcontainers.TestLogger(t)), + utils.WithTestLogConsumer(t), + ) + if err != nil { + t.Skipf("Failed to start kafka test container: %v\n", err) + } + + addr, err := tc.server.KafkaSeedBroker(ctx) + require.NoError(t, err, "failed to get seed broker address") + + tc.addrs = []string{addr} +} + +func produceMessage(t *testing.T, addrs []string, cfg *sarama.Config) { + t.Helper() + + producer, err := sarama.NewSyncProducer(addrs, cfg) + require.NoError(t, err, "failed to create producer") + defer func() { assert.NoError(t, producer.Close(), "failed to close producer") }() + + _, _, err = producer.SendMessage(&sarama.ProducerMessage{ + Topic: topic, + Partition: partition, + Value: sarama.StringEncoder("Hello, World!"), + }) + require.NoError(t, err, "failed to send message") + _, _, err = producer.SendMessage(&sarama.ProducerMessage{ + Topic: topic, + Partition: partition, + Value: sarama.StringEncoder("Another message to avoid flaky tests"), + }) + require.NoError(t, err, "failed to send message") +} + +func consumeMessage(t *testing.T, addrs []string, cfg *sarama.Config) { + t.Helper() + + consumer, err := sarama.NewConsumer(addrs, cfg) + require.NoError(t, err, "failed to create consumer") + defer func() { assert.NoError(t, consumer.Close(), "failed to close consumer") }() + + partitionConsumer, err := consumer.ConsumePartition(topic, partition, sarama.OffsetOldest) + require.NoError(t, err, "failed to create partition consumer") + defer func() { assert.NoError(t, partitionConsumer.Close(), "failed to close partition consumer") }() + + expectedMessages := []string{"Hello, World!", "Another message to avoid flaky tests"} + for i := 0; i < len(expectedMessages); i++ { + select { + case msg := <-partitionConsumer.Messages(): + require.Equal(t, expectedMessages[i], string(msg.Value)) + case <-time.After(15 * time.Second): + t.Fatal("timed out waiting for message") + } + } +} + +func (tc *TestCase) Run(t *testing.T) { + produceMessage(t, tc.addrs, tc.cfg) + consumeMessage(t, tc.addrs, tc.cfg) +} + +func (tc *TestCase) Teardown(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + + require.NoError(t, tc.server.Terminate(ctx)) +} + +func (tc *TestCase) ExpectedTraces() trace.Spans { + return trace.Spans{ + { + Tags: map[string]any{ + "name": "kafka.produce", + "type": "queue", + "service": "kafka", + }, + Meta: map[string]any{ + "span.kind": "producer", + "component": "Shopify/sarama", + }, + Children: trace.Spans{ + { + Tags: map[string]any{ + "name": "kafka.consume", + "type": "queue", + "service": "kafka", + }, + Meta: map[string]any{ + "span.kind": "consumer", + "component": "Shopify/sarama", + }, + }, + }, + }, + } +} diff --git a/_integration-tests/tests/suite.generated.go b/_integration-tests/tests/suite.generated.go index 0b7ea8ff9..92a1b7ba1 100644 --- a/_integration-tests/tests/suite.generated.go +++ b/_integration-tests/tests/suite.generated.go @@ -19,11 +19,13 @@ import ( gorm "orchestrion/integration/tests/gorm" gormjinzhu "orchestrion/integration/tests/gorm.jinzhu" grpc "orchestrion/integration/tests/grpc" + ibmsarama "orchestrion/integration/tests/ibm_sarama" k8sclientgo "orchestrion/integration/tests/k8s_client_go" mongo "orchestrion/integration/tests/mongo" mux "orchestrion/integration/tests/mux" nethttp "orchestrion/integration/tests/net_http" redigo "orchestrion/integration/tests/redigo" + shopifysarama "orchestrion/integration/tests/shopify_sarama" slog "orchestrion/integration/tests/slog" sql "orchestrion/integration/tests/sql" vault "orchestrion/integration/tests/vault" @@ -41,14 +43,16 @@ var suite = map[string]testCase{ "gorm": new(gorm.TestCase), "gorm.jinzhu": new(gormjinzhu.TestCase), "grpc": new(grpc.TestCase), + "ibm_sarama": new(ibmsarama.TestCase), "k8s_client_go/NewCfgFunc": new(k8sclientgo.TestCaseNewCfgFunc), "k8s_client_go/StructLiteralWithParam": new(k8sclientgo.TestCaseStructLiteralWithParam), "k8s_client_go/StructLiteralWithoutParam": new(k8sclientgo.TestCaseStructLiteralWithoutParam), - "mongo": new(mongo.TestCase), - "mux": new(mux.TestCase), - "net_http": new(nethttp.TestCase), - "redigo": new(redigo.TestCase), - "slog": new(slog.TestCase), - "sql": new(sql.TestCase), - "vault": new(vault.TestCase), + "mongo": new(mongo.TestCase), + "mux": new(mux.TestCase), + "net_http": new(nethttp.TestCase), + "redigo": new(redigo.TestCase), + "shopify_sarama": new(shopifysarama.TestCase), + "slog": new(slog.TestCase), + "sql": new(sql.TestCase), + "vault": new(vault.TestCase), } diff --git a/go.mod b/go.mod index 6b179dd62..c5edf3496 100644 --- a/go.mod +++ b/go.mod @@ -52,7 +52,9 @@ require ( github.com/DataDog/go-tuf v1.1.0-0.5.2 // indirect github.com/DataDog/gostackparse v0.7.0 // indirect github.com/DataDog/sketches-go v1.4.6 // indirect + github.com/IBM/sarama v1.40.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/Shopify/sarama v1.38.1 // indirect github.com/alecthomas/chroma/v2 v2.14.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c // indirect @@ -107,6 +109,9 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/disintegration/gift v1.2.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/eapache/go-resiliency v1.4.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect + github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect github.com/ebitengine/purego v0.7.1 // indirect github.com/evanw/esbuild v0.23.1 // indirect @@ -144,6 +149,7 @@ require ( github.com/gohugoio/localescompressed v1.0.1 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/snappy v0.0.4 // indirect github.com/gomodule/redigo v1.9.2 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/licenseclassifier/v2 v2.0.0 // indirect @@ -163,12 +169,18 @@ require ( github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.6 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/hashicorp/vault/api v1.14.0 // indirect github.com/hashicorp/vault/sdk v0.13.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/invopop/yaml v0.3.1 // indirect + github.com/jcmturner/aescts/v2 v2.0.0 // indirect + github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect + github.com/jcmturner/gofork v1.7.6 // indirect + github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect + github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jdkato/prose v1.2.1 // indirect github.com/jinzhu/gorm v1.9.16 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -212,10 +224,12 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect + github.com/pierrec/lz4/v4 v4.1.18 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect + github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/go.sum b/go.sum index 6a0dd5057..ed24ae945 100644 --- a/go.sum +++ b/go.sum @@ -92,10 +92,16 @@ github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/ github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= github.com/DataDog/sketches-go v1.4.6 h1:acd5fb+QdUzGrosfNLwrIhqyrbMORpvBy7mE+vHlT3I= github.com/DataDog/sketches-go v1.4.6/go.mod h1:7Y8GN8Jf66DLyDhc94zuWA3uHEt/7ttt8jHOBWWrSOg= +github.com/IBM/sarama v1.40.0 h1:QTVmX+gMKye52mT5x+Ve/Bod2D0Gy7ylE2Wslv+RHtc= +github.com/IBM/sarama v1.40.0/go.mod h1:6pBloAs1WanL/vsq5qFTyTGulJUntZHhMLOUYEIs9mg= github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/Shopify/sarama v1.38.1 h1:lqqPUPQZ7zPqYlWpTh+LQ9bhYNu2xJL6k1SJN4WVe2A= +github.com/Shopify/sarama v1.38.1/go.mod h1:iwv9a67Ha8VNa+TifujYoWGxWnu2kNVAQdSdZ4X2o5g= +github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= +github.com/Shopify/toxiproxy/v2 v2.5.0/go.mod h1:yhM2epWtAmel9CB8r2+L+PCmhH6yH2pITaPAo7jxJl0= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= @@ -242,6 +248,12 @@ github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/eapache/go-resiliency v1.4.0 h1:3OK9bWpPk5q6pbFAaYSEwD9CLUSHG8bnZuqX2yMt3B0= +github.com/eapache/go-resiliency v1.4.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= +github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 h1:8EXxF+tCLqaVk8AOC29zl2mnhQjwyLxxOTuhUazWRsg= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4/go.mod h1:I5sHm0Y0T1u5YjlyqC5GVArM7aNZRUYtTjmJ8mPJFds= github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA= @@ -463,6 +475,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m github.com/googleapis/gax-go/v2 v2.13.0 h1:yitjD5f7jQHhyDsnhKEBU52NdvvdSeGzlAnDPT0hH1s= github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS338j1Is2S+B7A= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hairyhenderson/go-codeowners v0.5.0 h1:dpQB+hVHiRc2VVvc2BHxkuM+tmu9Qej/as3apqUbsWc= @@ -486,6 +500,9 @@ github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= github.com/hashicorp/go-sockaddr v1.0.6 h1:RSG8rKU28VTUTvEKghe5gIhIQpv8evvNpnDEyqO4u9I= github.com/hashicorp/go-sockaddr v1.0.6/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= @@ -515,6 +532,18 @@ github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= +github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= +github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= +github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= +github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg= +github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= +github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= +github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= +github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8= +github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= +github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= +github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jdkato/prose v1.2.1 h1:Fp3UnJmLVISmlc57BgKUzdjr0lOtjqTZicL3PaYy6cU= github.com/jdkato/prose v1.2.1/go.mod h1:AiRHgVagnEx2JbQRQowVBKjG0bcs/vtkGCH1dYAL1rA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -654,6 +683,8 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 h1:jYi87L8j62qkXzaYHAQAhEapgukhenIMZRBKTNRLHJ4= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= +github.com/pierrec/lz4/v4 v4.1.18 h1:xaKrnTkyoqfh1YItXl56+6KJNVYWlEEPuAQW9xsplYQ= +github.com/pierrec/lz4/v4 v4.1.18/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -668,6 +699,8 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:Om github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 h1:4+LEVOB87y175cLJC/mbsgKmoDOjrBldtXvioEy96WY= @@ -830,6 +863,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= @@ -916,6 +950,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 46e99d71d..1c95de0ba 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -123,6 +123,98 @@ var Aspects = [...]aspect.Aspect{ advice.ReplaceFunction("gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo", "DialURL"), }, }, + // From datastreams/ibm_sarama.yml + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/IBM/sarama.NewConsumer"), + join.FunctionCall("github.com/IBM/sarama.NewConsumerClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "func(c sarama.Consumer, err error) (sarama.Consumer, error) {\n if c != nil {\n c = saramatrace.WrapConsumer(c)\n }\n return c, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/IBM/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1", + }, + )), + }, + }, + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/IBM/sarama.NewSyncProducer"), + join.FunctionCall("github.com/IBM/sarama.NewSyncProducerFromClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "{{- $cfg := .FindArgument \"sarama.Config\" -}}\nfunc(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) {\n if p != nil {\n p = saramatrace.WrapSyncProducer(\n {{- if $cfg -}}\n {{ $cfg }},\n {{- else -}}\n nil,\n {{- end -}}\n p,\n )\n }\n return p, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/IBM/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1", + }, + )), + }, + }, + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/IBM/sarama.NewAsyncProducer"), + join.FunctionCall("github.com/IBM/sarama.NewAsyncProducerFromClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "{{- $cfg := .FindArgument \"sarama.Config\" -}}\nfunc(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) {\n if p != nil {\n p = saramatrace.WrapAsyncProducer(\n {{- if $cfg -}}\n {{ $cfg }},\n {{- else -}}\n nil,\n {{- end -}}\n p,\n )\n }\n return p, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/IBM/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1", + }, + )), + }, + }, + // From datastreams/shopify_sarama.yml + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/Shopify/sarama.NewConsumer"), + join.FunctionCall("github.com/Shopify/sarama.NewConsumerClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "func(c sarama.Consumer, err error) (sarama.Consumer, error) {\n if c != nil {\n c = saramatrace.WrapConsumer(c)\n }\n return c, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/Shopify/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama", + }, + )), + }, + }, + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/Shopify/sarama.NewSyncProducer"), + join.FunctionCall("github.com/Shopify/sarama.NewSyncProducerFromClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "{{- $cfg := .FindArgument \"sarama.Config\" -}}\nfunc(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) {\n if p != nil {\n p = saramatrace.WrapSyncProducer(\n {{- if $cfg -}}\n {{ $cfg }},\n {{- else -}}\n nil,\n {{- end -}}\n p,\n )\n }\n return p, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/Shopify/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama", + }, + )), + }, + }, + { + JoinPoint: join.OneOf( + join.FunctionCall("github.com/Shopify/sarama.NewAsyncProducer"), + join.FunctionCall("github.com/Shopify/sarama.NewAsyncProducerFromClient"), + ), + Advice: []advice.Advice{ + advice.WrapExpression(code.MustTemplate( + "{{- $cfg := .FindArgument \"sarama.Config\" -}}\nfunc(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) {\n if p != nil {\n p = saramatrace.WrapAsyncProducer(\n {{- if $cfg -}}\n {{ $cfg }},\n {{- else -}}\n nil,\n {{- end -}}\n p,\n )\n }\n return p, err\n}({{ . }})", + map[string]string{ + "sarama": "github.com/Shopify/sarama", + "saramatrace": "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama", + }, + )), + }, + }, // From dd-span.yml { JoinPoint: join.FunctionBody(join.AllOf( @@ -632,6 +724,8 @@ var InjectedPaths = [...]string{ "github.com/datadog/orchestrion/instrument/event", "github.com/datadog/orchestrion/instrument/net/http", "gopkg.in/DataDog/dd-trace-go.v1/appsec/events", + "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1", + "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama", "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go/aws", "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql", "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin", @@ -670,4 +764,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:4Gi3IVMUORbzxWjHQbXgEgYMSTVz9W/vGmoeH+0ipdwC/ap6CwnYKop/THjVNFxAHS47zLj/m29sAl3dFROSnA==" +const Checksum = "sha512:wbkfjDjV3+GQ36tmhe3yOJDfllvuJ8Tt8Q6WjcsZyNbP2JLK5IKQU5+Ns5PTdZJiwCZ0BnRyCwYSOV/rx9aNzQ==" diff --git a/internal/injector/builtin/generated_deps.go b/internal/injector/builtin/generated_deps.go index 24995f22e..7acd6a0ac 100644 --- a/internal/injector/builtin/generated_deps.go +++ b/internal/injector/builtin/generated_deps.go @@ -15,6 +15,8 @@ import ( _ "github.com/datadog/orchestrion/instrument/event" _ "github.com/datadog/orchestrion/instrument/net/http" _ "gopkg.in/DataDog/dd-trace-go.v1/appsec/events" + _ "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1" + _ "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" _ "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go/aws" _ "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" _ "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin" diff --git a/internal/injector/builtin/testdata/client/ibm_sarama.go.snap b/internal/injector/builtin/testdata/client/ibm_sarama.go.snap new file mode 100644 index 000000000..d9ef6bde6 --- /dev/null +++ b/internal/injector/builtin/testdata/client/ibm_sarama.go.snap @@ -0,0 +1,45 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/IBM/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1" +) + +//line samples/client/ibm_sarama.go:10 +func ibmSaramaConsumer() { + cfg := sarama.NewConfig() + consumer, err := +//line :1 + func(c sarama.Consumer, err error) (sarama.Consumer, error) { + if c != nil { + c = __orchestrion_saramatrace.WrapConsumer(c) + } + return c, err + }( +//line samples/client/ibm_sarama.go:12 + sarama.NewConsumer([]string{"localhost:9092"}, cfg)) +//line samples/client/ibm_sarama.go:13 + if err != nil { + panic(err) + } + defer consumer.Close() +} + +func ibmSaramaConsumerFromClient() { + client, err := sarama.NewClient([]string{"localhost:9092"}, nil) + if err != nil { + panic(err) + } + consumer, err := sarama.NewConsumerFromClient(client) + if err != nil { + panic(err) + } + defer consumer.Close() +} diff --git a/internal/injector/builtin/testdata/client/sarama.go.snap b/internal/injector/builtin/testdata/client/sarama.go.snap new file mode 100644 index 000000000..68f4dcf92 --- /dev/null +++ b/internal/injector/builtin/testdata/client/sarama.go.snap @@ -0,0 +1,45 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/Shopify/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" +) + +//line samples/client/sarama.go:10 +func saramaConsumer() { + cfg := sarama.NewConfig() + consumer, err := +//line :1 + func(c sarama.Consumer, err error) (sarama.Consumer, error) { + if c != nil { + c = __orchestrion_saramatrace.WrapConsumer(c) + } + return c, err + }( +//line samples/client/sarama.go:12 + sarama.NewConsumer([]string{"localhost:9092"}, cfg)) +//line samples/client/sarama.go:13 + if err != nil { + panic(err) + } + defer consumer.Close() +} + +func saramaConsumerFromClient() { + client, err := sarama.NewClient([]string{"localhost:9092"}, nil) + if err != nil { + panic(err) + } + consumer, err := sarama.NewConsumerFromClient(client) + if err != nil { + panic(err) + } + defer consumer.Close() +} diff --git a/internal/injector/builtin/testdata/client/shopify_sarama.go.snap b/internal/injector/builtin/testdata/client/shopify_sarama.go.snap new file mode 100644 index 000000000..94b528f4f --- /dev/null +++ b/internal/injector/builtin/testdata/client/shopify_sarama.go.snap @@ -0,0 +1,45 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/Shopify/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" +) + +//line samples/client/shopify_sarama.go:10 +func shopifySaramaConsumer() { + cfg := sarama.NewConfig() + consumer, err := +//line :1 + func(c sarama.Consumer, err error) (sarama.Consumer, error) { + if c != nil { + c = __orchestrion_saramatrace.WrapConsumer(c) + } + return c, err + }( +//line samples/client/shopify_sarama.go:12 + sarama.NewConsumer([]string{"localhost:9092"}, cfg)) +//line samples/client/shopify_sarama.go:13 + if err != nil { + panic(err) + } + defer consumer.Close() +} + +func shopifySaramaConsumerFromClient() { + client, err := sarama.NewClient([]string{"localhost:9092"}, nil) + if err != nil { + panic(err) + } + consumer, err := sarama.NewConsumerFromClient(client) + if err != nil { + panic(err) + } + defer consumer.Close() +} diff --git a/internal/injector/builtin/testdata/server/ibm_sarama.go.snap b/internal/injector/builtin/testdata/server/ibm_sarama.go.snap new file mode 100644 index 000000000..54cd5af48 --- /dev/null +++ b/internal/injector/builtin/testdata/server/ibm_sarama.go.snap @@ -0,0 +1,106 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/IBM/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1" +) + +//line samples/server/ibm_sarama.go:10 +func ibmSaramaProducer() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/ibm_sarama.go:14 + sarama.NewSyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/ibm_sarama.go:15 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/ibm_sarama.go:29 + sarama.NewSyncProducerFromClient(client)) +//line samples/server/ibm_sarama.go:30 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaAsyncProducer() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/ibm_sarama.go:40 + sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/ibm_sarama.go:41 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaAsyncProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/ibm_sarama.go:55 + sarama.NewAsyncProducerFromClient(client)) +//line samples/server/ibm_sarama.go:56 + if err != nil { + panic(err) + } + defer producer.Close() +} diff --git a/internal/injector/builtin/testdata/server/sarama.go.snap b/internal/injector/builtin/testdata/server/sarama.go.snap new file mode 100644 index 000000000..0ea4575ec --- /dev/null +++ b/internal/injector/builtin/testdata/server/sarama.go.snap @@ -0,0 +1,106 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/Shopify/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" +) + +//line samples/server/sarama.go:10 +func saramaProducer() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/sarama.go:14 + sarama.NewSyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/sarama.go:15 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func saramaProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/sarama.go:29 + sarama.NewSyncProducerFromClient(client)) +//line samples/server/sarama.go:30 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func saramaAsyncProducer() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/sarama.go:40 + sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/sarama.go:41 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func saramaAsyncProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/sarama.go:55 + sarama.NewAsyncProducerFromClient(client)) +//line samples/server/sarama.go:56 + if err != nil { + panic(err) + } + defer producer.Close() +} diff --git a/internal/injector/builtin/testdata/server/shopify_sarama.go.snap b/internal/injector/builtin/testdata/server/shopify_sarama.go.snap new file mode 100644 index 000000000..134e82821 --- /dev/null +++ b/internal/injector/builtin/testdata/server/shopify_sarama.go.snap @@ -0,0 +1,106 @@ +// 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 2023-present Datadog, Inc. + +package main + +import ( + "github.com/Shopify/sarama" + +//line :1 + __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" +) + +//line samples/server/shopify_sarama.go:10 +func shopifySaramaProducer() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/shopify_sarama.go:14 + sarama.NewSyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/shopify_sarama.go:15 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) + } + return p, err + }( +//line samples/server/shopify_sarama.go:29 + sarama.NewSyncProducerFromClient(client)) +//line samples/server/shopify_sarama.go:30 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaAsyncProducer() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/shopify_sarama.go:40 + sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg)) +//line samples/server/shopify_sarama.go:41 + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaAsyncProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := +//line :1 + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) + } + return p, err + }( +//line samples/server/shopify_sarama.go:55 + sarama.NewAsyncProducerFromClient(client)) +//line samples/server/shopify_sarama.go:56 + if err != nil { + panic(err) + } + defer producer.Close() +} diff --git a/internal/injector/builtin/yaml/datastreams/ibm_sarama.yml b/internal/injector/builtin/yaml/datastreams/ibm_sarama.yml new file mode 100644 index 000000000..8a89d64bd --- /dev/null +++ b/internal/injector/builtin/yaml/datastreams/ibm_sarama.yml @@ -0,0 +1,79 @@ +# 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 2023-present Datadog, Inc. +--- +# yaml-language-server: $schema=../../../../../docs/static/schema.json +meta: + name: github.com/IBM/sarama + description: Sarama is a Go library for Apache Kafka + icon: fast-forward + +aspects: + - id: Wrap sarama.NewConsumer and sarama.NewConsumerClient + join-point: + one-of: + - function-call: github.com/IBM/sarama.NewConsumer + - function-call: github.com/IBM/sarama.NewConsumerClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1 + sarama: github.com/IBM/sarama + template: |- + func(c sarama.Consumer, err error) (sarama.Consumer, error) { + if c != nil { + c = saramatrace.WrapConsumer(c) + } + return c, err + }({{ . }}) + - id: Wrap sarama.NewSyncProducer and sarama.NewSyncProducerFromClient + join-point: + one-of: + - function-call: github.com/IBM/sarama.NewSyncProducer + - function-call: github.com/IBM/sarama.NewSyncProducerFromClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1 + sarama: github.com/IBM/sarama + template: |- + {{- $cfg := .FindArgument "sarama.Config" -}} + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = saramatrace.WrapSyncProducer( + {{- if $cfg -}} + {{ $cfg }}, + {{- else -}} + nil, + {{- end -}} + p, + ) + } + return p, err + }({{ . }}) + - id: Wrap sarama.NewAsyncProducer and sarama.NewAsyncProducerFromClient + join-point: + one-of: + - function-call: github.com/IBM/sarama.NewAsyncProducer + - function-call: github.com/IBM/sarama.NewAsyncProducerFromClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1 + sarama: github.com/IBM/sarama + template: |- + {{- $cfg := .FindArgument "sarama.Config" -}} + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = saramatrace.WrapAsyncProducer( + {{- if $cfg -}} + {{ $cfg }}, + {{- else -}} + nil, + {{- end -}} + p, + ) + } + return p, err + }({{ . }}) diff --git a/internal/injector/builtin/yaml/datastreams/shopify_sarama.yml b/internal/injector/builtin/yaml/datastreams/shopify_sarama.yml new file mode 100644 index 000000000..2f1691847 --- /dev/null +++ b/internal/injector/builtin/yaml/datastreams/shopify_sarama.yml @@ -0,0 +1,79 @@ +# 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 2023-present Datadog, Inc. +--- +# yaml-language-server: $schema=../../../../../docs/static/schema.json +meta: + name: github.com/Shopify/sarama + description: Sarama is a Go library for Apache Kafka + icon: fast-forward + +aspects: + - id: Wrap sarama.NewConsumer and sarama.NewConsumerClient + join-point: + one-of: + - function-call: github.com/Shopify/sarama.NewConsumer + - function-call: github.com/Shopify/sarama.NewConsumerClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama + sarama: github.com/Shopify/sarama + template: |- + func(c sarama.Consumer, err error) (sarama.Consumer, error) { + if c != nil { + c = saramatrace.WrapConsumer(c) + } + return c, err + }({{ . }}) + - id: Wrap sarama.NewSyncProducer and sarama.NewSyncProducerFromClient + join-point: + one-of: + - function-call: github.com/Shopify/sarama.NewSyncProducer + - function-call: github.com/Shopify/sarama.NewSyncProducerFromClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama + sarama: github.com/Shopify/sarama + template: |- + {{- $cfg := .FindArgument "sarama.Config" -}} + func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { + if p != nil { + p = saramatrace.WrapSyncProducer( + {{- if $cfg -}} + {{ $cfg }}, + {{- else -}} + nil, + {{- end -}} + p, + ) + } + return p, err + }({{ . }}) + - id: Wrap sarama.NewAsyncProducer and sarama.NewAsyncProducerFromClient + join-point: + one-of: + - function-call: github.com/Shopify/sarama.NewAsyncProducer + - function-call: github.com/Shopify/sarama.NewAsyncProducerFromClient + advice: + - wrap-expression: + imports: + saramatrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama + sarama: github.com/Shopify/sarama + template: |- + {{- $cfg := .FindArgument "sarama.Config" -}} + func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { + if p != nil { + p = saramatrace.WrapAsyncProducer( + {{- if $cfg -}} + {{ $cfg }}, + {{- else -}} + nil, + {{- end -}} + p, + ) + } + return p, err + }({{ . }}) diff --git a/samples/client/ibm_sarama.go b/samples/client/ibm_sarama.go new file mode 100644 index 000000000..2938b6ddf --- /dev/null +++ b/samples/client/ibm_sarama.go @@ -0,0 +1,29 @@ +// 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 2023-present Datadog, Inc. + +package main + +import "github.com/IBM/sarama" + +func ibmSaramaConsumer() { + cfg := sarama.NewConfig() + consumer, err := sarama.NewConsumer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer consumer.Close() +} + +func ibmSaramaConsumerFromClient() { + client, err := sarama.NewClient([]string{"localhost:9092"}, nil) + if err != nil { + panic(err) + } + consumer, err := sarama.NewConsumerFromClient(client) + if err != nil { + panic(err) + } + defer consumer.Close() +} diff --git a/samples/client/shopify_sarama.go b/samples/client/shopify_sarama.go new file mode 100644 index 000000000..6a0f806c8 --- /dev/null +++ b/samples/client/shopify_sarama.go @@ -0,0 +1,29 @@ +// 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 2023-present Datadog, Inc. + +package main + +import "github.com/Shopify/sarama" + +func shopifySaramaConsumer() { + cfg := sarama.NewConfig() + consumer, err := sarama.NewConsumer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer consumer.Close() +} + +func shopifySaramaConsumerFromClient() { + client, err := sarama.NewClient([]string{"localhost:9092"}, nil) + if err != nil { + panic(err) + } + consumer, err := sarama.NewConsumerFromClient(client) + if err != nil { + panic(err) + } + defer consumer.Close() +} diff --git a/samples/go.mod b/samples/go.mod index a3c6dac7c..43fb22c38 100644 --- a/samples/go.mod +++ b/samples/go.mod @@ -5,6 +5,8 @@ go 1.22.6 replace github.com/datadog/orchestrion => ../ require ( + github.com/IBM/sarama v1.43.3 + github.com/Shopify/sarama v1.38.1 github.com/aws/aws-sdk-go v1.55.5 github.com/datadog/orchestrion v0.0.0-00010101000000-000000000000 github.com/gin-gonic/gin v1.10.0 @@ -106,6 +108,9 @@ require ( github.com/disintegration/gift v1.2.1 // indirect github.com/dlclark/regexp2 v1.11.4 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/eapache/go-resiliency v1.7.0 // indirect + github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect + github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect github.com/ebitengine/purego v0.7.1 // indirect github.com/evanw/esbuild v0.23.1 // indirect @@ -160,6 +165,7 @@ require ( github.com/hashicorp/go-secure-stdlib/parseutil v0.1.8 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.6 // indirect + github.com/hashicorp/go-uuid v1.0.3 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/hashicorp/vault/sdk v0.13.0 // indirect @@ -169,6 +175,11 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgx/v5 v5.6.0 // indirect github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jcmturner/aescts/v2 v2.0.0 // indirect + github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect + github.com/jcmturner/gofork v1.7.6 // indirect + github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect + github.com/jcmturner/rpc/v2 v2.0.3 // indirect github.com/jdkato/prose v1.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect @@ -215,9 +226,11 @@ require ( github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 // indirect + github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pkg/errors v0.9.1 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect + github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/samples/go.sum b/samples/go.sum index 2832c8dbc..56327a008 100644 --- a/samples/go.sum +++ b/samples/go.sum @@ -92,10 +92,16 @@ github.com/DataDog/gostackparse v0.7.0 h1:i7dLkXHvYzHV308hnkvVGDL3BR4FWl7IsXNPz/ github.com/DataDog/gostackparse v0.7.0/go.mod h1:lTfqcJKqS9KnXQGnyQMCugq3u1FP6UZMfWR0aitKFMM= github.com/DataDog/sketches-go v1.4.6 h1:acd5fb+QdUzGrosfNLwrIhqyrbMORpvBy7mE+vHlT3I= github.com/DataDog/sketches-go v1.4.6/go.mod h1:7Y8GN8Jf66DLyDhc94zuWA3uHEt/7ttt8jHOBWWrSOg= +github.com/IBM/sarama v1.43.3 h1:Yj6L2IaNvb2mRBop39N7mmJAHBVY3dTPncr3qGVkxPA= +github.com/IBM/sarama v1.43.3/go.mod h1:FVIRaLrhK3Cla/9FfRF5X9Zua2KpS3SYIXxhac1H+FQ= github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/Shopify/sarama v1.38.1 h1:lqqPUPQZ7zPqYlWpTh+LQ9bhYNu2xJL6k1SJN4WVe2A= +github.com/Shopify/sarama v1.38.1/go.mod h1:iwv9a67Ha8VNa+TifujYoWGxWnu2kNVAQdSdZ4X2o5g= +github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT0eahc= +github.com/Shopify/toxiproxy/v2 v2.5.0/go.mod h1:yhM2epWtAmel9CB8r2+L+PCmhH6yH2pITaPAo7jxJl0= github.com/alecthomas/assert/v2 v2.7.0 h1:QtqSACNS3tF7oasA8CU6A6sXZSBDqnm7RfpLl9bZqbE= github.com/alecthomas/assert/v2 v2.7.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E= @@ -242,6 +248,12 @@ github.com/dlclark/regexp2 v1.11.4/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cn github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= +github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws= +github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0= +github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc= +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 h1:8EXxF+tCLqaVk8AOC29zl2mnhQjwyLxxOTuhUazWRsg= github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4/go.mod h1:I5sHm0Y0T1u5YjlyqC5GVArM7aNZRUYtTjmJ8mPJFds= github.com/ebitengine/purego v0.7.1 h1:6/55d26lG3o9VCZX8lping+bZcmShseiqlh2bnUDiPA= @@ -465,6 +477,8 @@ github.com/googleapis/gax-go/v2 v2.13.0/go.mod h1:Z/fvTZXF8/uw7Xu5GuslPw+bplx6SS github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hairyhenderson/go-codeowners v0.5.0 h1:dpQB+hVHiRc2VVvc2BHxkuM+tmu9Qej/as3apqUbsWc= @@ -488,6 +502,9 @@ github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= github.com/hashicorp/go-sockaddr v1.0.6 h1:RSG8rKU28VTUTvEKghe5gIhIQpv8evvNpnDEyqO4u9I= github.com/hashicorp/go-sockaddr v1.0.6/go.mod h1:uoUUmtwU7n9Dv3O4SNLeFvg0SxQ3lyjsj6+CCykpaxI= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= @@ -517,6 +534,18 @@ github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8= +github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs= +github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo= +github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM= +github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg= +github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo= +github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o= +github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg= +github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8= +github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= +github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= +github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= github.com/jdkato/prose v1.2.1 h1:Fp3UnJmLVISmlc57BgKUzdjr0lOtjqTZicL3PaYy6cU= github.com/jdkato/prose v1.2.1/go.mod h1:AiRHgVagnEx2JbQRQowVBKjG0bcs/vtkGCH1dYAL1rA= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -656,6 +685,8 @@ github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986 h1:jYi87L8j62qkXzaYHAQAhEapgukhenIMZRBKTNRLHJ4= github.com/philhofer/fwd v1.1.3-0.20240612014219-fbbf4953d986/go.mod h1:RqIHx9QI14HlwKwm98g9Re5prTQ6LdeRQn+gXJFxsJM= +github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= +github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -670,6 +701,8 @@ github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:Om github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM= +github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 h1:4+LEVOB87y175cLJC/mbsgKmoDOjrBldtXvioEy96WY= @@ -830,6 +863,7 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= @@ -916,6 +950,7 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= diff --git a/samples/server/ibm_sarama.go b/samples/server/ibm_sarama.go new file mode 100644 index 000000000..a2e671614 --- /dev/null +++ b/samples/server/ibm_sarama.go @@ -0,0 +1,60 @@ +// 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 2023-present Datadog, Inc. + +package main + +import "github.com/IBM/sarama" + +func ibmSaramaProducer() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + producer, err := sarama.NewSyncProducer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := sarama.NewSyncProducerFromClient(client) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaAsyncProducer() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + producer, err := sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func ibmSaramaAsyncProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := sarama.NewAsyncProducerFromClient(client) + if err != nil { + panic(err) + } + defer producer.Close() +} diff --git a/samples/server/shopify_sarama.go b/samples/server/shopify_sarama.go new file mode 100644 index 000000000..d51c98f83 --- /dev/null +++ b/samples/server/shopify_sarama.go @@ -0,0 +1,60 @@ +// 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 2023-present Datadog, Inc. + +package main + +import "github.com/Shopify/sarama" + +func shopifySaramaProducer() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + producer, err := sarama.NewSyncProducer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Producer.Return.Successes = true + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := sarama.NewSyncProducerFromClient(client) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaAsyncProducer() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + producer, err := sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + defer producer.Close() +} + +func shopifySaramaAsyncProducerFromClient() { + cfg := sarama.NewConfig() + cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing + + client, err := sarama.NewClient([]string{"localhost:9092"}, cfg) + if err != nil { + panic(err) + } + producer, err := sarama.NewAsyncProducerFromClient(client) + if err != nil { + panic(err) + } + defer producer.Close() +} From 2244821628e67e97ac806f4ba593e96e98c72b80 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 20 Aug 2024 10:43:12 +0200 Subject: [PATCH 02/13] chore: use oldstable and stable for running workflows (#227) This allows us to never have to change our workflow configuration when a new go release is issued, as these labels automatically resolve via the published release manifest. Also uses `go.mod` files instead of `go.sum` files to compute cache keys, as the `go.sum` files are technically not a dependency manifest. --- .github/workflows/deps-update.yml | 2 +- .github/workflows/docsite.yml | 2 +- .github/workflows/generate.yml | 4 +-- .github/workflows/release.yml | 3 ++- .github/workflows/tests.yml | 38 ++++++++++++----------------- .github/workflows/workflow_call.yml | 4 +-- 6 files changed, 23 insertions(+), 30 deletions(-) diff --git a/.github/workflows/deps-update.yml b/.github/workflows/deps-update.yml index 248a0249a..cf23b0fbf 100644 --- a/.github/workflows/deps-update.yml +++ b/.github/workflows/deps-update.yml @@ -23,7 +23,7 @@ jobs: uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: go-version: stable # Minimum supported go release - cache-dependency-path: '**/*.sum' + cache-dependency-path: '**/go.mod' # Select the latest available version of gopkg.in/DataDog/dd-trace-go.v1, while ignoring all # the `v1.999.*` versions, which are experimental pre-releases. diff --git a/.github/workflows/docsite.yml b/.github/workflows/docsite.yml index cbb1edbcd..fcd1309bc 100644 --- a/.github/workflows/docsite.yml +++ b/.github/workflows/docsite.yml @@ -26,7 +26,7 @@ jobs: - name: Setup go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: - cache-dependency-path: '**/*.sum' + cache-dependency-path: '**/go.mod' - name: Run go generate (builtin) run: go generate ./internal/injector/builtin - name: Build Site diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index ed17084d7..f87b5f28e 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -24,8 +24,8 @@ jobs: - name: Setup go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: - go-version: 'stable' - cache-dependency-path: '**/*.sum' + go-version: stable + cache-dependency-path: '**/go.mod' - name: Run 'go generate ./...' run: |- diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2cca2e113..5bbc0efe9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,8 @@ jobs: - name: Setup go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: - cache-dependency-path: '**/*.sum' + go-version: stable + cache-dependency-path: '**/go.mod' # Obtains the current configured version tag from source, and verifies it is a valid tag name. # Also checks whether the tag already exists. diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ccf4e8d6..e56750eb1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,8 +21,8 @@ jobs: - name: Setup go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: - go-version: 'stable' - cache-dependency-path: "**/*.sum" + go-version: stable + cache-dependency-path: "**/go.mod" - name: golangci-lint uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6 with: @@ -46,8 +46,8 @@ jobs: strategy: fail-fast: false matrix: - go-version: ['1.22', '1.23'] - name: Unit tests (go${{ matrix.go-version }}) + go-version: [oldstable, stable] + name: Unit tests (go ${{ matrix.go-version }}) steps: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 @@ -55,7 +55,7 @@ jobs: uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: go-version: ${{ matrix.go-version }} - cache-dependency-path: "**/*.sum" + cache-dependency-path: "**/go.mod" - name: Run unit tests run: |- mkdir -p coverage @@ -64,10 +64,8 @@ jobs: - name: Determine simple go version if: always() && github.event_name != 'merge_group' id: simple-go-version - run: echo "version=${COMPLETE_VERSION:0:4}" >> "${GITHUB_OUTPUT}" + run: echo "version=$(go version | cut -d' ' -f3 | grep -oE '\d+\.\d+')" >> "${GITHUB_OUTPUT}" shell: bash - env: - COMPLETE_VERSION: ${{ matrix.go-version }} - name: Upload coverage report # We want this even if the tests failed if: always() && github.event_name != 'merge_group' @@ -76,25 +74,25 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: go${{ steps.simple-go-version.outputs.version }},${{ runner.os }},${{ runner.arch }},unit files: ./coverage/unit.out,./coverage/integration.out - name: Unit Tests (go${{ matrix.go-version }}) + name: Unit Tests (go ${{ matrix.go-version }}) integration-tests: strategy: fail-fast: false matrix: runs-on: [macos, ubuntu, windows] - go-version: ['1.22', '1.23'] + go-version: [oldstable, stable] build-mode: [DRIVER] include: # Alternate build modes (only on ubuntu, latest go; to save CI time) - runs-on: ubuntu - go-version: '1.22' + go-version: oldstable build-mode: TOOLEXEC - runs-on: ubuntu - go-version: '1.22' + go-version: oldstable build-mode: GOFLAGS runs-on: ${{ matrix.runs-on }}-latest - name: Integration tests (go${{ matrix.go-version }}, ${{ matrix.runs-on }}, ${{ matrix.build-mode }}) + name: Integration tests (go ${{ matrix.go-version }}, ${{ matrix.runs-on }}, ${{ matrix.build-mode }}) steps: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 @@ -102,7 +100,7 @@ jobs: uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: go-version: ${{ matrix.go-version }} - cache-dependency-path: "**/*.sum" + cache-dependency-path: "**/go.mod" - name: Setup python uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 with: @@ -138,18 +136,12 @@ jobs: GOFLAGS: -tags=integration,buildtag # Globally set build tags (buildtag is used by the dd-span test) - name: Consolidate coverage report if: github.event_name != 'merge_group' - # Using gotip because the fix for https://github.com/golang/go/issues/68468 is not yet released. - run: |- - go install golang.org/dl/gotip@latest - gotip download - gotip tool covdata textfmt -i ./coverage/raw -o ./coverage/integration.out + run: go tool covdata textfmt -i ./coverage/raw -o ./coverage/integration.out - name: Determine simple go version if: github.event_name != 'merge_group' id: simple-go-version - run: echo "version=${COMPLETE_VERSION:0:4}" >> "${GITHUB_OUTPUT}" + run: echo "version=$(go version | cut -d' ' -f3 | grep -oE '\d+\.\d+')" >> "${GITHUB_OUTPUT}" shell: bash - env: - COMPLETE_VERSION: ${{ matrix.go-version }} - name: Upload coverage report if: github.event_name != 'merge_group' uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4 @@ -157,7 +149,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: go${{ steps.simple-go-version.outputs.version }},${{ runner.os }},${{ runner.arch }},integration files: ./coverage/integration.out - name: Integration Tests (go${{ matrix.go-version }}, ${{ matrix.runs-on }}, ${{ matrix.build-mode }}) + name: Integration Tests (go ${{ matrix.go-version }}, ${{ matrix.runs-on }}, ${{ matrix.build-mode }}) # This is just a join point intended to simplify branch protection settings complete: diff --git a/.github/workflows/workflow_call.yml b/.github/workflows/workflow_call.yml index ad9f8e9f7..d95b9b59a 100644 --- a/.github/workflows/workflow_call.yml +++ b/.github/workflows/workflow_call.yml @@ -39,8 +39,8 @@ jobs: - name: Setup go uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: - go-version: 'stable' - cache-dependency-path: "**/*.sum" + go-version: stable + cache-dependency-path: "**/go.mod" - name: Setup python uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 with: From 581e992da351fe4018d022529dce5ae14de04f3b Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 20 Aug 2024 11:36:16 +0200 Subject: [PATCH 03/13] chore: uniformly pass log.Tracef as packages.Load logger (#229) This allows to get more debugging information with the TRACE log level. --- internal/ensure/requiredversion.go | 6 +++++- internal/injector/injector.go | 2 ++ internal/jobserver/buildid/version.go | 1 + internal/jobserver/pkgs/resolve.go | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/ensure/requiredversion.go b/internal/ensure/requiredversion.go index 67d0cb334..617241506 100644 --- a/internal/ensure/requiredversion.go +++ b/internal/ensure/requiredversion.go @@ -128,7 +128,11 @@ func requiredVersion( // working directory is used. The version may be blank if a replace directive is in effect; in which // case the path value may indicate the location of the source code that is being used instead. func goModVersion(dir string) (moduleVersion string, moduleDir string, err error) { - cfg := &packages.Config{Dir: dir, Mode: packages.NeedModule} + cfg := &packages.Config{ + Dir: dir, + Mode: packages.NeedModule, + Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, + } pkgs, err := packages.Load(cfg, orchestrionPkgPath) if err != nil { return "", "", err diff --git a/internal/injector/injector.go b/internal/injector/injector.go index 5b602704f..dd586ac5d 100644 --- a/internal/injector/injector.go +++ b/internal/injector/injector.go @@ -23,6 +23,7 @@ import ( "github.com/datadog/orchestrion/internal/injector/aspect/context" "github.com/datadog/orchestrion/internal/injector/builtin" "github.com/datadog/orchestrion/internal/injector/typed" + "github.com/datadog/orchestrion/internal/log" "github.com/dave/dst" "github.com/dave/dst/decorator" "github.com/dave/dst/decorator/resolver/guess" @@ -79,6 +80,7 @@ func New(pkgDir string, opts Options) (*Injector, error) { packages.NeedSyntax | packages.NeedTypesInfo, Tests: opts.IncludeTests, + Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, } if flags, err := goflags.Flags(); err == nil { // Honor any `-tags` flags provided by the user, as these may affect what diff --git a/internal/jobserver/buildid/version.go b/internal/jobserver/buildid/version.go index 6b5e4cd32..7663bf8a6 100644 --- a/internal/jobserver/buildid/version.go +++ b/internal/jobserver/buildid/version.go @@ -51,6 +51,7 @@ func (s *service) versionSuffix(req *VersionSuffixRequest) (VersionSuffixRespons &packages.Config{ Mode: packages.NeedDeps | packages.NeedEmbedFiles | packages.NeedFiles | packages.NeedImports | packages.NeedModule, BuildFlags: []string{"-toolexec="}, // Explicitly disable toolexec to avoid infinite recursion + Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, }, builtin.InjectedPaths[:]..., ) diff --git a/internal/jobserver/pkgs/resolve.go b/internal/jobserver/pkgs/resolve.go index a4331910a..c7cc3e409 100644 --- a/internal/jobserver/pkgs/resolve.go +++ b/internal/jobserver/pkgs/resolve.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/datadog/orchestrion/internal/jobserver/client" + "github.com/datadog/orchestrion/internal/log" "golang.org/x/tools/go/packages" ) @@ -130,6 +131,7 @@ func (s *service) resolve(req *ResolveRequest) (ResolveResponse, error) { Dir: req.Dir, Env: env, BuildFlags: req.BuildFlags, + Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, }, req.Pattern, ) From 4a440bbf73adcf508d743df798a337aad5a08879 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 20 Aug 2024 14:22:48 +0200 Subject: [PATCH 04/13] docs: improved contributor guide, security policy (#233) Remove PR template, which is replaced by an updated `CONTRIBUTING.md` guide. Also add a new `SECURITY.md` that indicates how to engage Datadog about security issues. --- .github/pull_request_template.md | 29 ------------- CONTRIBUTING.md | 73 ++++++++++++++++++++++++++++---- SECURITY.md | 13 ++++++ 3 files changed, 77 insertions(+), 38 deletions(-) delete mode 100644 .github/pull_request_template.md create mode 100644 SECURITY.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index ad11d490f..000000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,29 +0,0 @@ - -### What does this PR do? - - - -### Motivation - - - -### Reviewer's Checklist - - -- [ ] Changed code has unit tests for its functionality. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3e66cd26..06226ecbc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,73 @@ -### Contributing +## Contributing Thanks for your interest in contributing! This is an open source project, so we appreciate community contributions. -Pull requests for bug fixes are welcome, but before submitting new features or changes to current functionalities open an issue and discuss your ideas or propose the changes you wish to make. After a resolution is reached a PR can be submitted for review. PRs created before a decision has been reached may be closed. +Pull requests for bug fixes are welcome, but before submitting new features or changes to current functionalities +[open an issue][new-issue] and discuss your ideas or propose the changes you wish to make. After a resolution is reached +a PR can be submitted for review. PRs created before a decision has been reached may be closed. -For commit messages, try to use the same conventions as most Go projects, for example: +### License -``` -cmd/orchestrion: add -rm flag to remove instrumentation +Orchestrion is licensed under the [`Apache-2.0` license](/LICENSE). By sumitting a PR to this repository, you are making +the contribution under the terms of the [`Apache-2.0` license](/LICENSE), and that you are authorized to do so. -This commit adds the 'rm' flag to the orchestrion command, which causes -orchestrion to remove any instrumentation from a package. +All files in this repository must include the appropriate `Apache-2.0` license header: +``` +// 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 2023-present Datadog, Inc. ``` -Please apply the same logic for Pull Requests and Issues: start with the package name, followed by a colon and a description of the change, just like the official Go language. +Code that is copied from another repository should be placed in separate files that inly contain code from the same +origin, and that must include the licensing header from the original repository below Datadog's `Apache-2.0` header. +That code must be governed by a license that is compatible with the terms of [`Apache-2.0` license](/LICENSE). + +### Pull Request + +Orchestrion uses the [conventional commits][conventional-commits] specification for commit messages. Pull requests are +squash-merged, and the PR title and body are used as the commit title and message that will land on the `main` branch. + +Please make sure your PR titles follow the [conventional commits][conventional-commits] specification. +In particular, bug fix PR titles should refer to the bug being fixed, not how it is fixed: +- :x: `fix: infer -coverpkg argument if absent` +- :white_check_mark: `fix: link step fails if -cover is used without -coverpkg` + +We expect the PR body for most changes should answer the following questions: +- Why is the change being made? + - For bug fixes, this usually means providing more detail about the bug's root cause + - For enhancements, this means explaining the use-case or added value for the change +- What is the change? + - Explain what's changed in plain english; this will help PR reviewers make sense of the code changes + - Allows people to make sense of the commit without having to read or understand the code + +Link to any relevant GitHub issue (including in other repositories) by using header-style footers in your PR body, e.g: +- `Fixes: #123` - fixes the bug/issue number `123` reported on this repository +- `Depends-On: DataDog/dd-trace-go#456` - depends on issue/PR number `456` in the `DataDog/dd-trace-go` repository + +### Checks + +All automated testing must pass before a PR is eligible for merging. PRs will failing automated tests will not be +reviewed in priority. + +We expect PRs to include new tests for any added or significantly updated functionality; unless existing tests provide +adequate coverage for the changed surface. The CodeCov integration can help you get a sense of what the test coverage +for your change is. Reviewers may request additional tests be added before approving a change. + +### What to expect + +We try to review new PRs within a week or so of creation. If your PR passes all automated tests and has been waiting for +a review for more than a week, feel free to comment on it to bubble it up. + +PRs that have been reviewed and are left open for more than a month awaiting updates or replies by the author may be +closed due to staleness. If you want to resume working on a PR that was closed for staleness at a later point, feel free +to open a new PR. + +### Code Style + +All Go code must be formatted using `go fmt` so that it is in "canonical go format". We run `golangci-lint` as part of +our automated testing suite. -All new code is expected to be covered by tests. + +[new-issue]: https://github.com/DataDog/orchestrion/issues/new/choose +[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/ diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..b20ebdc3e --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,13 @@ +## Security Policy + +### Reporting a Vulnerability + +If you believe you have found a security issue in our code directly, please contact Datadog's security team at +[security@datadoghq.com][mailto] rather than filing a public issue on GitHub. Our security team will get back to you +within 24 hours, usually earlier. The security team's PGP key is available for download at +[`www.datadoghq.com/8869756E.asc.txt`](https://www.datadoghq.com/8869756E.asc.txt) in case you need to encrypt +communications. + +We request that you do not publicly disclose the issue until we had a chance to address it. + +[mailto]: mailto:security@datadoghq.com?subject=[github.com/DataDog/orchestrion]%20Vulnerability%20report From 5875cc23a7964578baf0ca4188f4692ecf21f4f4 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 20 Aug 2024 14:22:55 +0200 Subject: [PATCH 05/13] chore: uniformize integration tests (#228) Name the files appropriately instead of "main", and add the `integration` build constraint to all of them so that `go test ./...` does not waste time building them for nothing. --- .../tests/aws.v1/{main.go => aws.go} | 2 + .../tests/chi.v5/{main.go => chi.go} | 2 + .../tests/dd-span/{main.go => ddspan.go} | 2 + _integration-tests/tests/dd-span/no-tag.go | 2 +- _integration-tests/tests/dd-span/tag.go | 2 +- .../tests/echo.v4/{main.go => echo.go} | 2 + .../tests/fiber.v2/{main.go => fiber.go} | 2 + .../tests/gin/{main.go => gin.go} | 2 + .../go-redis.v7/{main.go => go-redis.go} | 6 ++- .../go-redis.v8/{main.go => go-redis.go} | 6 ++- .../tests/gorm.jinzhu/{main.go => gorm.go} | 2 + .../tests/gorm/{main.go => gorm.go} | 2 + .../tests/grpc/{main.go => grpc.go} | 2 + _integration-tests/tests/grpc/server.go | 39 ++++++++++--------- .../tests/k8s_client_go/common.go | 2 + .../tests/k8s_client_go/new_cfg_func.go | 2 + .../struct_literal_with_param.go | 2 + .../struct_literal_without_param.go | 2 + .../tests/mongo/{main.go => mongo.go} | 2 + .../tests/mux/{main.go => mux.go} | 2 + .../tests/net_http/{main.go => net_http.go} | 2 + .../tests/redigo/{main.go => redigo.go} | 6 ++- .../tests/slog/{main.go => slog.go} | 2 + .../tests/sql/{main.go => sql.go} | 2 + _integration-tests/tests/suite.generated.go | 2 + _integration-tests/tests/suite.go | 2 + .../tests/vault/{main.go => vault.go} | 2 + _integration-tests/utils/generator/main.go | 4 +- 28 files changed, 80 insertions(+), 27 deletions(-) rename _integration-tests/tests/aws.v1/{main.go => aws.go} (99%) rename _integration-tests/tests/chi.v5/{main.go => chi.go} (98%) rename _integration-tests/tests/dd-span/{main.go => ddspan.go} (97%) rename _integration-tests/tests/echo.v4/{main.go => echo.go} (98%) rename _integration-tests/tests/fiber.v2/{main.go => fiber.go} (98%) rename _integration-tests/tests/gin/{main.go => gin.go} (98%) rename _integration-tests/tests/go-redis.v7/{main.go => go-redis.go} (97%) rename _integration-tests/tests/go-redis.v8/{main.go => go-redis.go} (97%) rename _integration-tests/tests/gorm.jinzhu/{main.go => gorm.go} (98%) rename _integration-tests/tests/gorm/{main.go => gorm.go} (98%) rename _integration-tests/tests/grpc/{main.go => grpc.go} (98%) rename _integration-tests/tests/mongo/{main.go => mongo.go} (99%) rename _integration-tests/tests/mux/{main.go => mux.go} (98%) rename _integration-tests/tests/net_http/{main.go => net_http.go} (99%) rename _integration-tests/tests/redigo/{main.go => redigo.go} (97%) rename _integration-tests/tests/slog/{main.go => slog.go} (98%) rename _integration-tests/tests/sql/{main.go => sql.go} (98%) rename _integration-tests/tests/vault/{main.go => vault.go} (98%) diff --git a/_integration-tests/tests/aws.v1/main.go b/_integration-tests/tests/aws.v1/aws.go similarity index 99% rename from _integration-tests/tests/aws.v1/main.go rename to _integration-tests/tests/aws.v1/aws.go index a8013a6c5..0d612f0f6 100644 --- a/_integration-tests/tests/aws.v1/main.go +++ b/_integration-tests/tests/aws.v1/aws.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package awsv1 import ( diff --git a/_integration-tests/tests/chi.v5/main.go b/_integration-tests/tests/chi.v5/chi.go similarity index 98% rename from _integration-tests/tests/chi.v5/main.go rename to _integration-tests/tests/chi.v5/chi.go index 1211f9c15..bd80779b9 100644 --- a/_integration-tests/tests/chi.v5/main.go +++ b/_integration-tests/tests/chi.v5/chi.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package chiv5 import ( diff --git a/_integration-tests/tests/dd-span/main.go b/_integration-tests/tests/dd-span/ddspan.go similarity index 97% rename from _integration-tests/tests/dd-span/main.go rename to _integration-tests/tests/dd-span/ddspan.go index 1e4649a03..c29e06971 100644 --- a/_integration-tests/tests/dd-span/main.go +++ b/_integration-tests/tests/dd-span/ddspan.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package ddspan import ( diff --git a/_integration-tests/tests/dd-span/no-tag.go b/_integration-tests/tests/dd-span/no-tag.go index a58645854..d35be43be 100644 --- a/_integration-tests/tests/dd-span/no-tag.go +++ b/_integration-tests/tests/dd-span/no-tag.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. -//go:build !buildtag +//go:build integration && !buildtag package ddspan diff --git a/_integration-tests/tests/dd-span/tag.go b/_integration-tests/tests/dd-span/tag.go index 3be1fe35b..778dfb5f5 100644 --- a/_integration-tests/tests/dd-span/tag.go +++ b/_integration-tests/tests/dd-span/tag.go @@ -3,7 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. -//go:build buildtag +//go:build integration && buildtag package ddspan diff --git a/_integration-tests/tests/echo.v4/main.go b/_integration-tests/tests/echo.v4/echo.go similarity index 98% rename from _integration-tests/tests/echo.v4/main.go rename to _integration-tests/tests/echo.v4/echo.go index fc6eb60be..5246a8fc6 100644 --- a/_integration-tests/tests/echo.v4/main.go +++ b/_integration-tests/tests/echo.v4/echo.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package echo import ( diff --git a/_integration-tests/tests/fiber.v2/main.go b/_integration-tests/tests/fiber.v2/fiber.go similarity index 98% rename from _integration-tests/tests/fiber.v2/main.go rename to _integration-tests/tests/fiber.v2/fiber.go index d2d4bc652..3b6c1429b 100644 --- a/_integration-tests/tests/fiber.v2/main.go +++ b/_integration-tests/tests/fiber.v2/fiber.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package fiber import ( diff --git a/_integration-tests/tests/gin/main.go b/_integration-tests/tests/gin/gin.go similarity index 98% rename from _integration-tests/tests/gin/main.go rename to _integration-tests/tests/gin/gin.go index 67a6cd633..d74a611a3 100644 --- a/_integration-tests/tests/gin/main.go +++ b/_integration-tests/tests/gin/gin.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package gin import ( diff --git a/_integration-tests/tests/go-redis.v7/main.go b/_integration-tests/tests/go-redis.v7/go-redis.go similarity index 97% rename from _integration-tests/tests/go-redis.v7/main.go rename to _integration-tests/tests/go-redis.v7/go-redis.go index d35b01976..1da3d10f4 100644 --- a/_integration-tests/tests/go-redis.v7/main.go +++ b/_integration-tests/tests/go-redis.v7/go-redis.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package goredis import ( @@ -33,9 +35,9 @@ func (tc *TestCase) Setup(t *testing.T) { ctx := context.Background() var err error - tc.server, err = testredis.RunContainer(ctx, + tc.server, err = testredis.Run(ctx, + "redis:7", testcontainers.WithLogger(testcontainers.TestLogger(t)), - testcontainers.WithImage("redis:7"), utils.WithTestLogConsumer(t), testcontainers.WithWaitStrategy( wait.ForAll( diff --git a/_integration-tests/tests/go-redis.v8/main.go b/_integration-tests/tests/go-redis.v8/go-redis.go similarity index 97% rename from _integration-tests/tests/go-redis.v8/main.go rename to _integration-tests/tests/go-redis.v8/go-redis.go index decf01fe0..4744a9fc3 100644 --- a/_integration-tests/tests/go-redis.v8/main.go +++ b/_integration-tests/tests/go-redis.v8/go-redis.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package goredis import ( @@ -33,9 +35,9 @@ func (tc *TestCase) Setup(t *testing.T) { ctx := context.Background() var err error - tc.server, err = testredis.RunContainer(ctx, + tc.server, err = testredis.Run(ctx, + "redis:7", testcontainers.WithLogger(testcontainers.TestLogger(t)), - testcontainers.WithImage("redis:7"), utils.WithTestLogConsumer(t), testcontainers.WithWaitStrategy( wait.ForAll( diff --git a/_integration-tests/tests/gorm.jinzhu/main.go b/_integration-tests/tests/gorm.jinzhu/gorm.go similarity index 98% rename from _integration-tests/tests/gorm.jinzhu/main.go rename to _integration-tests/tests/gorm.jinzhu/gorm.go index 0c120ece1..54c5b6de4 100644 --- a/_integration-tests/tests/gorm.jinzhu/main.go +++ b/_integration-tests/tests/gorm.jinzhu/gorm.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package gorm import ( diff --git a/_integration-tests/tests/gorm/main.go b/_integration-tests/tests/gorm/gorm.go similarity index 98% rename from _integration-tests/tests/gorm/main.go rename to _integration-tests/tests/gorm/gorm.go index c473efa04..14a6727ff 100644 --- a/_integration-tests/tests/gorm/main.go +++ b/_integration-tests/tests/gorm/gorm.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package gorm import ( diff --git a/_integration-tests/tests/grpc/main.go b/_integration-tests/tests/grpc/grpc.go similarity index 98% rename from _integration-tests/tests/grpc/main.go rename to _integration-tests/tests/grpc/grpc.go index 21d85121b..71ee52c05 100644 --- a/_integration-tests/tests/grpc/main.go +++ b/_integration-tests/tests/grpc/grpc.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package grpc import ( diff --git a/_integration-tests/tests/grpc/server.go b/_integration-tests/tests/grpc/server.go index c62165a91..4c9a86f29 100644 --- a/_integration-tests/tests/grpc/server.go +++ b/_integration-tests/tests/grpc/server.go @@ -2,27 +2,30 @@ // under the Apache License Version 2.0. // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. - +// +// // This file was copied from the grpc-go repository at https://github.com/grpc/grpc-go // This file is published according to the Apache License Version 2.0 and copyright is // held by gRPC authors as detailed in the license below: -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ +// +// +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// + +//go:build integration package grpc diff --git a/_integration-tests/tests/k8s_client_go/common.go b/_integration-tests/tests/k8s_client_go/common.go index 574759334..02b1ea6e7 100644 --- a/_integration-tests/tests/k8s_client_go/common.go +++ b/_integration-tests/tests/k8s_client_go/common.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package k8sclientgo import ( diff --git a/_integration-tests/tests/k8s_client_go/new_cfg_func.go b/_integration-tests/tests/k8s_client_go/new_cfg_func.go index f2f1f018e..d39258578 100644 --- a/_integration-tests/tests/k8s_client_go/new_cfg_func.go +++ b/_integration-tests/tests/k8s_client_go/new_cfg_func.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package k8sclientgo import ( diff --git a/_integration-tests/tests/k8s_client_go/struct_literal_with_param.go b/_integration-tests/tests/k8s_client_go/struct_literal_with_param.go index 6d8b240d8..897d8c00c 100644 --- a/_integration-tests/tests/k8s_client_go/struct_literal_with_param.go +++ b/_integration-tests/tests/k8s_client_go/struct_literal_with_param.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package k8sclientgo import ( diff --git a/_integration-tests/tests/k8s_client_go/struct_literal_without_param.go b/_integration-tests/tests/k8s_client_go/struct_literal_without_param.go index 716e35de6..5593e93dd 100644 --- a/_integration-tests/tests/k8s_client_go/struct_literal_without_param.go +++ b/_integration-tests/tests/k8s_client_go/struct_literal_without_param.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package k8sclientgo import ( diff --git a/_integration-tests/tests/mongo/main.go b/_integration-tests/tests/mongo/mongo.go similarity index 99% rename from _integration-tests/tests/mongo/main.go rename to _integration-tests/tests/mongo/mongo.go index 925a79927..e67c81e9f 100644 --- a/_integration-tests/tests/mongo/main.go +++ b/_integration-tests/tests/mongo/mongo.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package mongo import ( diff --git a/_integration-tests/tests/mux/main.go b/_integration-tests/tests/mux/mux.go similarity index 98% rename from _integration-tests/tests/mux/main.go rename to _integration-tests/tests/mux/mux.go index 8adfe511b..fd0b1a781 100644 --- a/_integration-tests/tests/mux/main.go +++ b/_integration-tests/tests/mux/mux.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package mux import ( diff --git a/_integration-tests/tests/net_http/main.go b/_integration-tests/tests/net_http/net_http.go similarity index 99% rename from _integration-tests/tests/net_http/main.go rename to _integration-tests/tests/net_http/net_http.go index bf93147cb..6a8476a58 100644 --- a/_integration-tests/tests/net_http/main.go +++ b/_integration-tests/tests/net_http/net_http.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package nethttp import ( diff --git a/_integration-tests/tests/redigo/main.go b/_integration-tests/tests/redigo/redigo.go similarity index 97% rename from _integration-tests/tests/redigo/main.go rename to _integration-tests/tests/redigo/redigo.go index 8369f95e4..4aa35a335 100644 --- a/_integration-tests/tests/redigo/main.go +++ b/_integration-tests/tests/redigo/redigo.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package redigo import ( @@ -32,9 +34,9 @@ func (tc *TestCase) Setup(t *testing.T) { ctx := context.Background() var err error - tc.server, err = testredis.RunContainer(ctx, + tc.server, err = testredis.Run(ctx, + "redis:7", testcontainers.WithLogger(testcontainers.TestLogger(t)), - testcontainers.WithImage("redis:7"), utils.WithTestLogConsumer(t), testcontainers.WithWaitStrategy( wait.ForAll( diff --git a/_integration-tests/tests/slog/main.go b/_integration-tests/tests/slog/slog.go similarity index 98% rename from _integration-tests/tests/slog/main.go rename to _integration-tests/tests/slog/slog.go index 7788b41c6..2e9f75caa 100644 --- a/_integration-tests/tests/slog/main.go +++ b/_integration-tests/tests/slog/slog.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package slog import ( diff --git a/_integration-tests/tests/sql/main.go b/_integration-tests/tests/sql/sql.go similarity index 98% rename from _integration-tests/tests/sql/main.go rename to _integration-tests/tests/sql/sql.go index 32a997c0b..bec94ecc3 100644 --- a/_integration-tests/tests/sql/main.go +++ b/_integration-tests/tests/sql/sql.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package sql import ( diff --git a/_integration-tests/tests/suite.generated.go b/_integration-tests/tests/suite.generated.go index 92a1b7ba1..5dbf0295c 100644 --- a/_integration-tests/tests/suite.generated.go +++ b/_integration-tests/tests/suite.generated.go @@ -5,6 +5,8 @@ // // Code generated by 'go generate'; DO NOT EDIT. +//go:build integration + package tests import ( diff --git a/_integration-tests/tests/suite.go b/_integration-tests/tests/suite.go index 17579a5d4..103a41590 100644 --- a/_integration-tests/tests/suite.go +++ b/_integration-tests/tests/suite.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package tests import ( diff --git a/_integration-tests/tests/vault/main.go b/_integration-tests/tests/vault/vault.go similarity index 98% rename from _integration-tests/tests/vault/main.go rename to _integration-tests/tests/vault/vault.go index 364c32e5a..7baa6297d 100644 --- a/_integration-tests/tests/vault/main.go +++ b/_integration-tests/tests/vault/vault.go @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2023-present Datadog, Inc. +//go:build integration + package vault import ( diff --git a/_integration-tests/utils/generator/main.go b/_integration-tests/utils/generator/main.go index 98f1bc8c5..71355431c 100644 --- a/_integration-tests/utils/generator/main.go +++ b/_integration-tests/utils/generator/main.go @@ -45,7 +45,9 @@ func main() { file.HeaderComment("This product includes software developed at Datadog (https://www.datadoghq.com/).") file.HeaderComment("Copyright 2023-present Datadog, Inc.") file.HeaderComment("") - file.HeaderComment(fmt.Sprintf("Code generated by 'go generate'; DO NOT EDIT.")) + file.HeaderComment("Code generated by 'go generate'; DO NOT EDIT.") + + file.Comment("//go:build integration") entries, err := os.ReadDir(root) if err != nil { From 97384a53edff43794f667e587e69e01e7078476f Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Tue, 20 Aug 2024 15:50:22 +0200 Subject: [PATCH 06/13] fix(goflags): using `-cover` causes fingerprint mismatch (#230) In order to properly convey coverage flags to child processes when doing injected package resolution, it is important the `-cover` flags only applies to packages selected for instrumentation by the user, otherwise some packages may be instrumented or not instrumented depending on whether they are directly resolved or a transitive dependency of a directly resolved package; and this leads to link-time fingerprint mismatches. This implies we must make the default value of `-coverpkg` explicit if it is not provided by the user. --- internal/ensure/requiredversion_test.go | 3 +- internal/goenv/gobin.go | 24 ++++ internal/goenv/gobin_test.go | 18 +++ internal/goflags/flags.go | 147 ++++++++++++++++++++---- internal/goflags/flags_test.go | 88 +++++++++++--- internal/goflags/quoted/quoted.go | 63 ++++++++++ internal/goflags/quoted/quoted_test.go | 59 ++++++++++ internal/goproxy/dashc.go | 45 ++++++++ internal/goproxy/proxy.go | 54 +++------ 9 files changed, 423 insertions(+), 78 deletions(-) create mode 100644 internal/goenv/gobin.go create mode 100644 internal/goenv/gobin_test.go create mode 100644 internal/goflags/quoted/quoted.go create mode 100644 internal/goflags/quoted/quoted_test.go create mode 100644 internal/goproxy/dashc.go diff --git a/internal/ensure/requiredversion_test.go b/internal/ensure/requiredversion_test.go index d1e0abcff..8f44e499c 100644 --- a/internal/ensure/requiredversion_test.go +++ b/internal/ensure/requiredversion_test.go @@ -16,6 +16,7 @@ import ( "sync/atomic" "testing" + "github.com/datadog/orchestrion/internal/goenv" "github.com/datadog/orchestrion/internal/version" "github.com/stretchr/testify/require" ) @@ -80,7 +81,7 @@ func TestGoModVersion(t *testing.T) { } func TestRequiredVersion(t *testing.T) { - goBin, err := exec.LookPath("go") + goBin, err := goenv.GoBinPath() require.NoError(t, err, "could not resolve go command path") testError := errors.New("simulated failure") diff --git a/internal/goenv/gobin.go b/internal/goenv/gobin.go new file mode 100644 index 000000000..4487ad3e1 --- /dev/null +++ b/internal/goenv/gobin.go @@ -0,0 +1,24 @@ +// 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 2023-present Datadog, Inc. + +package goenv + +import "os/exec" + +var goBinPath string + +// GoBinPath returns the resolved path to the `go` command's binary. The result is cached to avoid +// looking it up multiple times. If the lookup fails, the error is returned and the result is not +// cached. +func GoBinPath() (string, error) { + if goBinPath == "" { + goBin, err := exec.LookPath("go") + if err != nil { + return "", err + } + goBinPath = goBin + } + return goBinPath, nil +} diff --git a/internal/goenv/gobin_test.go b/internal/goenv/gobin_test.go new file mode 100644 index 000000000..3b8e72857 --- /dev/null +++ b/internal/goenv/gobin_test.go @@ -0,0 +1,18 @@ +// 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 2023-present Datadog, Inc. + +package goenv + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func Test(t *testing.T) { + path, err := GoBinPath() + require.NoError(t, err) + t.Logf("GOBIN: %s", path) +} diff --git a/internal/goflags/flags.go b/internal/goflags/flags.go index ab1c4e6f7..1f4abee4e 100644 --- a/internal/goflags/flags.go +++ b/internal/goflags/flags.go @@ -15,8 +15,11 @@ import ( "strings" "sync" - "github.com/datadog/orchestrion/internal/goproxy" + "github.com/datadog/orchestrion/internal/goenv" + "github.com/datadog/orchestrion/internal/goflags/quoted" + "github.com/datadog/orchestrion/internal/log" "github.com/shirou/gopsutil/v3/process" + "golang.org/x/tools/go/packages" ) // CommandFlags represents the flags provided to a go command invocation @@ -87,16 +90,66 @@ func (f CommandFlags) Slice() []string { } // ParseCommandFlags parses a slice representing a go command invocation -// and returns its flags. Direct arguments to the command are ignored -func ParseCommandFlags(args []string) CommandFlags { +// and returns its flags. Direct arguments to the command are ignored. The value +// of $GOFLAGS is also included in the returned flags. +func ParseCommandFlags(wd string, args []string) (CommandFlags, error) { flags := CommandFlags{ - Long: make(map[string]string, len(args)), - Short: make(map[string]struct{}, len(args)), + Long: make(map[string]string, len(longFlags)), + Short: make(map[string]struct{}, len(shortFlags)), } + goflags := os.Getenv("GOFLAGS") + goflagsArgs, err := quoted.Split(goflags) + if err != nil { + log.Warnf("Failed to interpreted quoted strings in GOFLAGS=%q: %v\n", goflags, err) + } else { + log.Tracef("GOFLAGS arguments: %q\n", goflagsArgs) + } + + // Remove any `-C` flag provided on the command line. This is required to immediately follow the `go` command, and + // can be present only once. + if len(args) > 0 { + if arg := args[0]; strings.HasPrefix(arg, "-C") { + if arg == "-C" && len(args) > 1 { + // ["-C", "directory", ...] + log.Tracef("Skipping -C %q flag\n", args[1]) + args = args[2:] + } else if arg[:3] == "-C=" { + // ["-C=directory", ...] + log.Tracef("Skipping %q flag\n", arg) + args = args[1:] + } + } + } + + // The next argument after a `-C` (if present) would be the go command name ("run", "test", "list", etc...). This is + // not interesting for our purposes, so we skip it. + if len(args) > 0 { + log.Tracef("The go command is %q\n", args[0]) + args = args[1:] + } + + // Compose the complete list of arguments: those from GOFLAGS, and the rest of the command line so far; in this order + // as the CLI arguments have precedence over those from GOFLAGS. + args = append(append(make([]string, 0, len(goflagsArgs)+len(args)), goflagsArgs...), args...) + + var positional []string for i := 0; i < len(args); i += 1 { arg := args[i] + // Any argument after "--" is a positional argument, so we are done parsing. + if arg == "--" { + positional = args[i+1:] + break + } + + // Any argument without a leading "-" is a positional argument, and the go CLI demands all flags are placed before + // positional arguments, so we are done parsing. + if !strings.HasPrefix(arg, "-") { + positional = args[i:] + break + } + normArg := arg if strings.HasPrefix(arg, "--") { // The Go CLI accepts flags with two hyphens instead of one, but we want @@ -104,10 +157,12 @@ func ParseCommandFlags(args []string) CommandFlags { normArg = arg[1:] } - if isAssigned(normArg) { - key, val, found := strings.Cut(normArg, "=") - if found { + if key, val, isAssigned := strings.Cut(normArg, "="); isAssigned { + if isLong(key) { flags.Long[key] = val + } else { + // Intentionally the un-normalized variant in Unknown flags. + flags.Unknown = append(flags.Unknown, arg) } } else if isLong(normArg) { flags.Long[normArg] = args[i+1] @@ -115,12 +170,52 @@ func ParseCommandFlags(args []string) CommandFlags { } else if isShort(normArg) { flags.Short[normArg] = struct{}{} } else { - // We intentionally keep the original arg value in this case instead of the normalized one. + // Intentionally the un-normalized variant in Unknown flags. flags.Unknown = append(flags.Unknown, arg) + // If there's more args, and the next one does not have a leading -, we'll assume this is the value of this + // unknown flag and consume it. + if len(args) > i && !strings.HasPrefix(args[i+1], "-") { + flags.Unknown = append(flags.Unknown, args[i+1]) + i++ + } } } - return flags + return flags, flags.inferCoverpkg(wd, positional) +} + +// inferCoverpkg will add the necessary `-coverpkg` argument if the `-cover` flags is present and `-coverpkg` is not, as +// otherwise, sub-commands triggered with these flags will not apply coverage to the intended packages. +func (f *CommandFlags) inferCoverpkg(wd string, positionalArgs []string) error { + if _, hasCoverpkg := f.Long["-coverpkg"]; hasCoverpkg { + return nil + } + if _, isCover := f.Short["-cover"]; !isCover { + return nil + } + + pkgs, err := packages.Load( + &packages.Config{ + Mode: packages.NeedName, + Dir: wd, + BuildFlags: append(f.Slice(), "-toolexec"), // Make sure we satisfy the same build constraints; but don't run -toolexec + Logf: func(format string, args ...any) { log.Tracef(format+"\n", args...) }, + }, + positionalArgs..., + ) + if err != nil { + return fmt.Errorf("failed to resolve package list from %q: %w", positionalArgs, err) + } + + coverpkg := make([]string, len(pkgs)) + for i, pkg := range pkgs { + coverpkg[i] = pkg.PkgPath + } + val := strings.Join(coverpkg, ",") + log.Tracef("Inferred -coverpkg=%q from %q\n", val, positionalArgs) + f.Long["-coverpkg"] = val + + return nil } // Flags return the top level go command flags @@ -131,13 +226,12 @@ func Flags() (CommandFlags, error) { return flags, flagsErr } -func isAssigned(str string) bool { - if !strings.HasPrefix(str, "-") { - return false - } - flag, _, ok := strings.Cut(str, "=") - // An assigned flag is a long flag using the '=' separator - return ok && isLong(flag) +// SetFlags sets the flags for this process to those parsed from the provided +// slice. Does nothing if SetFlags or Flags has already been called once. +func SetFlags(wd string, args []string) { + once.Do(func() { + flags, flagsErr = ParseCommandFlags(wd, args) + }) } func isLong(str string) bool { @@ -153,14 +247,14 @@ func isShort(str string) bool { // parentGoCommandFlags backtracks through the process tree // to find a parent go command invocation and returns its arguments func parentGoCommandFlags() (flags CommandFlags, err error) { - goBin, err := goproxy.GoBin() + goBin, err := goenv.GoBinPath() if err != nil { - return flags, err + return flags, fmt.Errorf("failed to resolve go command path: %w", err) } p, err := process.NewProcess(int32(os.Getpid())) if err != nil { - return flags, err + return flags, fmt.Errorf("failed to get handle of the current process: %w", err) } // Backtrack through the process stack until we find the parent Go command @@ -168,15 +262,15 @@ func parentGoCommandFlags() (flags CommandFlags, err error) { for { p, err = p.Parent() if err != nil { - return flags, err + return flags, fmt.Errorf("failed to find parent process of %d: %w", p.Pid, err) } args, err = p.CmdlineSlice() if err != nil { - return flags, err + return flags, fmt.Errorf("failed to get command line of %d: %w", p.Pid, err) } cmd, err := exec.LookPath(args[0]) if err != nil { - return flags, err + return flags, fmt.Errorf("failed to resolve argv0 (%q) of %d: %w", args[0], p.Pid, err) } // Found the go command process, break out of backtracking if cmd == goBin { @@ -184,7 +278,12 @@ func parentGoCommandFlags() (flags CommandFlags, err error) { } } - return ParseCommandFlags(args[2:]), nil + wd, err := p.Cwd() + if err != nil { + return flags, fmt.Errorf("failed to get working directory of %d: %w", p.Pid, err) + } + + return ParseCommandFlags(wd, args[2:]) } var ( diff --git a/internal/goflags/flags_test.go b/internal/goflags/flags_test.go index 7298f4215..b1d5ecaf8 100644 --- a/internal/goflags/flags_test.go +++ b/internal/goflags/flags_test.go @@ -6,9 +6,12 @@ package goflags import ( + "path/filepath" "reflect" + "runtime" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -44,47 +47,98 @@ func TestTrim(t *testing.T) { } func TestParse(t *testing.T) { + _, thisFile, _, _ := runtime.Caller(0) + thisDir := filepath.Dir(thisFile) + for name, tc := range map[string]struct { flags []string + goflags string expected CommandFlags }{ "short": { - flags: []string{"-short1", "--short2"}, + flags: []string{"run", "-short1", "--short2"}, expected: CommandFlags{Short: map[string]struct{}{"-short1": {}, "-short2": {}}}, }, "long": { - flags: []string{"-long1", "longval1", "--long2", "longval2"}, + flags: []string{"run", "-long1", "longval1", "--long2", "longval2"}, expected: CommandFlags{Long: map[string]string{"-long1": "longval1", "-long2": "longval2"}}, }, "long-assigned": { - flags: []string{"-long1=longval1", "--long2=longval2"}, + flags: []string{"run", "-long1=longval1", "--long2=longval2"}, expected: CommandFlags{Long: map[string]string{"-long1": "longval1", "-long2": "longval2"}}, }, "long-mixed": { - flags: []string{"-long1=longval1", "-long2", "longval2"}, + flags: []string{"run", "-long1=longval1", "-long2", "longval2"}, expected: CommandFlags{Long: map[string]string{"-long1": "longval1", "-long2": "longval2"}}, }, "special": { - flags: []string{"-gcflags", "-N -l -other", "-ldflags", "-extldflags '-lm -lstdc++ -static'"}, + flags: []string{"run", "-gcflags", "-N -l -other", "-ldflags", "-extldflags '-lm -lstdc++ -static'"}, expected: CommandFlags{ Long: map[string]string{"-gcflags": "-N -l -other", "-ldflags": "-extldflags '-lm -lstdc++ -static'"}, }, }, "combined": { - flags: []string{"-short1", "-gcflags", "-N -l -other", "-ldflags", "-extldflags '-lm -lstdc++ -static'", "-long1=longval1", "-short2", "-long2", "longval2"}, + flags: []string{"run", "-short1", "-gcflags", "-N -l -other", "-ldflags", "-extldflags '-lm -lstdc++ -static'", "-long1=longval1", "-short2", "-long2", "longval2"}, expected: CommandFlags{ Long: map[string]string{"-gcflags": "-N -l -other", "-ldflags": "-extldflags '-lm -lstdc++ -static'", "-long1": "longval1", "-long2": "longval2"}, Short: map[string]struct{}{"-short1": {}, "-short2": {}}, }, }, "combined-and-unknown": { - flags: []string{"unknown1", "-short1", "-long1=longval1", "unknown2", "-short2", "-long2", "longval2", "unknown3"}, + flags: []string{"run", "-unknown1", "-short1", "-long1=longval1", "-unknown2", "-short2", "-long2", "longval2", "unknown3"}, expected: CommandFlags{ Long: map[string]string{"-long1": "longval1", "-long2": "longval2"}, Short: map[string]struct{}{"-short1": {}, "-short2": {}}, }, }, + "cover": { + flags: []string{"run", "-cover", "-covermode=atomic"}, + expected: CommandFlags{ + Long: map[string]string{"-covermode": "atomic", "-coverpkg": "github.com/datadog/orchestrion/internal/goflags"}, + Short: map[string]struct{}{"-cover": {}}, + }, + }, + "cover-with-coverpkg": { + flags: []string{"run", "-cover", "-covermode=atomic", "--", "-some.go"}, + goflags: "-coverpkg=std", + expected: CommandFlags{ + Long: map[string]string{"-covermode": "atomic", "-coverpkg": "std"}, + Short: map[string]struct{}{"-cover": {}}, + }, + }, + "cover-dash-c": { + flags: []string{"-C", "..", "run", "-cover", "-covermode=atomic"}, + expected: CommandFlags{ + // Note - the "-C" flags has no effect at this stage, so it's expected coverpkg is this package. + Long: map[string]string{"-covermode": "atomic", "-coverpkg": "github.com/datadog/orchestrion/internal/goflags"}, + Short: map[string]struct{}{"-cover": {}}, + }, + }, + "cover-dash-c-alt": { + flags: []string{"-C=..", "run", "-cover", "-covermode=atomic", "."}, + expected: CommandFlags{ + // Note - the "-C" flags has no effect at this stage, so it's expected coverpkg is this package. + Long: map[string]string{"-covermode": "atomic", "-coverpkg": "github.com/datadog/orchestrion/internal/goflags"}, + Short: map[string]struct{}{"-cover": {}}, + }, + }, + "goflags": { + flags: []string{"run", "."}, + goflags: "-cover -covermode=atomic -tags=integration '-toolexec=foo bar'", + expected: CommandFlags{ + Long: map[string]string{"-covermode": "atomic", "-coverpkg": "github.com/datadog/orchestrion/internal/goflags", "-tags": "integration", "-toolexec": "foo bar"}, + Short: map[string]struct{}{"-cover": {}}, + }, + }, } { + // Make sure the expected outcomes are non-nil, makes it easier to validate afterwards. + if tc.expected.Short == nil { + tc.expected.Short = map[string]struct{}{} + } + if tc.expected.Long == nil { + tc.expected.Long = map[string]string{} + } + t.Run(name, func(t *testing.T) { defer restore(shortFlags, longFlags) shortFlags = tc.expected.Short @@ -93,17 +147,19 @@ func TestParse(t *testing.T) { longFlags[flag] = struct{}{} } - flags := ParseCommandFlags(tc.flags) - if len(tc.expected.Short) > 0 { - require.True(t, reflect.DeepEqual(tc.expected.Short, flags.Short)) + t.Setenv("GOFLAGS", tc.goflags) + flags, err := ParseCommandFlags(thisDir, tc.flags) + require.NoError(t, err) + + if flags.Short == nil { + flags.Short = map[string]struct{}{} } - if len(tc.expected.Long) > 0 { - require.True(t, reflect.DeepEqual(tc.expected.Long, flags.Long)) - for key, val := range tc.expected.Long { - actual, _ := flags.Get(key) - require.Equal(t, val, actual) - } + assert.True(t, reflect.DeepEqual(tc.expected.Short, flags.Short), "expected:\n%#v\nactual:\n%#v", tc.expected.Short, flags.Short) + + if flags.Long == nil { + flags.Long = map[string]string{} } + assert.True(t, reflect.DeepEqual(tc.expected.Long, flags.Long), "expected:\n%#v\nactual:\n%#v", tc.expected.Long, flags.Long) }) } } diff --git a/internal/goflags/quoted/quoted.go b/internal/goflags/quoted/quoted.go new file mode 100644 index 000000000..b71d574cb --- /dev/null +++ b/internal/goflags/quoted/quoted.go @@ -0,0 +1,63 @@ +// 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 2023-present Datadog, Inc. + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package quoted provides string manipulation utilities. This is elements +// copied from the go command's internals: +// https://github.com/golang/go/blob/go1.23rc2/src/cmd/go/internal/base/goflags.go +package quoted + +import ( + "fmt" +) + +func isSpaceByte(c byte) bool { + return c == ' ' || c == '\t' || c == '\n' || c == '\r' +} + +// Split splits s into a list of fields, +// allowing single or double quotes around elements. +// There is no unescaping or other processing within +// quoted fields. +// +// Keep in sync with cmd/dist/quoted.go +func Split(s string) ([]string, error) { + // Split fields allowing '' or "" around elements. + // Quotes further inside the string do not count. + var f []string + for len(s) > 0 { + for len(s) > 0 && isSpaceByte(s[0]) { + s = s[1:] + } + if len(s) == 0 { + break + } + // Accepted quoted string. No unescaping inside. + if s[0] == '"' || s[0] == '\'' { + quote := s[0] + s = s[1:] + i := 0 + for i < len(s) && s[i] != quote { + i++ + } + if i >= len(s) { + return nil, fmt.Errorf("unterminated %c string", quote) + } + f = append(f, s[:i]) + s = s[i+1:] + continue + } + i := 0 + for i < len(s) && !isSpaceByte(s[i]) { + i++ + } + f = append(f, s[:i]) + s = s[i:] + } + return f, nil +} diff --git a/internal/goflags/quoted/quoted_test.go b/internal/goflags/quoted/quoted_test.go new file mode 100644 index 000000000..60491f293 --- /dev/null +++ b/internal/goflags/quoted/quoted_test.go @@ -0,0 +1,59 @@ +// 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 2023-present Datadog, Inc. + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package quoted + +import ( + "reflect" + "strings" + "testing" +) + +func TestSplit(t *testing.T) { + for _, test := range []struct { + name string + value string + want []string + wantErr string + }{ + {name: "empty", value: "", want: nil}, + {name: "space", value: " ", want: nil}, + {name: "one", value: "a", want: []string{"a"}}, + {name: "leading_space", value: " a", want: []string{"a"}}, + {name: "trailing_space", value: "a ", want: []string{"a"}}, + {name: "two", value: "a b", want: []string{"a", "b"}}, + {name: "two_multi_space", value: "a b", want: []string{"a", "b"}}, + {name: "two_tab", value: "a\tb", want: []string{"a", "b"}}, + {name: "two_newline", value: "a\nb", want: []string{"a", "b"}}, + {name: "quote_single", value: `'a b'`, want: []string{"a b"}}, + {name: "quote_double", value: `"a b"`, want: []string{"a b"}}, + {name: "quote_both", value: `'a '"b "`, want: []string{"a ", "b "}}, + {name: "quote_contains", value: `'a "'"'b"`, want: []string{`a "`, `'b`}}, + {name: "escape", value: `\'`, want: []string{`\'`}}, + {name: "quote_unclosed", value: `'a`, wantErr: "unterminated ' string"}, + } { + t.Run(test.name, func(t *testing.T) { + got, err := Split(test.value) + if err != nil { + if test.wantErr == "" { + t.Fatalf("unexpected error: %v", err) + } else if errMsg := err.Error(); !strings.Contains(errMsg, test.wantErr) { + t.Fatalf("error %q does not contain %q", errMsg, test.wantErr) + } + return + } + if test.wantErr != "" { + t.Fatalf("unexpected success; wanted error containing %q", test.wantErr) + } + if !reflect.DeepEqual(got, test.want) { + t.Errorf("got %q; want %q", got, test.want) + } + }) + } +} diff --git a/internal/goproxy/dashc.go b/internal/goproxy/dashc.go new file mode 100644 index 000000000..7bed8b874 --- /dev/null +++ b/internal/goproxy/dashc.go @@ -0,0 +1,45 @@ +// 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 2023-present Datadog, Inc. + +package goproxy + +import ( + "os" + "strings" + + "github.com/datadog/orchestrion/internal/log" +) + +// ProcessDashC gets the command line arguments passed to a "go" command (without "go" itself), and processes the "-C" +// flag present at the beginning of the slice (if present), changing directories as requested, then returns the slice +// without it. +// +// The "-C" flags is reuqired to be the very first argument provided to "go" commands. +func ProcessDashC(args []string) ([]string, error) { + if len(args) == 0 { + return nil, nil + } + + arg0 := args[0] + if !strings.HasPrefix(arg0, "-C") { + return args, nil + } + + if arg0 == "-C" && len(args) > 1 { + // ["-C", "directory", ...] + log.Tracef("Found -C %q flag, changing directory\n", args[1]) + return args[2:], os.Chdir(args[1]) + } + + if !strings.HasPrefix(arg0, "-C=") { + // Probably not the flag we're looking for... ignoring that... + log.Tracef("Ignoring unknown flag with -C prefix: %q\n", arg0) + return args, nil + } + + // ["-C=directory", ...] + log.Tracef("Found %q flag, changing directory\n", arg0) + return args[1:], os.Chdir(arg0[3:]) +} diff --git a/internal/goproxy/proxy.go b/internal/goproxy/proxy.go index b5a4154ee..7d286320f 100644 --- a/internal/goproxy/proxy.go +++ b/internal/goproxy/proxy.go @@ -11,6 +11,8 @@ import ( "os/exec" "strings" + "github.com/datadog/orchestrion/internal/goenv" + "github.com/datadog/orchestrion/internal/goflags" "github.com/datadog/orchestrion/internal/jobserver" "github.com/datadog/orchestrion/internal/jobserver/client" "github.com/datadog/orchestrion/internal/log" @@ -48,16 +50,21 @@ func WithToolexec(bin string, args ...string) Option { } } -// Run takes a go directive (go build, go install, etc...) and applies -// changes specified through opts to the command before running it in a -// different process +// Run takes a go command ("build", "install", etc...) with its arguments, and +// applies changes specified through opts to the command before running it in a +// different process. func Run(goArgs []string, opts ...Option) error { var cfg config for _, opt := range opts { opt(&cfg) } - goBin, err := GoBin() + goArgs, err := ProcessDashC(goArgs) + if err != nil { + return err + } + + goBin, err := goenv.GoBinPath() if err != nil { return fmt.Errorf("locating 'go' binary: %w", err) } @@ -73,20 +80,7 @@ func Run(goArgs []string, opts ...Option) error { env := os.Environ() if len(argv) > 1 { - // The command may not be at index 0, if the `-C` flag is used (it is REQUIRED to occur first - // before anything else on the go command) - cmdIdx := 1 - for { - if cmdIdx+2 < len(argv) && argv[cmdIdx] == "-C" { - cmdIdx += 2 - } else if cmdIdx+1 < len(argv) && strings.HasPrefix(argv[cmdIdx], "-C") { - cmdIdx++ - } else { - break - } - } - - switch cmd := argv[cmdIdx]; cmd { + switch cmd := argv[1]; cmd { // "go build" arguments are shared by build, clean, get, install, list, run, and test. case "build", "clean", "get", "install", "list", "run", "test": if cfg.toolexec != "" { @@ -96,10 +90,10 @@ func Run(goArgs []string, opts ...Option) error { // Add two slots to the argV array argv = append(argv, "", "") // Move all values after the cmdIdx 2 slots forward - copy(argv[cmdIdx+3:], argv[cmdIdx+1:oldLen]) + copy(argv[4:], argv[2:oldLen]) // Fill in the two slots for toolexec. - argv[cmdIdx+1] = "-toolexec" - argv[cmdIdx+2] = cfg.toolexec + argv[2] = "-toolexec" + argv[3] = cfg.toolexec // We'll need a job server to support toolexec operations server, err := jobserver.New(&jobserver.Options{ServerName: fmt.Sprintf("orchestrion[%d]", os.Getpid())}) @@ -111,6 +105,8 @@ func Run(goArgs []string, opts ...Option) error { log.Tracef("[JOBSERVER]: %s\n", server.CacheStats.String()) }() env = append(env, fmt.Sprintf("%s=%s", client.ENV_VAR_JOBSERVER_URL, server.ClientURL())) + // Set the process' goflags, since we know them already... + goflags.SetFlags("", argv[1:]) } } } @@ -130,19 +126,3 @@ func Run(goArgs []string, opts ...Option) error { return nil } - -var goBinPath string - -// GoBin returns the resolved path to the `go` command's binary. The result is cached to avoid -// looking it up multiple times. If the lookup fails, the error is returned and the result is not -// cached. -func GoBin() (string, error) { - if goBinPath == "" { - goBin, err := exec.LookPath("go") - if err != nil { - return "", err - } - goBinPath = goBin - } - return goBinPath, nil -} From df291cf8ca3af58957eb42f68911774c2e2cd5ea Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 21 Aug 2024 15:42:02 +0200 Subject: [PATCH 07/13] chore(deps): bump github/codeql-action from 3.26.2 to 3.26.3 (#235) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.2 to 3.26.3.
Changelog

Sourced from github/codeql-action's changelog.

CodeQL Action Changelog

See the releases page for the relevant changes to the CodeQL CLI and language packs.

Note that the only difference between v2 and v3 of the CodeQL Action is the node version they support, with v3 running on node 20 while we continue to release v2 to support running on node 16. For example 3.22.11 was the first v3 release and is functionally identical to 2.22.11. This approach ensures an easy way to track exactly which features are included in different versions, indicated by the minor and patch version numbers.

[UNRELEASED]

No user facing changes.

3.26.3 - 19 Aug 2024

  • Fix an issue where the CodeQL Action could not write diagnostic messages on Windows. This issue did not impact analysis quality. #2430

3.26.2 - 14 Aug 2024

  • Update default CodeQL bundle version to 2.18.2. #2417

3.26.1 - 13 Aug 2024

No user facing changes.

3.26.0 - 06 Aug 2024

  • Deprecation: Swift analysis on Ubuntu runner images is no longer supported. Please migrate to a macOS runner if this affects you. #2403
  • Bump the minimum CodeQL bundle version to 2.13.5. #2408

3.25.15 - 26 Jul 2024

  • Update default CodeQL bundle version to 2.18.1. #2385

3.25.14 - 25 Jul 2024

  • Experimental: add a new start-proxy action which starts the same HTTP proxy as used by github/dependabot-action. Do not use this in production as it is part of an internal experiment and subject to change at any time. #2376

3.25.13 - 19 Jul 2024

  • Add codeql-version to outputs. #2368
  • Add a deprecation warning for customers using CodeQL version 2.13.4 and earlier. These versions of CodeQL were discontinued on 9 July 2024 alongside GitHub Enterprise Server 3.9, and will be unsupported by CodeQL Action versions 3.26.0 and later and versions 2.26.0 and later. #2375
    • If you are using one of these versions, please update to CodeQL CLI version 2.13.5 or later. For instance, if you have specified a custom version of the CLI using the 'tools' input to the 'init' Action, you can remove this input to use the default version.
    • Alternatively, if you want to continue using a version of the CodeQL CLI between 2.12.6 and 2.13.4, you can replace github/codeql-action/*@v3 by github/codeql-action/*@v3.25.13 and github/codeql-action/*@v2 by github/codeql-action/*@v2.25.13 in your code scanning workflow to ensure you continue using this version of the CodeQL Action.

3.25.12 - 12 Jul 2024

  • Improve the reliability and performance of analyzing code when analyzing a compiled language with the autobuild build mode on GitHub Enterprise Server. This feature is already available to GitHub.com users. #2353
  • Update default CodeQL bundle version to 2.18.0. #2364

3.25.11 - 28 Jun 2024

  • Avoid failing the workflow run if there is an error while uploading debug artifacts. #2349

... (truncated)

Commits
  • 883d858 Merge pull request #2431 from github/update-v3.26.3-b187c86ce
  • e100ceb Update changelog for v3.26.3
  • b187c86 Merge pull request #2430 from github/henrymercer/windows-diagnostics-fix
  • e2bb5a2 Add changelog note
  • e5a6587 Fix writing diagnostics on Windows
  • 5c681ef Merge pull request #2426 from github/mergeback/v3.26.2-to-main-429e1977
  • 676519a Update checked-in dependencies
  • 25a5b8f Update changelog and version after v3.26.2
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github/codeql-action&package-manager=github_actions&previous-version=3.26.2&new-version=3.26.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ossf-scorecard.yml | 2 +- .github/workflows/sast.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ossf-scorecard.yml b/.github/workflows/ossf-scorecard.yml index 1eccf4e71..9d55751c1 100644 --- a/.github/workflows/ossf-scorecard.yml +++ b/.github/workflows/ossf-scorecard.yml @@ -43,6 +43,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3 + uses: github/codeql-action/upload-sarif@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 with: sarif_file: results.sarif diff --git a/.github/workflows/sast.yml b/.github/workflows/sast.yml index 4a41c31a7..eef65c05a 100644 --- a/.github/workflows/sast.yml +++ b/.github/workflows/sast.yml @@ -34,12 +34,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3 + uses: github/codeql-action/init@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 with: languages: go build-mode: autobuild - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@429e1977040da7a23b6822b13c129cd1ba93dbb2 # v3 + uses: github/codeql-action/analyze@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 with: category: "/language:go" From 0922cdc3509073e7102ee77ec766b9803114b0f2 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 22 Aug 2024 10:21:10 +0200 Subject: [PATCH 08/13] fix: GLS slot not cleaned up after goroutine exits (#232) ### What does this PR do? Specifically `nil` out the GLS slot when the goroutine exits, so that the underlying map can be GC'd and it is not incorrectly re-used by the next goroutine if that g is recycled from the gf list. ### Motivation The GLS slot was not reset to nil when the goroutine exits, causing the old context to be re- used whenever the g object was recycled from the free list. --- _integration-tests/tests/aws.v1/aws.go | 2 +- internal/injector/builtin/generated.go | 16 +++++++++++++++- .../injector/builtin/yaml/stdlib/runtime.yml | 12 ++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/_integration-tests/tests/aws.v1/aws.go b/_integration-tests/tests/aws.v1/aws.go index 0d612f0f6..147e90c38 100644 --- a/_integration-tests/tests/aws.v1/aws.go +++ b/_integration-tests/tests/aws.v1/aws.go @@ -36,7 +36,7 @@ func (tc *TestCase) Setup(t *testing.T) { ContainerRequest: testcontainers.ContainerRequest{ Image: "amazon/dynamodb-local:latest", ExposedPorts: []string{port}, - WaitingFor: wait.ForListeningPort(nat.Port(port)), + WaitingFor: wait.ForHTTP("").WithStatusCodeMatcher(func(int) bool { return true }), Name: "dynamodb-local", WorkingDir: "/home/dynamodblocal", Cmd: []string{ diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 1c95de0ba..6f8a55d10 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -677,6 +677,20 @@ var Aspects = [...]aspect.Aspect{ ), []string{}), }, }, + { + JoinPoint: join.AllOf( + join.ImportPath("runtime"), + join.FunctionBody(join.Function( + join.Name("goexit1"), + )), + ), + Advice: []advice.Advice{ + advice.PrependStmts(code.MustTemplate( + "getg().__dd_gls = nil", + map[string]string{}, + )), + }, + }, // From stdlib/slog.yml { JoinPoint: join.FunctionCall("log/slog.New"), @@ -764,4 +778,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:wbkfjDjV3+GQ36tmhe3yOJDfllvuJ8Tt8Q6WjcsZyNbP2JLK5IKQU5+Ns5PTdZJiwCZ0BnRyCwYSOV/rx9aNzQ==" +const Checksum = "sha512:quSpwHxYELyo6rzgDKUOgR3cGbimB2ugq8b2cpxX20EKOfflQSJNqnerpjjBn61LOb6MTf0Gk9E8LbJfRtHOSA==" diff --git a/internal/injector/builtin/yaml/stdlib/runtime.yml b/internal/injector/builtin/yaml/stdlib/runtime.yml index 2a7912a25..4a4ec096d 100644 --- a/internal/injector/builtin/yaml/stdlib/runtime.yml +++ b/internal/injector/builtin/yaml/stdlib/runtime.yml @@ -34,3 +34,15 @@ aspects: var __dd_orchestrion_gls_set = func(val any) { getg().m.curg.__dd_gls = val } + - id: Clear GLS slot on goroutine exit + join-point: + all-of: + - import-path: runtime + - function-body: + function: + # This is the function that finishes the execution of a goroutine. + # See: https://github.com/golang/go/blob/f38d42f2c4c6ad0d7cbdad5e1417cac3be2a5dcb/src/runtime/proc.go#L4264 + - name: goexit1 + advice: + - prepend-statements: + template: getg().__dd_gls = nil From 4420b75bde03df72967705bcca38e78b6fa2c72e Mon Sep 17 00:00:00 2001 From: Nick Ripley Date: Thu, 22 Aug 2024 06:25:59 -0400 Subject: [PATCH 09/13] fix: apply `//dd:orchestrion-enabled` to tracer-internal modules (#223) ### What does this PR do? The //dd:orchestrion-enabled directive aspect is currently not applied to tracer-internal modules. dd-trace-go will rely on this directive to detect whether it was built with Orchestrion. So, set "tracer-internal: true" for the directive. Nothing seems to be broken right now. I'm not sure the best way to test this, at least in this PR. I'm working on an integration test for the profiler when built with Orchestrion. Once that's up and running, it will break if the profiler relies on the directive to add Orchestrion-related info. And presumably once we start relying on goroutine-local storage for context, stuff will break if the directive doesn't work in dd-trace-go? ### Motivation I happened to notice this was broken while trying to add Orchestrion-related information to the profiler uploads. The `internal/orchestrion.Enabled` function in dd-trace-go was always returning false, even when built with Orchestrion. ### Reviewer's Checklist - [ ] Changed code has unit tests for its functionality. --------- Co-authored-by: Romain Marcadier --- _integration-tests/go.mod | 2 +- _integration-tests/go.sum | 4 +-- _integration-tests/tests/redigo/redigo.go | 34 +++++++++---------- go.mod | 2 +- go.sum | 4 +-- internal/injector/builtin/generated.go | 3 +- .../yaml/directive/orchestrion-enabled.yml | 1 + samples/go.mod | 2 +- samples/go.sum | 4 +-- 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/_integration-tests/go.mod b/_integration-tests/go.mod index 74aacdd69..26addc651 100644 --- a/_integration-tests/go.mod +++ b/_integration-tests/go.mod @@ -33,7 +33,7 @@ require ( go.mongodb.org/mongo-driver v1.16.1 google.golang.org/grpc v1.65.0 google.golang.org/grpc/examples v0.0.0-20240816220358-f8d98a477c22 - gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 + gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 gorm.io/driver/sqlite v1.5.6 gorm.io/gorm v1.25.11 gotest.tools/v3 v3.5.1 diff --git a/_integration-tests/go.sum b/_integration-tests/go.sum index 54ee60712..710e8728d 100644 --- a/_integration-tests/go.sum +++ b/_integration-tests/go.sum @@ -1326,8 +1326,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 h1:SmWlCDNk5b+Nf+UuyM9B62QTpBOdm4zpEX96LUHEkVY= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3/go.mod h1:m7ZoVxmeBmoKm3ogbgIagIs+kxKy5Nm7Fl2XM8FbQDw= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 h1:3Cb46zyKIlEWac21tvDF2O4KyMlOHQxrQkyiaUpdwM0= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0/go.mod h1:6DdiJPKOeJfZyd/IUGCAd5elY8qPGkztK6wbYYsMjag= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/_integration-tests/tests/redigo/redigo.go b/_integration-tests/tests/redigo/redigo.go index 4aa35a335..99183a96c 100644 --- a/_integration-tests/tests/redigo/redigo.go +++ b/_integration-tests/tests/redigo/redigo.go @@ -121,23 +121,23 @@ func (tc *TestCase) ExpectedTraces() trace.Spans { "span.kind": "client", }, }, - }, - }, - { - Tags: map[string]any{ - "resource": "redigo.Conn.Flush", - "type": "redis", - "name": "redis.command", - "service": "redis.conn", - }, - Meta: map[string]any{ - "redis.raw_command": "", - "db.system": "redis", - "component": "gomodule/redigo", - "out.network": "tcp", - "out.host": "localhost", - "redis.args_length": "0", - "span.kind": "client", + { + Tags: map[string]any{ + "resource": "redigo.Conn.Flush", + "type": "redis", + "name": "redis.command", + "service": "redis.conn", + }, + Meta: map[string]any{ + "redis.raw_command": "", + "db.system": "redis", + "component": "gomodule/redigo", + "out.network": "tcp", + "out.host": "localhost", + "redis.args_length": "0", + "span.kind": "client", + }, + }, }, }, } diff --git a/go.mod b/go.mod index c5edf3496..665c81f78 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( golang.org/x/sys v0.24.0 golang.org/x/term v0.23.0 golang.org/x/tools v0.24.0 - gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 + gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 gopkg.in/yaml.v3 v3.0.1 gotest.tools/v3 v3.5.1 k8s.io/client-go v0.31.0 diff --git a/go.sum b/go.sum index ed24ae945..043de4720 100644 --- a/go.sum +++ b/go.sum @@ -1230,8 +1230,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 h1:SmWlCDNk5b+Nf+UuyM9B62QTpBOdm4zpEX96LUHEkVY= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3/go.mod h1:m7ZoVxmeBmoKm3ogbgIagIs+kxKy5Nm7Fl2XM8FbQDw= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 h1:3Cb46zyKIlEWac21tvDF2O4KyMlOHQxrQkyiaUpdwM0= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0/go.mod h1:6DdiJPKOeJfZyd/IUGCAd5elY8qPGkztK6wbYYsMjag= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/injector/builtin/generated.go b/internal/injector/builtin/generated.go index 6f8a55d10..72d3efe95 100644 --- a/internal/injector/builtin/generated.go +++ b/internal/injector/builtin/generated.go @@ -262,6 +262,7 @@ var Aspects = [...]aspect.Aspect{ map[string]string{}, )), }, + TracerInternal: true, }, // From go-main.yml { @@ -778,4 +779,4 @@ var InjectedPaths = [...]string{ } // Checksum is a checksum of the built-in configuration which can be used to invalidate caches. -const Checksum = "sha512:quSpwHxYELyo6rzgDKUOgR3cGbimB2ugq8b2cpxX20EKOfflQSJNqnerpjjBn61LOb6MTf0Gk9E8LbJfRtHOSA==" +const Checksum = "sha512:1rr045miszvEWzw89RRL9FrGL4Mcg8d0JiSadIuBOAr8luZKk2kImnlnYuP4XTYRGqaSd+HUJDy9NBVtLjL43A==" diff --git a/internal/injector/builtin/yaml/directive/orchestrion-enabled.yml b/internal/injector/builtin/yaml/directive/orchestrion-enabled.yml index 885a9465f..89c36fcc0 100644 --- a/internal/injector/builtin/yaml/directive/orchestrion-enabled.yml +++ b/internal/injector/builtin/yaml/directive/orchestrion-enabled.yml @@ -14,6 +14,7 @@ meta: generally be avoided. aspects: - id: Initialize to true + tracer-internal: true # This is safe to apply in the tracer itself. join-point: all-of: - directive: dd:orchestrion-enabled diff --git a/samples/go.mod b/samples/go.mod index 43fb22c38..a67fab95f 100644 --- a/samples/go.mod +++ b/samples/go.mod @@ -295,7 +295,7 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/protobuf v1.34.2 // indirect - gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 // indirect + gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect howett.net/plist v1.0.1 // indirect diff --git a/samples/go.sum b/samples/go.sum index 56327a008..a3d55ed4a 100644 --- a/samples/go.sum +++ b/samples/go.sum @@ -1231,8 +1231,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3 h1:SmWlCDNk5b+Nf+UuyM9B62QTpBOdm4zpEX96LUHEkVY= -gopkg.in/DataDog/dd-trace-go.v1 v1.67.0-rc.3/go.mod h1:m7ZoVxmeBmoKm3ogbgIagIs+kxKy5Nm7Fl2XM8FbQDw= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0 h1:3Cb46zyKIlEWac21tvDF2O4KyMlOHQxrQkyiaUpdwM0= +gopkg.in/DataDog/dd-trace-go.v1 v1.67.0/go.mod h1:6DdiJPKOeJfZyd/IUGCAd5elY8qPGkztK6wbYYsMjag= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 2faf2a294630f6c42ce3dbc3ef4e8cef400e25e2 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Thu, 22 Aug 2024 16:26:12 +0200 Subject: [PATCH 10/13] release: v0.7.4 (#237) Release v0.7.4 or Orchestrion. --- internal/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/version/version.go b/internal/version/version.go index 6a6f621cf..7797b6ede 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -6,4 +6,4 @@ package version // Tag specifies the current release tag. It needs to be manually updated. -const Tag = "v0.7.4-rc.2" +const Tag = "v0.7.4" From 824132f77c393815d2c05365d899b854e0b60707 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Fri, 23 Aug 2024 10:24:50 +0200 Subject: [PATCH 11/13] docs: mention new integrations in README.md (#239) --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dc8347d79..d742267ff 100644 --- a/README.md +++ b/README.md @@ -191,8 +191,12 @@ Library | Since | Notes `gorm.io/gorm` | `v0.7.0` | [Aspect][gorm] `net/http` | `v0.7.0` | [Client][net-http.client] / [Server][net-http.server] `go.mongodb.org/mongo-driver/mongo` | `v0.7.3` | [Aspect][mongo] -`k8s.io/client-go` | `v0.7.4` | [Aspect][k8s-client] +`github.com/aws-sdk-go/aws` | `v0.7.4` | [Aspect][aws-sdk-go] `github.com/hashicorp/vault` | `v0.7.4` | [Aspect][hashicorp-vault] +`github.com/IBM/sarama` | `v0.7.4` | [Aspect][ibm-sarama] +`github.com/Shopify/sarama` | `v0.7.4` | [Aspect][shopify-sarama] +`k8s.io/client-go` | `v0.7.4` | [Aspect][k8s-client] +`log/slog` | `v0.7.4` | [Aspect][log-slog] [db-sql]: https://datadoghq.dev/orchestrion/docs/built-in/stdlib/database-sql/ [gin]: https://datadoghq.dev/orchestrion/docs/built-in/http/gin/ @@ -212,6 +216,10 @@ Library | Since | Notes [mongo]: https://datadoghq.dev/orchestrion/docs/built-in/databases/mongo/ [k8s-client]: https://datadoghq.dev/orchestrion/docs/built-in/k8s-client/ [hashicorp-vault]: https://datadoghq.dev/orchestrion/docs/built-in/api/vault/ +[log-slog]: https://datadoghq.dev/orchestrion/docs/built-in/stdlib/slog/ +[aws-sdk-go]: https://datadoghq.dev/orchestrion/docs/built-in/cloud/aws-sdk/ +[ibm-sarama]: https://datadoghq.dev/orchestrion/docs/built-in/datastreams/ibm_sarama/ +[shopify-sarama]: https://datadoghq.dev/orchestrion/docs/built-in/datastreams/shopify_sarama/ Calls to these libraries are instrumented with library-specific code adding tracing to them, including support for distributed traces. From 3c2972b5a4c76c58c0ed6045cb78ff5ceb3871f9 Mon Sep 17 00:00:00 2001 From: Romain Marcadier Date: Fri, 23 Aug 2024 12:09:40 +0200 Subject: [PATCH 12/13] feat: improved line information preservation (#231) Use a new and improved method to preserve line information from the original source file into the modified AST; by comparing information about original nodes in the decorator's view with those in the restorer's. This ensures better correspondance, emits fewer line directives, and shoudl result in better debugging experience on instrumented code. --- internal/goflags/flags.go | 2 +- .../builtin/testdata/client/aws.go.snap | 6 +- .../builtin/testdata/client/gorm.go.snap | 8 +- .../builtin/testdata/client/grpc.go.snap | 5 +- .../builtin/testdata/client/http.go.snap | 32 ++-- .../testdata/client/ibm_sarama.go.snap | 6 +- .../builtin/testdata/client/main.go.snap | 5 +- .../builtin/testdata/client/mongo.go.snap | 7 +- .../builtin/testdata/client/redis.go.snap | 11 +- .../testdata/client/shopify_sarama.go.snap | 6 +- .../builtin/testdata/client/vault.go.snap | 13 +- .../builtin/testdata/server/chiv5.go.snap | 10 +- .../builtin/testdata/server/database.go.snap | 3 +- .../builtin/testdata/server/echov4.go.snap | 11 +- .../builtin/testdata/server/fiberv2.go.snap | 7 +- .../builtin/testdata/server/gin.go.snap | 7 +- .../builtin/testdata/server/gorilla.go.snap | 6 +- .../builtin/testdata/server/grpc.go.snap | 5 +- .../testdata/server/ibm_sarama.go.snap | 15 +- .../builtin/testdata/server/main.go.snap | 7 +- .../testdata/server/other_handlers.go.snap | 48 ++---- .../testdata/server/shopify_sarama.go.snap | 15 +- internal/injector/injector.go | 101 ++--------- internal/injector/lineinfo/annotation.go | 160 ++++++++++++++++++ internal/injector/lineinfo/canonicalize.go | 72 ++++++++ internal/injector/lineinfo/lineinfo.go | 50 ++++++ .../chi5-newroute-dotimport/expected.diff | 13 +- .../injector/chi5-newroute/expected.diff | 13 +- .../injector/database-sql/expected.diff | 10 +- .../testdata/injector/directive/expected.diff | 10 +- .../testdata/injector/grpc/expected.diff | 14 +- .../injector/http-line-info/expected.diff | 13 +- .../injector/http-server/expected.diff | 11 +- .../injector/name-conflict/expected.diff | 7 +- .../testdata/injector/redigo/expected.diff | 12 +- internal/toolexec/aspect/oncompile.go | 14 -- 36 files changed, 476 insertions(+), 259 deletions(-) create mode 100644 internal/injector/lineinfo/annotation.go create mode 100644 internal/injector/lineinfo/canonicalize.go create mode 100644 internal/injector/lineinfo/lineinfo.go diff --git a/internal/goflags/flags.go b/internal/goflags/flags.go index 1f4abee4e..9b3d48eba 100644 --- a/internal/goflags/flags.go +++ b/internal/goflags/flags.go @@ -174,7 +174,7 @@ func ParseCommandFlags(wd string, args []string) (CommandFlags, error) { flags.Unknown = append(flags.Unknown, arg) // If there's more args, and the next one does not have a leading -, we'll assume this is the value of this // unknown flag and consume it. - if len(args) > i && !strings.HasPrefix(args[i+1], "-") { + if len(args) > i+1 && !strings.HasPrefix(args[i+1], "-") { flags.Unknown = append(flags.Unknown, args[i+1]) i++ } diff --git a/internal/injector/builtin/testdata/client/aws.go.snap b/internal/injector/builtin/testdata/client/aws.go.snap index ad6bfd413..d2d978aff 100644 --- a/internal/injector/builtin/testdata/client/aws.go.snap +++ b/internal/injector/builtin/testdata/client/aws.go.snap @@ -1,3 +1,4 @@ +//line samples/client/aws.go:1:1 // 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/). @@ -9,7 +10,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" -//line :1 +//line __orchestrion_awstrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/aws/aws-sdk-go/aws" ) @@ -17,7 +18,7 @@ import ( func AWSClientV1() { cfg := aws.NewConfig().WithRegion("us-west-2") sess := session.Must( -//line :1 +//line func(sess *session.Session, err error) (*session.Session, error) { if sess != nil { sess = __orchestrion_awstrace.WrapSession(sess) @@ -27,7 +28,6 @@ func AWSClientV1() { //line samples/client/aws.go:16 session.NewSession(cfg))) -//line samples/client/aws.go:18 s3api := s3.New(sess) s3api.CreateBucket(&s3.CreateBucketInput{ Bucket: aws.String("shiny-bucket"), diff --git a/internal/injector/builtin/testdata/client/gorm.go.snap b/internal/injector/builtin/testdata/client/gorm.go.snap index 2837bb105..a6e987bbe 100644 --- a/internal/injector/builtin/testdata/client/gorm.go.snap +++ b/internal/injector/builtin/testdata/client/gorm.go.snap @@ -1,3 +1,4 @@ +//line samples/client/gorm.go:1:1 // 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/). @@ -5,6 +6,7 @@ package main +//line samples/client/gorm.go:10 import ( "log" @@ -13,7 +15,7 @@ import ( "gorm.io/gorm" _ "github.com/mattn/go-sqlite3" -//line :1 +//line __orchestrion_sql "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" __orchestrion_gorm "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorm.io/gorm.v1" __orchestrion_gormtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/jinzhu/gorm" @@ -41,12 +43,12 @@ func gormClient() { func jinzhuGormClient() { db, err := -//line :1 +//line func() (*jinzhu.DB, error) { db, err := //line samples/client/gorm.go:39 jinzhu.Open("sqlite3", "file::memory:?cache=shared") -//line :1 +//line if err != nil { return nil, err } diff --git a/internal/injector/builtin/testdata/client/grpc.go.snap b/internal/injector/builtin/testdata/client/grpc.go.snap index d91990d1e..6e8bd2252 100644 --- a/internal/injector/builtin/testdata/client/grpc.go.snap +++ b/internal/injector/builtin/testdata/client/grpc.go.snap @@ -1,3 +1,4 @@ +//line samples/client/grpc.go:1:1 // 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/). @@ -9,14 +10,14 @@ import ( "log" "google.golang.org/grpc" -//line :1 +//line __orchestrion_grpctrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/google.golang.org/grpc" ) //line samples/client/grpc.go:14 func grpcClient() { conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), -//line :1 +//line grpc.WithStreamInterceptor(__orchestrion_grpctrace.StreamClientInterceptor()), grpc.WithUnaryInterceptor(__orchestrion_grpctrace.UnaryClientInterceptor())) //line samples/client/grpc.go:16 if err != nil { diff --git a/internal/injector/builtin/testdata/client/http.go.snap b/internal/injector/builtin/testdata/client/http.go.snap index c5c84eaf9..e52b02c27 100644 --- a/internal/injector/builtin/testdata/client/http.go.snap +++ b/internal/injector/builtin/testdata/client/http.go.snap @@ -1,3 +1,4 @@ +//line samples/client/http.go:1:1 // 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/). @@ -11,58 +12,51 @@ import ( "net/http" "net/url" "strings" -//line :1 +//line __orchestrion_instrument "github.com/datadog/orchestrion/instrument/net/http" ) //line samples/client/http.go:16 -func shortHandsWithContext( -//line :1 - _arg_0 context. //line samples/client/http.go:16 - Context) { +func shortHandsWithContext(_arg_0 context.Context) { resp, err := -//line :1 +//line __orchestrion_instrument.Get( _arg_0, //line samples/client/http.go:17 "http://localhost:8080") -//line samples/client/http.go:18 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.Head( _arg_0, //line samples/client/http.go:23 "http://localhost:8080") -//line samples/client/http.go:24 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.Post( _arg_0, //line samples/client/http.go:29 "http://localhost:8080", "text/plain", strings.NewReader("Body")) -//line samples/client/http.go:30 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.PostForm( _arg_0, //line samples/client/http.go:35 "http://localhost:8080", url.Values{"key": {"value"}}) -//line samples/client/http.go:36 if err != nil { log.Fatal(err) } @@ -71,48 +65,44 @@ func shortHandsWithContext( func shortHandsWithRequest(_arg_0 *http.Request /* for context */) { resp, err := -//line :1 +//line __orchestrion_instrument.Get( _arg_0.Context(), //line samples/client/http.go:43 "http://localhost:8080") -//line samples/client/http.go:44 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.Head( _arg_0.Context(), //line samples/client/http.go:49 "http://localhost:8080") -//line samples/client/http.go:50 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.Post( _arg_0.Context(), //line samples/client/http.go:55 "http://localhost:8080", "text/plain", strings.NewReader("Body")) -//line samples/client/http.go:56 if err != nil { log.Fatal(err) } resp.Body.Close() resp, err = -//line :1 +//line __orchestrion_instrument.PostForm( _arg_0.Context(), //line samples/client/http.go:61 "http://localhost:8080", url.Values{"key": {"value"}}) -//line samples/client/http.go:62 if err != nil { log.Fatal(err) } diff --git a/internal/injector/builtin/testdata/client/ibm_sarama.go.snap b/internal/injector/builtin/testdata/client/ibm_sarama.go.snap index d9ef6bde6..08f7ea619 100644 --- a/internal/injector/builtin/testdata/client/ibm_sarama.go.snap +++ b/internal/injector/builtin/testdata/client/ibm_sarama.go.snap @@ -1,3 +1,4 @@ +//line samples/client/ibm_sarama.go:1:1 // 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/). @@ -8,7 +9,7 @@ package main import ( "github.com/IBM/sarama" -//line :1 +//line __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1" ) @@ -16,7 +17,7 @@ import ( func ibmSaramaConsumer() { cfg := sarama.NewConfig() consumer, err := -//line :1 +//line func(c sarama.Consumer, err error) (sarama.Consumer, error) { if c != nil { c = __orchestrion_saramatrace.WrapConsumer(c) @@ -25,7 +26,6 @@ func ibmSaramaConsumer() { }( //line samples/client/ibm_sarama.go:12 sarama.NewConsumer([]string{"localhost:9092"}, cfg)) -//line samples/client/ibm_sarama.go:13 if err != nil { panic(err) } diff --git a/internal/injector/builtin/testdata/client/main.go.snap b/internal/injector/builtin/testdata/client/main.go.snap index 50abdf68e..8fc6e9a8b 100644 --- a/internal/injector/builtin/testdata/client/main.go.snap +++ b/internal/injector/builtin/testdata/client/main.go.snap @@ -1,3 +1,4 @@ +//line samples/client/main.go:1:1 // 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/). @@ -13,7 +14,7 @@ import ( "os" "strings" "time" -//line :1 +//line __orchestrion_tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" __orchestrion_profiler "gopkg.in/DataDog/dd-trace-go.v1/profiler" __orchestrion_log "log" @@ -21,7 +22,7 @@ import ( //line samples/client/main.go:18 func main() { -//line :1 +//line { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) defer __orchestrion_tracer.Stop() diff --git a/internal/injector/builtin/testdata/client/mongo.go.snap b/internal/injector/builtin/testdata/client/mongo.go.snap index 1b0b79fe3..951ebdbdc 100644 --- a/internal/injector/builtin/testdata/client/mongo.go.snap +++ b/internal/injector/builtin/testdata/client/mongo.go.snap @@ -1,3 +1,4 @@ +//line samples/client/mongo.go:1:1 // 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/). @@ -11,7 +12,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" -//line :1 +//line __orchestrion_mongotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go.mongodb.org/mongo-driver/mongo" ) @@ -19,10 +20,10 @@ import ( func mongoClient() { ctx := context.Background() opts := -//line :1 +//line //line samples/client/mongo.go:18 options.Client(). -//line :1 +//line SetMonitor(__orchestrion_mongotrace.NewMonitor()). //line samples/client/mongo.go:18 ApplyURI("mongodb://localhost:27017") diff --git a/internal/injector/builtin/testdata/client/redis.go.snap b/internal/injector/builtin/testdata/client/redis.go.snap index 633677743..ec82e1823 100644 --- a/internal/injector/builtin/testdata/client/redis.go.snap +++ b/internal/injector/builtin/testdata/client/redis.go.snap @@ -1,3 +1,4 @@ +//line samples/client/redis.go:1:1 // 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/). @@ -12,7 +13,7 @@ import ( redisv7 "github.com/go-redis/redis/v7" redisv8 "github.com/go-redis/redis/v8" redigo "github.com/gomodule/redigo/redis" -//line :1 +//line __orchestrion_trace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v7" __orchestrion_trace1 "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-redis/redis.v8" __orchestrion_redigo "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" @@ -21,12 +22,12 @@ import ( //line samples/client/redis.go:17 func redisV7Client() { client := -//line :1 +//line func() (client *redisv7.Client) { client = //line samples/client/redis.go:18 redisv7.NewClient(&redisv7.Options{Addr: "127.0.0.1", Password: "", DB: 0}) -//line :1 +//line __orchestrion_trace.WrapClient(client) return }() @@ -39,12 +40,12 @@ func redisV7Client() { func redisV8Client(ctx context.Context) { client := -//line :1 +//line func() (client *redisv8.Client) { client = //line samples/client/redis.go:26 redisv8.NewClient(&redisv8.Options{Addr: "127.0.0.1", Password: "", DB: 0}) -//line :1 +//line __orchestrion_trace1.WrapClient(client) return }() diff --git a/internal/injector/builtin/testdata/client/shopify_sarama.go.snap b/internal/injector/builtin/testdata/client/shopify_sarama.go.snap index 94b528f4f..8140dde30 100644 --- a/internal/injector/builtin/testdata/client/shopify_sarama.go.snap +++ b/internal/injector/builtin/testdata/client/shopify_sarama.go.snap @@ -1,3 +1,4 @@ +//line samples/client/shopify_sarama.go:1:1 // 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/). @@ -8,7 +9,7 @@ package main import ( "github.com/Shopify/sarama" -//line :1 +//line __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" ) @@ -16,7 +17,7 @@ import ( func shopifySaramaConsumer() { cfg := sarama.NewConfig() consumer, err := -//line :1 +//line func(c sarama.Consumer, err error) (sarama.Consumer, error) { if c != nil { c = __orchestrion_saramatrace.WrapConsumer(c) @@ -25,7 +26,6 @@ func shopifySaramaConsumer() { }( //line samples/client/shopify_sarama.go:12 sarama.NewConsumer([]string{"localhost:9092"}, cfg)) -//line samples/client/shopify_sarama.go:13 if err != nil { panic(err) } diff --git a/internal/injector/builtin/testdata/client/vault.go.snap b/internal/injector/builtin/testdata/client/vault.go.snap index eff4eec0e..db29b139e 100644 --- a/internal/injector/builtin/testdata/client/vault.go.snap +++ b/internal/injector/builtin/testdata/client/vault.go.snap @@ -1,3 +1,4 @@ +//line samples/client/vault.go:1:1 // 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/). @@ -9,18 +10,18 @@ import ( "net/http" "github.com/hashicorp/vault/api" -//line :1 +//line __orchestrion_vaulttrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/hashicorp/vault" ) //line samples/client/vault.go:14 func vaultClient() { c, err := api.NewClient(& -//line :1 +//line //line samples/client/vault.go:15 api.Config{ Address: "http://vault.mydomain.com:8200", -//line :1 +//line HttpClient: __orchestrion_vaulttrace.NewHTTPClient(), }) //line samples/client/vault.go:18 @@ -32,17 +33,15 @@ func vaultClient() { func vaultProvidedClient() { c, err := api.NewClient(& -//line :1 +//line //line samples/client/vault.go:25 api.Config{ -//line :1 +//line HttpClient: __orchestrion_vaulttrace.WrapHTTPClient( //line samples/client/vault.go:26 &http.Client{}), -//line samples/client/vault.go:27 Address: "http://vault.mydomain.com:8200", }) -//line samples/client/vault.go:29 if err != nil { panic(err) } diff --git a/internal/injector/builtin/testdata/server/chiv5.go.snap b/internal/injector/builtin/testdata/server/chiv5.go.snap index bd9b3a603..7a806afc9 100644 --- a/internal/injector/builtin/testdata/server/chiv5.go.snap +++ b/internal/injector/builtin/testdata/server/chiv5.go.snap @@ -1,3 +1,4 @@ +//line samples/server/chiv5.go:1:1 // 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/). @@ -9,7 +10,7 @@ import ( "net/http" "github.com/go-chi/chi/v5" -//line :1 +//line __orchestrion_instrument "github.com/datadog/orchestrion/instrument" __orchestrion_chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5" ) @@ -17,23 +18,22 @@ import ( //line samples/server/chiv5.go:14 func chiV5Server() { router := -//line :1 +//line func() *chi.Mux { mux := //line samples/server/chiv5.go:15 chi.NewRouter() -//line :1 +//line mux.Use(__orchestrion_chitrace.Middleware()) return mux }() //line samples/server/chiv5.go:16 router.Get("/", -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/chiv5.go:16 func(w http.ResponseWriter, _ *http.Request) { w.Write([]byte("Hello World!\n")) })) -//line samples/server/chiv5.go:19 http.ListenAndServe(":8080", router) } diff --git a/internal/injector/builtin/testdata/server/database.go.snap b/internal/injector/builtin/testdata/server/database.go.snap index 8279a51f8..5ec346ed4 100644 --- a/internal/injector/builtin/testdata/server/database.go.snap +++ b/internal/injector/builtin/testdata/server/database.go.snap @@ -1,3 +1,4 @@ +//line samples/server/database.go:1:1 // 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/). @@ -11,7 +12,7 @@ import ( "database/sql/driver" "fmt" "log" -//line :1 +//line __orchestrion_sql "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" ) diff --git a/internal/injector/builtin/testdata/server/echov4.go.snap b/internal/injector/builtin/testdata/server/echov4.go.snap index aa3f026ea..c2ec55500 100644 --- a/internal/injector/builtin/testdata/server/echov4.go.snap +++ b/internal/injector/builtin/testdata/server/echov4.go.snap @@ -1,3 +1,4 @@ +//line samples/server/echov4.go:1:1 // 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/). @@ -9,19 +10,19 @@ import ( "net/http" "github.com/labstack/echo/v4" -//line :1 +//line __orchestrion_echotrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/labstack/echo.v4" ) //line samples/server/echov4.go:14 func echoV4Server() { r := -//line :1 +//line func() *echo.Echo { e := //line samples/server/echov4.go:15 echo.New() -//line :1 +//line e.Use(__orchestrion_echotrace.Middleware()) return e }() @@ -40,12 +41,12 @@ type api struct { func (a *api) echoV4Server() { a.srv = -//line :1 +//line func() *echo.Echo { e := //line samples/server/echov4.go:29 echo.New() -//line :1 +//line e.Use(__orchestrion_echotrace.Middleware()) return e }() diff --git a/internal/injector/builtin/testdata/server/fiberv2.go.snap b/internal/injector/builtin/testdata/server/fiberv2.go.snap index 5d5d277a6..010071a03 100644 --- a/internal/injector/builtin/testdata/server/fiberv2.go.snap +++ b/internal/injector/builtin/testdata/server/fiberv2.go.snap @@ -1,3 +1,4 @@ +//line samples/server/fiberv2.go:1:1 // 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/). @@ -7,19 +8,19 @@ package main import ( "github.com/gofiber/fiber/v2" -//line :1 +//line __orchestrion_fibertrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gofiber/fiber.v2" ) //line samples/server/fiberv2.go:12 func fiberV2Server() { r := -//line :1 +//line func() *fiber.App { app := //line samples/server/fiberv2.go:13 fiber.New() -//line :1 +//line app.Use(__orchestrion_fibertrace.Middleware()) return app }() diff --git a/internal/injector/builtin/testdata/server/gin.go.snap b/internal/injector/builtin/testdata/server/gin.go.snap index b373aebc5..9543b034a 100644 --- a/internal/injector/builtin/testdata/server/gin.go.snap +++ b/internal/injector/builtin/testdata/server/gin.go.snap @@ -1,3 +1,4 @@ +//line samples/server/gin.go:1:1 // 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/). @@ -9,19 +10,19 @@ import ( "net/http" "github.com/gin-gonic/gin" -//line :1 +//line __orchestrion_gintrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gin-gonic/gin" ) //line samples/server/gin.go:14 func ginServer() { r := -//line :1 +//line func() *gin.Engine { e := //line samples/server/gin.go:15 gin.Default() -//line :1 +//line e.Use(__orchestrion_gintrace.Middleware("")) return e }() diff --git a/internal/injector/builtin/testdata/server/gorilla.go.snap b/internal/injector/builtin/testdata/server/gorilla.go.snap index 2cc4e174d..60f2a01ec 100644 --- a/internal/injector/builtin/testdata/server/gorilla.go.snap +++ b/internal/injector/builtin/testdata/server/gorilla.go.snap @@ -1,3 +1,4 @@ +//line samples/server/gorilla.go:1:1 // 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/). @@ -10,7 +11,7 @@ import ( "net/http" "github.com/gorilla/mux" -//line :1 +//line __orchestrion_instrument "github.com/datadog/orchestrion/instrument" ) @@ -18,7 +19,7 @@ import ( func gorillaMuxServer() { r := mux.NewRouter() ping := -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/gorilla.go:17 func(w http.ResponseWriter, r *http.Request) { @@ -27,7 +28,6 @@ func gorillaMuxServer() { _, _ = io.WriteString(w, `{"message":"pong"}`) }) -//line samples/server/gorilla.go:23 r.HandleFunc("/ping", ping).Methods("GET") _ = http.ListenAndServe(":8080", r) } diff --git a/internal/injector/builtin/testdata/server/grpc.go.snap b/internal/injector/builtin/testdata/server/grpc.go.snap index 46423a9ca..b647ef0cf 100644 --- a/internal/injector/builtin/testdata/server/grpc.go.snap +++ b/internal/injector/builtin/testdata/server/grpc.go.snap @@ -1,3 +1,4 @@ +//line samples/server/grpc.go:1:1 // 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/). @@ -10,7 +11,7 @@ import ( "net" "google.golang.org/grpc" -//line :1 +//line __orchestrion_grpctrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/google.golang.org/grpc" ) @@ -22,7 +23,7 @@ func grpcServer() { } s := grpc.NewServer(grpc.EmptyServerOption{}, -//line :1 +//line grpc.StreamInterceptor(__orchestrion_grpctrace.StreamServerInterceptor()), grpc.UnaryInterceptor(__orchestrion_grpctrace.UnaryServerInterceptor())) //line samples/server/grpc.go:22 if err := s.Serve(ln); err != nil { diff --git a/internal/injector/builtin/testdata/server/ibm_sarama.go.snap b/internal/injector/builtin/testdata/server/ibm_sarama.go.snap index 54cd5af48..16e5a256a 100644 --- a/internal/injector/builtin/testdata/server/ibm_sarama.go.snap +++ b/internal/injector/builtin/testdata/server/ibm_sarama.go.snap @@ -1,3 +1,4 @@ +//line samples/server/ibm_sarama.go:1:1 // 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/). @@ -8,7 +9,7 @@ package main import ( "github.com/IBM/sarama" -//line :1 +//line __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/IBM/sarama.v1" ) @@ -18,7 +19,7 @@ func ibmSaramaProducer() { cfg.Producer.Return.Successes = true producer, err := -//line :1 +//line func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) @@ -27,7 +28,6 @@ func ibmSaramaProducer() { }( //line samples/server/ibm_sarama.go:14 sarama.NewSyncProducer([]string{"localhost:9092"}, cfg)) -//line samples/server/ibm_sarama.go:15 if err != nil { panic(err) } @@ -43,7 +43,7 @@ func ibmSaramaProducerFromClient() { panic(err) } producer, err := -//line :1 +//line func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) @@ -52,7 +52,6 @@ func ibmSaramaProducerFromClient() { }( //line samples/server/ibm_sarama.go:29 sarama.NewSyncProducerFromClient(client)) -//line samples/server/ibm_sarama.go:30 if err != nil { panic(err) } @@ -64,7 +63,7 @@ func ibmSaramaAsyncProducer() { cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing producer, err := -//line :1 +//line func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) @@ -73,7 +72,6 @@ func ibmSaramaAsyncProducer() { }( //line samples/server/ibm_sarama.go:40 sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg)) -//line samples/server/ibm_sarama.go:41 if err != nil { panic(err) } @@ -89,7 +87,7 @@ func ibmSaramaAsyncProducerFromClient() { panic(err) } producer, err := -//line :1 +//line func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) @@ -98,7 +96,6 @@ func ibmSaramaAsyncProducerFromClient() { }( //line samples/server/ibm_sarama.go:55 sarama.NewAsyncProducerFromClient(client)) -//line samples/server/ibm_sarama.go:56 if err != nil { panic(err) } diff --git a/internal/injector/builtin/testdata/server/main.go.snap b/internal/injector/builtin/testdata/server/main.go.snap index a647138f6..c10428405 100644 --- a/internal/injector/builtin/testdata/server/main.go.snap +++ b/internal/injector/builtin/testdata/server/main.go.snap @@ -1,3 +1,4 @@ +//line samples/server/main.go:1:1 // 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/). @@ -9,7 +10,7 @@ import ( "io" "log" "net/http" -//line :1 +//line __orchestrion_instrument "github.com/datadog/orchestrion/instrument" __orchestrion_tracer "gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer" __orchestrion_profiler "gopkg.in/DataDog/dd-trace-go.v1/profiler" @@ -18,7 +19,7 @@ import ( //line samples/server/main.go:14 func main() { -//line :1 +//line { __orchestrion_tracer.Start(__orchestrion_tracer.WithOrchestrion(map[string]string{"version": ""})) defer __orchestrion_tracer.Stop() @@ -48,8 +49,8 @@ func main() { s := &http.Server{ Addr: ":8080", Handler: -//line :1 //dd:startwrap +//line __orchestrion_instrument.WrapHandler( //line samples/server/main.go:17 http.HandlerFunc(myHandler)), diff --git a/internal/injector/builtin/testdata/server/other_handlers.go.snap b/internal/injector/builtin/testdata/server/other_handlers.go.snap index 8d306628c..f8ad39b34 100644 --- a/internal/injector/builtin/testdata/server/other_handlers.go.snap +++ b/internal/injector/builtin/testdata/server/other_handlers.go.snap @@ -1,3 +1,4 @@ +//line samples/server/other_handlers.go:1:1 // 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/). @@ -13,7 +14,7 @@ import ( "os" "strings" "time" -//line :1 +//line __orchestrion_instrument "github.com/datadog/orchestrion/instrument" __orchestrion_event "github.com/datadog/orchestrion/instrument/event" ) @@ -28,22 +29,20 @@ func (f foo) fooHandler(rw http.ResponseWriter, req *http.Request) { func buildHandlers() { http.HandleFunc("/foo/bar", -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:26 func(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte("done!")) })) -//line samples/server/other_handlers.go:29 v := -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:29 func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("another one!")) }) -//line samples/server/other_handlers.go:33 fmt.Printf("%T\n", v) type holder struct { @@ -52,7 +51,7 @@ func buildHandlers() { x := holder{ f: -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:40 func(w http.ResponseWriter, request *http.Request) { @@ -60,11 +59,10 @@ func buildHandlers() { }), } -//line samples/server/other_handlers.go:45 fmt.Println(x) // silly legal things -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:48 func(w http.ResponseWriter, r *http.Request) { @@ -81,36 +79,30 @@ func buildHandlers() { } fmt.Println(resp.Status) w.Write([]byte("expression!")) - })( -//line samples/server/other_handlers.go:62 - httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) + })(httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) for i := 0; i < 10; i++ { go -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:65 func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("goroutine!")) - })( -//line samples/server/other_handlers.go:67 - httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) + })(httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) } defer -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:70 func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("goroutine!")) - })( -//line samples/server/other_handlers.go:72 - httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) + })(httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/asfd", nil)) } //dd:span foo:bar type:potato func myFunc(_arg_0 context.Context, name string) { -//line :1 +//line { _arg_0 = __orchestrion_instrument.Report(_arg_0, __orchestrion_event.EventStart, "function-name", "myFunc", "foo", "bar", "type", "potato") defer __orchestrion_instrument.Report(_arg_0, __orchestrion_event.EventEnd, "function-name", "myFunc", "foo", "bar", "type", "potato") @@ -121,7 +113,7 @@ func myFunc(_arg_0 context.Context, name string) { //dd:span foo2:bar2 type:request func myFunc2(name string, _arg_1 *http.Request) { -//line :1 +//line { _arg_1 = _arg_1.WithContext(__orchestrion_instrument.Report(_arg_1.Context(), __orchestrion_event.EventStart, "function-name", "myFunc2", "foo2", "bar2", "type", "request")) defer __orchestrion_instrument.Report(_arg_1.Context(), __orchestrion_event.EventEnd, "function-name", "myFunc2", "foo2", "bar2", "type", "request") @@ -140,41 +132,37 @@ func registerHandlers() { http.Handle("/handle-1", handler) http.Handle("/hundle-2", http.HandlerFunc(myHandler)) http.Handle("/hundle-3", http.HandlerFunc( -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:94 func(w http.ResponseWriter, r *http.Request) {}))) -//line samples/server/other_handlers.go:95 http.HandleFunc("/handlefunc-1", handler) http.HandleFunc("/handlefunc-2", http.HandlerFunc(myHandler)) http.HandleFunc("/handlefunc-3", -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:97 func(w http.ResponseWriter, r *http.Request) {})) -//line samples/server/other_handlers.go:98 s := http.NewServeMux() s.Handle("/handle-mux", handler) s.Handle("/handle-mux", http.HandlerFunc(myHandler)) s.Handle("/handle-mux", http.HandlerFunc( -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:101 func(w http.ResponseWriter, r *http.Request) {}))) -//line samples/server/other_handlers.go:102 s.HandleFunc("/handlefunc-1", handler) s.HandleFunc("/handlefunc-2", http.HandlerFunc(myHandler)) s.HandleFunc("/handlefunc-3", -//line :1 +//line __orchestrion_instrument.WrapHandlerFunc( //line samples/server/other_handlers.go:104 func(w http.ResponseWriter, r *http.Request) {})) -//line samples/server/other_handlers.go:105 _ = &http.Server{ Addr: ":8080", Handler: -//line :1 //dd:startwrap +//line __orchestrion_instrument.WrapHandler( //line samples/server/other_handlers.go:107 handler), diff --git a/internal/injector/builtin/testdata/server/shopify_sarama.go.snap b/internal/injector/builtin/testdata/server/shopify_sarama.go.snap index 134e82821..62172e1ee 100644 --- a/internal/injector/builtin/testdata/server/shopify_sarama.go.snap +++ b/internal/injector/builtin/testdata/server/shopify_sarama.go.snap @@ -1,3 +1,4 @@ +//line samples/server/shopify_sarama.go:1:1 // 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/). @@ -8,7 +9,7 @@ package main import ( "github.com/Shopify/sarama" -//line :1 +//line __orchestrion_saramatrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/Shopify/sarama" ) @@ -18,7 +19,7 @@ func shopifySaramaProducer() { cfg.Producer.Return.Successes = true producer, err := -//line :1 +//line func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) @@ -27,7 +28,6 @@ func shopifySaramaProducer() { }( //line samples/server/shopify_sarama.go:14 sarama.NewSyncProducer([]string{"localhost:9092"}, cfg)) -//line samples/server/shopify_sarama.go:15 if err != nil { panic(err) } @@ -43,7 +43,7 @@ func shopifySaramaProducerFromClient() { panic(err) } producer, err := -//line :1 +//line func(p sarama.SyncProducer, err error) (sarama.SyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapSyncProducer(nil, p) @@ -52,7 +52,6 @@ func shopifySaramaProducerFromClient() { }( //line samples/server/shopify_sarama.go:29 sarama.NewSyncProducerFromClient(client)) -//line samples/server/shopify_sarama.go:30 if err != nil { panic(err) } @@ -64,7 +63,7 @@ func shopifySaramaAsyncProducer() { cfg.Version = sarama.V0_11_0_0 // minimum version that supports headers which are required for tracing producer, err := -//line :1 +//line func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) @@ -73,7 +72,6 @@ func shopifySaramaAsyncProducer() { }( //line samples/server/shopify_sarama.go:40 sarama.NewAsyncProducer([]string{"localhost:9092"}, cfg)) -//line samples/server/shopify_sarama.go:41 if err != nil { panic(err) } @@ -89,7 +87,7 @@ func shopifySaramaAsyncProducerFromClient() { panic(err) } producer, err := -//line :1 +//line func(p sarama.AsyncProducer, err error) (sarama.AsyncProducer, error) { if p != nil { p = __orchestrion_saramatrace.WrapAsyncProducer(nil, p) @@ -98,7 +96,6 @@ func shopifySaramaAsyncProducerFromClient() { }( //line samples/server/shopify_sarama.go:55 sarama.NewAsyncProducerFromClient(client)) -//line samples/server/shopify_sarama.go:56 if err != nil { panic(err) } diff --git a/internal/injector/injector.go b/internal/injector/injector.go index dd586ac5d..049c675ce 100644 --- a/internal/injector/injector.go +++ b/internal/injector/injector.go @@ -22,6 +22,7 @@ import ( "github.com/datadog/orchestrion/internal/injector/aspect" "github.com/datadog/orchestrion/internal/injector/aspect/context" "github.com/datadog/orchestrion/internal/injector/builtin" + "github.com/datadog/orchestrion/internal/injector/lineinfo" "github.com/datadog/orchestrion/internal/injector/typed" "github.com/datadog/orchestrion/internal/log" "github.com/dave/dst" @@ -34,11 +35,11 @@ import ( type ( // Injector injects go code into a program. Injector struct { - fileset *token.FileSet - decorators []*decorator.Decorator - restorer *decorator.Restorer - opts Options - mutex sync.Mutex // Guards access to InjectFile + fileset *token.FileSet + decorators []*decorator.Decorator + newRestorer func(string) *decorator.FileRestorer + opts Options + mutex sync.Mutex // Guards access to InjectFile } // ModifiedFileFn is called with the original file and must return the path to use when writing a modified version. @@ -147,8 +148,12 @@ func New(pkgDir string, opts Options) (*Injector, error) { return &Injector{ fileset: fileset, decorators: decorators, - restorer: decorator.NewRestorerWithImports(pkgPath, guess.WithMap(restorerMap)), - opts: opts, + newRestorer: func(filename string) *decorator.FileRestorer { + res := decorator.NewRestorerWithImports(pkgPath, guess.WithMap(restorerMap)).FileRestorer() + res.Name = filename + return res + }, + opts: opts, }, nil } @@ -158,7 +163,6 @@ type ( References typed.ReferenceMap // New package references injected into the file and what kind of reference they are Filename string // The file name of the output file (may be different from the input file) Modified bool // Whether the file was modified - NewFiles map[string][]byte // New source files to be compiled } ) @@ -175,16 +179,13 @@ func (i *Injector) InjectFile(filename string, rootConfig map[string]string) (re return res, err } - if res.NewFiles == nil { - res.NewFiles = make(map[string][]byte) - } - if res.Modified, res.References, err = i.inject(file, decorator, rootConfig, res.NewFiles); err != nil { + if res.Modified, res.References, err = i.inject(file, decorator, rootConfig); err != nil { return res, err } if res.Modified { buf := bytes.NewBuffer(nil) - if err = i.restorer.Fprint(buf, file); err != nil { + if err = i.newRestorer(filename).Fprint(buf, file); err != nil { return res, err } @@ -237,7 +238,7 @@ func (i *Injector) lookupDecoratedFile(filename string) (*dst.File, *decorator.D // inject performs all configured injections on the specified file. It returns whether the file was // modified, any import references introduced by modifications. In case of an error, the // trasnformation aborts as quickly as possible and returns the error. -func (i *Injector) inject(file *dst.File, decorator *decorator.Decorator, rootConfig map[string]string, newFiles map[string][]byte) (mod bool, refs typed.ReferenceMap, err error) { +func (i *Injector) inject(file *dst.File, decorator *decorator.Decorator, rootConfig map[string]string) (mod bool, refs typed.ReferenceMap, err error) { var chain *context.NodeChain dstutil.Apply( @@ -283,7 +284,9 @@ func (i *Injector) inject(file *dst.File, decorator *decorator.Decorator, rootCo } if mod && i.opts.PreserveLineInfo { - i.addLineDirectives(file, decorator) + if err := lineinfo.AnnotateMovedNodes(decorator, file, i.newRestorer); err != nil { + return mod, refs, err + } } return @@ -312,74 +315,6 @@ func (i *Injector) injectNode(ctx context.AdviceContext) (mod bool, err error) { return } -// addLineDirectives travers a transformed AST and adds "//line file:line" directives where -// necessary to preserve the original file's line numbering, and to correctly locate synthetic nodes -// within a `` pseudo-file. -func (i *Injector) addLineDirectives(file *dst.File, decorator *decorator.Decorator) { - var ( - // Whether we are in generated code or not - inGen = false - // Force emitting a generated code line directive even if we are already in generated code. This - // is necessary when original AST nodes are inlined within generated code (usually by - // a wrap-expression advice), so we appropriately resume generated code tagging afterwards. - forceGen = false - ) - - var stack []bool - dst.Inspect(file, func(node dst.Node) bool { - if node == nil { - if len(stack) == 0 { - panic("popping empty stack") - } - forceGen = !inGen && stack[len(stack)-1] - inGen, stack = inGen || stack[len(stack)-1], stack[:len(stack)-1] - return true - } - - // Push the current node onto the stack - defer func() { - stack = append(stack, inGen) - // The forceGen flag is reset after any node is processed, as at this stage we have resumed - // normal operations. - forceGen = false - }() - - ast := decorator.Ast.Nodes[node] - if ast != nil { - position := i.fileset.Position(ast.Pos()) - // Generated nodes from templates may have a corresponding AST node, with a blank filename. - // Those should be treated as synthetic nodes (they are!). - if position.Filename != "" { - if inGen { - // We need to properly re-position this node (previous node was synthetic) - deco := node.Decorations() - if deco.Before == dst.None { - deco.Before = dst.NewLine - } - deco.Start.Append(fmt.Sprintf("//line %s:%d", position.Filename, position.Line)) - inGen = false - } - return true - } - } - - if !inGen || forceGen { - deco := node.Decorations() - if deco.Before == dst.None { - deco.Before = dst.NewLine - } - deco.Start.Prepend("//line :1") - inGen = true - } - - return true - }) - - if len(stack) != 0 { - panic("finished with non-zero stack!") - } -} - // outputFileFor returns the file name to be used when writing a modified file. It uses the options // specified when building this Injector. func (i *Injector) outputFileFor(filename string) string { diff --git a/internal/injector/lineinfo/annotation.go b/internal/injector/lineinfo/annotation.go new file mode 100644 index 000000000..8baf4639a --- /dev/null +++ b/internal/injector/lineinfo/annotation.go @@ -0,0 +1,160 @@ +// 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 2023-present Datadog, Inc. + +package lineinfo + +import ( + "bytes" + "go/ast" + "go/token" + "strconv" + + "github.com/dave/dst" + "github.com/dave/dst/decorator" +) + +const generated = "" + +type ( + // annotationVisitor is an ast.Visitor that adds `//line` directives to the visited nodes to + // adjust their logical source location so it matches those of the original `*ast.File` tree. + annotationVisitor struct { + // dev is the decorator that transformed the original *ast.File into the visited *dst.File + dec *decorator.Decorator + // res is a restorer that was used to restore the visited *dst.File into an *ast.File, and hence + // provides source location information for the restored AST. + res *decorator.FileRestorer + + lineInfo + stack []dst.Node + } + lineInfo struct { + curFile string // The current un-adjusted file name + adjFile string // The current adjusted file name + curLine int // The current un-adjusted line number + adjLine int // The current adjusted line number + } +) + +var _ ast.Visitor = (*annotationVisitor)(nil) + +func (v *annotationVisitor) Visit(node ast.Node) ast.Visitor { + if node == nil { + last := len(v.stack) - 1 + + switch node := v.stack[last].(type) { + case *dst.GenDecl: + // If this is a `*dst.GenDecl` with a single item that's rendered without parentheses, we + // hoist decorations from the single item to the `*dst.GenDecl` itself, as it'll render + // better. + if !node.Lparen && len(node.Specs) > 1 { + break + } + specDeco := node.Specs[0].Decorations() + node.Decs.Start = append(node.Decs.Start, specDeco.Start...) + specDeco.Start.Clear() + } + + // Finished visiting a node, we don't have anything particular to do... + v.stack = v.stack[:last] + return nil + } + + prevInfo := v.lineInfo + + curPosition := v.res.Fset.Position(node.Pos()) + v.curFile, v.curLine = curPosition.Filename, curPosition.Line + + dstNode := v.res.Dst.Nodes[node] + v.stack = append(v.stack, dstNode) + if dstNode == nil { + // Nodes such as `ast.FuncType` are not mapped directly by dst... They anyway do not represent + // lines that can show on stack frames, so it's not all that important... + return v + } + + // Emit a `//line :1:1` directive at start of file to act as a base for all subsequent declarations. + if prevInfo.adjFile == "" { + prevInfo.adjFile, prevInfo.adjLine = curPosition.Filename, 1 + dstNode.Decorations().Start.Prepend(prevInfo.directive(true)) + } + + var adjPosition token.Position + if orgNode := v.dec.Ast.Nodes[dstNode]; orgNode != nil { + adjPosition = v.dec.Fset.Position(orgNode.Pos()) + } + + if adjPosition.Filename == "" { + if _, isIdent := dstNode.(*dst.Ident); isIdent && adjPosition.Line == 0 { + // This is a virtual `*dst.Ident` node that was created by import management. It does not map + // back to a node in the original AST, and it's part of a `*dst.SelectorExpr` that we'll be + // able to properly map; so we can safely ignore it now. + return v + } + + // This is a synthetic node... + v.adjFile, v.adjLine = generated, 0 + + if prevInfo.adjFile != generated { + decs := dstNode.Decorations() + decs.Start.Append(v.directive(false)) + if decs.Before == dst.None { + decs.Before = dst.NewLine + } + } + return v + } + + // Update the adjusted position to the current observed one... + v.adjFile, v.adjLine = adjPosition.Filename, adjPosition.Line + + if curPosition.Line == adjPosition.Line && curPosition.Filename == adjPosition.Filename && + adjPosition.Filename == prevInfo.adjFile { + // Current & adjusted positions match, and we've not changed adjusted files -- nothing to do! + return v + } + + if adjPosition.Line-prevInfo.adjLine == curPosition.Line-prevInfo.curLine && + prevInfo.curFile == curPosition.Filename && + prevInfo.adjFile == adjPosition.Filename { + // We're already correctly adjusted, so we don't need to add another directive... + return v + } + + decs := dstNode.Decorations() + decs.Start.Append(v.directive(false)) + if decs.Before == dst.None { + decs.Before = dst.NewLine + } + + return v +} + +func (l *lineInfo) directive(fileStart bool) string { + line := strconv.FormatInt(int64(l.adjLine), 10) + + const prefix = "//line " + builder := bytes.NewBuffer(make([]byte, 0, len(prefix)+len(l.adjFile)+1+len(line)+2)) + + builder.WriteString(prefix) + builder.WriteString(l.adjFile) + switch l.adjLine { + case 0: + // We don't emit 0 line numbers + case 1: + if fileStart { + // We emit :1:1 for line 1, so we match the output of `go tool cover` for this particular case. + builder.WriteString(":1:1") + break + } + fallthrough + default: + // Otherwise, we only emit line number (no column). + builder.WriteByte(':') + builder.WriteString(line) + } + + return builder.String() +} diff --git a/internal/injector/lineinfo/canonicalize.go b/internal/injector/lineinfo/canonicalize.go new file mode 100644 index 000000000..84e06121e --- /dev/null +++ b/internal/injector/lineinfo/canonicalize.go @@ -0,0 +1,72 @@ +// 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 2023-present Datadog, Inc. + +package lineinfo + +import ( + "github.com/dave/dst" +) + +// canonicalizationVisitor is a dst.Visitor that adds dst.NewLine before select AST nodes +// (*dst.GenDecl and select dst.Stmt nodes), to get the AST closer to what the canonical go format +// is. This allows us to have more accurate line information from the transformed AST and removes +// the risk of false equivalence when we assess the need for line directives. +type ( + canonicalizationVisitor struct { + stack []*stackEntry + } + stackEntry struct { + node dst.Node + lastChild dst.Node + } +) + +var _ dst.Visitor = (*canonicalizationVisitor)(nil) + +func (v *canonicalizationVisitor) Visit(node dst.Node) dst.Visitor { + if node == nil { + v.stack = v.stack[:len(v.stack)-1] + return nil + } + + v.stack = append(v.stack, &stackEntry{node: node}) + var parent *stackEntry + if len := len(v.stack); len > 1 { + parent = v.stack[len-2] + // Upon returning, set the parent's last visited child to the current one... + defer func() { parent.lastChild = node }() + } + + // dave/dst will double-count new lines between imports if an ImportSpec with "After" spacing set + // to `dst.EmptyLine` is immediately followed by another with "Before" spacing of `dst.EmptyLine`. + // The two empty lines are satisfied by the same; so we can safely turn either one into a + // `dst.NewLine` instead, so we get accurate line numbering data from the restorer. + if node.Decorations().Before == dst.EmptyLine && + parent != nil && parent.lastChild != nil && parent.lastChild.Decorations().After == dst.EmptyLine { + parent.lastChild.Decorations().After = dst.NewLine + } + + if node, isGenDecl := node.(*dst.GenDecl); isGenDecl { + if node.Decs.Before == dst.None { + node.Decs.Before = dst.NewLine + } + return v + } + + if node.Decorations().Before != dst.None { + return v + } + if _, isStmt := node.(dst.Stmt); !isStmt { + return v + } + + // Don't space up the statements if they're not within a *dst.Block. + if _, isBlock := parent.node.(*dst.BlockStmt); !isBlock { + return v + } + + node.Decorations().Before = dst.NewLine + return v +} diff --git a/internal/injector/lineinfo/lineinfo.go b/internal/injector/lineinfo/lineinfo.go new file mode 100644 index 000000000..8bb8c6e12 --- /dev/null +++ b/internal/injector/lineinfo/lineinfo.go @@ -0,0 +1,50 @@ +// 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 2023-present Datadog, Inc. + +package lineinfo + +import ( + "go/ast" + + "github.com/dave/dst" + "github.com/dave/dst/decorator" +) + +// AnnotateMovedNodes adds `//line` directives to the provided `*dst.File` to adjust source location +// information of each AST node that exists in the original source file to its location there, and +// marks other nodes as originating from ``. +func AnnotateMovedNodes( + // The decorator that produced the *dst.File + decorator *decorator.Decorator, + // The *dst.File to annotate + file *dst.File, + // A function that creates a new *decorator.FileRestorer for the given filename + newRestorer func(string) *decorator.FileRestorer, +) error { + canonicalizer := canonicalizationVisitor{} + // Pre-process the AST to make it closer to the canonical go format, which will allow us to have + // more accurate "after-printing" line information. + dst.Walk(&canonicalizer, file) + if len(canonicalizer.stack) != 0 { + panic("noempty stack after canonicalizater visit is complete") + } + + // Restore to an *ast.File so we can obtain the new line information data. + res := newRestorer(decorator.Filenames[file]) + astFile, err := res.RestoreFile(file) + if err != nil { + return err + } + + // Visit the AST to add `//line` directives where the updated line information no longer matches + // the original source file's. + annotator := annotationVisitor{dec: decorator, res: res} + ast.Walk(&annotator, astFile) + if len(annotator.stack) != 0 { + panic("noempty stack after annotation visit is complete") + } + + return nil +} diff --git a/internal/injector/testdata/injector/chi5-newroute-dotimport/expected.diff b/internal/injector/testdata/injector/chi5-newroute-dotimport/expected.diff index 07883a537..bfe507b7d 100644 --- a/internal/injector/testdata/injector/chi5-newroute-dotimport/expected.diff +++ b/internal/injector/testdata/injector/chi5-newroute-dotimport/expected.diff @@ -1,10 +1,15 @@ --- input.go +++ output.go -@@ -9,10 +9,23 @@ +@@ -1,3 +1,4 @@ ++//line input.go:1:1 + package main + + import ( +@@ -9,10 +10,23 @@ "orchestrion/integration" . "github.com/go-chi/chi/v5" -+//line :1 ++//line + __orchestrion_chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5" ) @@ -12,12 +17,12 @@ func main() { - router := NewRouter() + router := -+//line :1 ++//line + func() *Mux { + mux := +//line input.go:15 + NewRouter() -+//line :1 ++//line + mux.Use(__orchestrion_chitrace.Middleware()) + return mux + }() diff --git a/internal/injector/testdata/injector/chi5-newroute/expected.diff b/internal/injector/testdata/injector/chi5-newroute/expected.diff index 1ea8c6f87..7e870ccf5 100644 --- a/internal/injector/testdata/injector/chi5-newroute/expected.diff +++ b/internal/injector/testdata/injector/chi5-newroute/expected.diff @@ -1,10 +1,15 @@ --- input.go +++ output.go -@@ -8,10 +8,23 @@ +@@ -1,3 +1,4 @@ ++//line input.go:1:1 + package main + + import ( +@@ -8,10 +9,23 @@ "github.com/go-chi/chi/v5" "orchestrion/integration" -+//line :1 ++//line + __orchestrion_chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5" ) @@ -12,12 +17,12 @@ func main() { - router := chi.NewRouter() + router := -+//line :1 ++//line + func() *chi.Mux { + mux := +//line input.go:14 + chi.NewRouter() -+//line :1 ++//line + mux.Use(__orchestrion_chitrace.Middleware()) + return mux + }() diff --git a/internal/injector/testdata/injector/database-sql/expected.diff b/internal/injector/testdata/injector/database-sql/expected.diff index 7ac3581ec..99118c072 100644 --- a/internal/injector/testdata/injector/database-sql/expected.diff +++ b/internal/injector/testdata/injector/database-sql/expected.diff @@ -1,12 +1,14 @@ --- input.go +++ output.go @@ -1,19 +1,31 @@ ++//line input.go:1:1 package test ++//line input.go:5 import ( - "database/sql" "database/sql/driver" -+//line :1 ++//line + __orchestrion_sqltrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/database/sql" ) @@ -16,11 +18,10 @@ func main() { - db1, err := sql.Open("foo", "bar") + db1, err := -+//line :1 ++//line + __orchestrion_sqltrace.Open( +//line input.go:11 + "foo", "bar") -+//line input.go:12 if err != nil { panic(err) } @@ -28,10 +29,9 @@ - db2 := sql.OpenDB(conn) + db2 := -+//line :1 ++//line + __orchestrion_sqltrace.OpenDB( +//line input.go:17 + conn) -+//line input.go:18 defer db2.Close() } diff --git a/internal/injector/testdata/injector/directive/expected.diff b/internal/injector/testdata/injector/directive/expected.diff index 32698ebe7..91a314a57 100644 --- a/internal/injector/testdata/injector/directive/expected.diff +++ b/internal/injector/testdata/injector/directive/expected.diff @@ -1,10 +1,12 @@ --- input.go +++ output.go -@@ -2,12 +2,28 @@ +@@ -1,13 +1,30 @@ ++//line input.go:1:1 + package test import ( "context" -+//line :1 ++//line + __orchestrion_instrument "github.com/datadog/orchestrion/instrument" + __orchestrion_event "github.com/datadog/orchestrion/instrument/event" ) @@ -12,7 +14,7 @@ //dd:span foo:bar baz:qux +//line input.go:8 func outer(ctx context.Context) { -+//line :1 ++//line + { + __orchestrion_instrument.Report(ctx, __orchestrion_event.EventStart, "name", "outer", "foo", "bar", "baz", "qux") + defer __orchestrion_instrument.Report(ctx, __orchestrion_event.EventEnd, "name", "outer", "foo", "bar", "baz", "qux") @@ -20,7 +22,7 @@ //dd:span +//line input.go:10 inner := func(c context.Context) { -+//line :1 ++//line + { + __orchestrion_instrument.Report(c, __orchestrion_event.EventStart) + defer __orchestrion_instrument.Report(c, __orchestrion_event.EventEnd) diff --git a/internal/injector/testdata/injector/grpc/expected.diff b/internal/injector/testdata/injector/grpc/expected.diff index d0a59f5f7..94839f92e 100644 --- a/internal/injector/testdata/injector/grpc/expected.diff +++ b/internal/injector/testdata/injector/grpc/expected.diff @@ -1,10 +1,15 @@ --- input.go +++ output.go -@@ -5,11 +5,21 @@ +@@ -1,3 +1,4 @@ ++//line input.go:1:1 + package test + + import ( +@@ -5,11 +6,20 @@ "net" "google.golang.org/grpc" -+//line :1 ++//line + __orchestrion_grpctrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/google.golang.org/grpc" ) @@ -13,13 +18,12 @@ dialOpts := []grpc.DialOption{grpc.WithInsecure()} - conn, err := grpc.Dial("localhost:50051", dialOpts...) + conn, err := grpc.Dial("localhost:50051", -+//line :1 ++//line + func(opts ...grpc.DialOption) []grpc.DialOption { + return append(opts, grpc.WithStreamInterceptor(__orchestrion_grpctrace.StreamClientInterceptor()), grpc.WithUnaryInterceptor(__orchestrion_grpctrace.UnaryClientInterceptor())) + }( +//line input.go:12 + dialOpts...)...) -+//line input.go:13 if err != nil { log.Fatal(err) } @@ -29,7 +33,7 @@ - s := grpc.NewServer(grpc.EmptyServerOption{}) + s := grpc.NewServer(grpc.EmptyServerOption{}, -+//line :1 ++//line + grpc.StreamInterceptor(__orchestrion_grpctrace.StreamServerInterceptor()), grpc.UnaryInterceptor(__orchestrion_grpctrace.UnaryServerInterceptor())) +//line input.go:26 if err := s.Serve(ln); err != nil { diff --git a/internal/injector/testdata/injector/http-line-info/expected.diff b/internal/injector/testdata/injector/http-line-info/expected.diff index 9f672c5a4..660c81e63 100644 --- a/internal/injector/testdata/injector/http-line-info/expected.diff +++ b/internal/injector/testdata/injector/http-line-info/expected.diff @@ -1,10 +1,15 @@ --- input.go +++ output.go -@@ -7,8 +7,12 @@ +@@ -1,3 +1,4 @@ ++//line input.go:1:1 + package main + + import ( +@@ -7,8 +8,12 @@ "net/http" "orchestrion/integration" -+//line :1 ++//line + __orchestrion_instrument "github.com/datadog/orchestrion/instrument" + __orchestrion_event "github.com/datadog/orchestrion/instrument/event" ) @@ -13,11 +18,11 @@ func main() { s := &http.Server{ Addr: ":8085", -@@ -21,6 +23,28 @@ +@@ -21,6 +24,28 @@ } func handle(w http.ResponseWriter, r *http.Request) { -+//line :1 ++//line + { + r = r.WithContext(__orchestrion_instrument.Report( + r.Context(), diff --git a/internal/injector/testdata/injector/http-server/expected.diff b/internal/injector/testdata/injector/http-server/expected.diff index 820a264a8..5dca5cb53 100644 --- a/internal/injector/testdata/injector/http-server/expected.diff +++ b/internal/injector/testdata/injector/http-server/expected.diff @@ -1,10 +1,15 @@ --- input.go +++ output.go -@@ -7,13 +7,23 @@ +@@ -1,3 +1,4 @@ ++//line input.go:1:1 + package main + + import ( +@@ -7,13 +8,23 @@ "net/http" "orchestrion/integration" -+//line :1 ++//line + __orchestrion_instrument "github.com/datadog/orchestrion/instrument" ) @@ -15,8 +20,8 @@ - Handler: http.HandlerFunc(handle), + Addr: ":8085", + Handler: -+//line :1 + //dd:startwrap ++//line + __orchestrion_instrument.WrapHandler( +//line input.go:15 + http.HandlerFunc(handle)), diff --git a/internal/injector/testdata/injector/name-conflict/expected.diff b/internal/injector/testdata/injector/name-conflict/expected.diff index ea058abfa..cfde382ca 100644 --- a/internal/injector/testdata/injector/name-conflict/expected.diff +++ b/internal/injector/testdata/injector/name-conflict/expected.diff @@ -1,9 +1,10 @@ --- input.go +++ output.go -@@ -1,8 +1,17 @@ +@@ -1,8 +1,18 @@ ++//line input.go:1:1 package test -+//line :1 ++//line +import __orchestrion_fmt "fmt" + +//line input.go:3 @@ -11,7 +12,7 @@ //dd:span func foo() { -+//line :1 ++//line + { + __orchestrion_fmt.Println("hello world") + } diff --git a/internal/injector/testdata/injector/redigo/expected.diff b/internal/injector/testdata/injector/redigo/expected.diff index 0908cc91d..aa993f994 100644 --- a/internal/injector/testdata/injector/redigo/expected.diff +++ b/internal/injector/testdata/injector/redigo/expected.diff @@ -1,10 +1,14 @@ --- input.go +++ output.go -@@ -4,10 +4,13 @@ +@@ -1,13 +1,17 @@ ++//line input.go:1:1 + package test + + import ( "context" "github.com/gomodule/redigo/redis" -+//line :1 ++//line + __orchestrion_redigo "gopkg.in/DataDog/dd-trace-go.v1/contrib/gomodule/redigo" ) @@ -15,7 +19,7 @@ if err != nil { return err } -@@ -16,7 +16,7 @@ +@@ -16,7 +11,7 @@ } func dialContext(ctx context.Context, net, address string) error { @@ -24,7 +28,7 @@ if err != nil { return err } -@@ -25,7 +25,7 @@ +@@ -25,7 +20,7 @@ } func dialURL(url string) error { diff --git a/internal/toolexec/aspect/oncompile.go b/internal/toolexec/aspect/oncompile.go index 5b3ca6da2..e1c76ea64 100644 --- a/internal/toolexec/aspect/oncompile.go +++ b/internal/toolexec/aspect/oncompile.go @@ -13,7 +13,6 @@ import ( "regexp" "slices" "strings" - "unsafe" "github.com/datadog/orchestrion/internal/injector" "github.com/datadog/orchestrion/internal/injector/aspect" @@ -100,19 +99,6 @@ func (w Weaver) OnCompile(cmd *proxy.CompileCommand) error { } } - outDir := filepath.Join(orchestrionDir, "src", "synthetic") - for name, data := range res.NewFiles { - log.Debugf("New source file: %q\n%s\n", name, unsafe.String(unsafe.SliceData(data), len(data))) - if err := os.MkdirAll(outDir, 0o755); err != nil { - return fmt.Errorf("creating synthetic source directory %q: %w", outDir, err) - } - filename := filepath.Join(outDir, name) - if err := os.WriteFile(filename, data, 0o644); err != nil { - return fmt.Errorf("writing synthetic source file %q: %w", filename, err) - } - cmd.AddFiles([]string{filename}) - } - references.Merge(res.References) } From afc28d1802e7175ca94de41fb79ff60f93047285 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:45:30 +0200 Subject: [PATCH 13/13] chore(deps): bump github/codeql-action from 3.26.3 to 3.26.4 (#238) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.26.3 to 3.26.4.
Changelog

Sourced from github/codeql-action's changelog.

CodeQL Action Changelog

See the releases page for the relevant changes to the CodeQL CLI and language packs.

Note that the only difference between v2 and v3 of the CodeQL Action is the node version they support, with v3 running on node 20 while we continue to release v2 to support running on node 16. For example 3.22.11 was the first v3 release and is functionally identical to 2.22.11. This approach ensures an easy way to track exactly which features are included in different versions, indicated by the minor and patch version numbers.

[UNRELEASED]

No user facing changes.

3.26.4 - 21 Aug 2024

  • Deprecation: The add-snippets input on the analyze Action is deprecated and will be removed in the first release in August 2025. #2436
  • Fix an issue where the disk usage system call used for telemetry would fail on MacOS ARM machines with System Integrity Protection disabled, and then surface a warning. The system call is now disabled for these machines. #2434

3.26.3 - 19 Aug 2024

  • Fix an issue where the CodeQL Action could not write diagnostic messages on Windows. This issue did not impact analysis quality. #2430

3.26.2 - 14 Aug 2024

  • Update default CodeQL bundle version to 2.18.2. #2417

3.26.1 - 13 Aug 2024

No user facing changes.

3.26.0 - 06 Aug 2024

  • Deprecation: Swift analysis on Ubuntu runner images is no longer supported. Please migrate to a macOS runner if this affects you. #2403
  • Bump the minimum CodeQL bundle version to 2.13.5. #2408

3.25.15 - 26 Jul 2024

  • Update default CodeQL bundle version to 2.18.1. #2385

3.25.14 - 25 Jul 2024

  • Experimental: add a new start-proxy action which starts the same HTTP proxy as used by github/dependabot-action. Do not use this in production as it is part of an internal experiment and subject to change at any time. #2376

3.25.13 - 19 Jul 2024

  • Add codeql-version to outputs. #2368
  • Add a deprecation warning for customers using CodeQL version 2.13.4 and earlier. These versions of CodeQL were discontinued on 9 July 2024 alongside GitHub Enterprise Server 3.9, and will be unsupported by CodeQL Action versions 3.26.0 and later and versions 2.26.0 and later. #2375
    • If you are using one of these versions, please update to CodeQL CLI version 2.13.5 or later. For instance, if you have specified a custom version of the CLI using the 'tools' input to the 'init' Action, you can remove this input to use the default version.
    • Alternatively, if you want to continue using a version of the CodeQL CLI between 2.12.6 and 2.13.4, you can replace github/codeql-action/*@v3 by github/codeql-action/*@v3.25.13 and github/codeql-action/*@v2 by github/codeql-action/*@v2.25.13 in your code scanning workflow to ensure you continue using this version of the CodeQL Action.

3.25.12 - 12 Jul 2024

  • Improve the reliability and performance of analyzing code when analyzing a compiled language with the autobuild build mode on GitHub Enterprise Server. This feature is already available to GitHub.com users. #2353

... (truncated)

Commits
  • f0f3afe Merge main into releases/v3 (#2437)
  • e354359 Update changelog for v3.26.4
  • ae01f80 Merge pull request #2436 from rvermeulen/rvermeulen/deprecate-add-snippets
  • 72bc3f7 Address incorrect changelog location
  • 7388c47 Merge branch 'main' into rvermeulen/deprecate-add-snippets
  • d7c48ef Add link to PR deprecating add-snippets to CHANGELOG.md
  • ec21b8f Update changelog with deprecation.
  • 4067cda Add deprecation message to add-snippets input.
  • 202b3b9 Stop checking disk usage for MacOS ARM with SIP disabled (#2434)
  • 512e306 Merge pull request #2404 from github/marcogario/proxy_64
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github/codeql-action&package-manager=github_actions&previous-version=3.26.3&new-version=3.26.4)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
--------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Romain Marcadier Co-authored-by: Romain Marcadier --- .github/dependabot.yml | 5 + .github/workflows/generate.yml | 107 ------------ .github/workflows/ossf-scorecard.yml | 2 +- .github/workflows/sast.yml | 4 +- .github/workflows/{tests.yml => validate.yml} | 152 +++++++++++++++++- .github/workflows/workflow_call.yml | 2 +- .../utils/agent/requirements.txt | 21 ++- codecov.yml | 9 +- internal/injector/builtin/generator/doc.go | 13 -- 9 files changed, 184 insertions(+), 131 deletions(-) delete mode 100644 .github/workflows/generate.yml rename .github/workflows/{tests.yml => validate.yml} (50%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5b1b32fea..39e8ec605 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,8 @@ updates: directory: / schedule: interval: daily + + - package-ecosystem: pip + directory: /_integration-tests/utils/agent + schedule: + interval: daily diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml deleted file mode 100644 index f87b5f28e..000000000 --- a/.github/workflows/generate.yml +++ /dev/null @@ -1,107 +0,0 @@ -name: Generate -on: - pull_request: - branches: ['**'] - merge_group: - branches: [main] - push: - branches: [main] - -permissions: read-all - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - generate: - runs-on: ubuntu-latest - outputs: - has-patch: ${{ steps.is-tree-dirty.outputs.result }} - steps: - - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - - name: Setup go - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 - with: - go-version: stable - cache-dependency-path: '**/go.mod' - - - name: Run 'go generate ./...' - run: |- - mkdir -p ${GOCOVERDIR} - go generate ./... - env: - GOFLAGS: -covermode=atomic -coverpkg=github.com/datadog/orchestrion/... - GOCOVERDIR: ${{ github.workspace }}/coverage - - name: Consolidate coverage report - if: always() && github.event_name != 'merge_group' - run: go tool covdata textfmt -i ./coverage -o ./coverage/generator.out - - name: Upload coverage report - # We want this even if the tests failed - if: always() && github.event_name != 'merge_group' - uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} - flags: ${{ runner.os }},${{ runner.arch }},generator - file: ./coverage/generator.out - name: Generators - - - name: Run 'go mod tidy' - # Don't run for push, it's not necessary - if: github.event_name != 'push' - run: find . -iname go.mod -execdir go mod tidy \; - - - name: Refresh LICENSE-3rdparty.csv - run: ./tools/make-licenses.sh - env: - TMPDIR: ${{ runner.temp }} - - - name: Check if working tree is dirty - # Don't run for push, it's not necessary - if: github.event_name != 'push' - id: is-tree-dirty - run: |- - git add . - git diff --staged --patch --exit-code > .repo.patch || echo "result=true" >> ${GITHUB_OUTPUT} - - name: Upload patch - if: github.event_name != 'push' && steps.is-tree-dirty.outputs.result == 'true' - uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4 - with: - name: repo.patch - path: .repo.patch - - name: Fail build if working tree is dirty - if: github.event_name == 'push' && steps.is-tree-dirty.outputs.result == 'true' - run: |- - echo "::error::Files have been modified by 'go generate ./...' (see logs)." - cat .repo.patch - exit 1 - - # If generated files changed and this is a pull request that we can modify, update the PR with the updated files. - self-mutation: - needs: generate - runs-on: ubuntu-latest - if: always() && needs.generate.outputs.has-patch == 'true' && github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request.maintainer_can_modify) - steps: - - name: Checkout - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - repository: ${{ github.event.pull_request.head.repo.full_name }} - - name: Download patch - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 - with: - name: repo.patch - path: ${{ runner.temp }} - - name: Apply patch - run: |- - [ -s '${{ runner.temp }}/.repo.patch' ] && git apply '${{ runner.temp }}/.repo.patch' || echo 'Empty patch. Skipping.' - # We use ghcommit to create signed commits directly using the GitHub API - - name: Push changes - uses: planetscale/ghcommit-action@c7915d6c18d5ce4eb42b0eff3f10a29fe0766e4c # v0.1.44 - with: - commit_message: "chore: update generated files" - repo: ${{ github.event.pull_request.head.repo.full_name }} - branch: ${{ github.event.pull_request.head.ref }} - env: - GITHUB_TOKEN: ${{ secrets.MUTATOR_GITHUB_TOKEN }} diff --git a/.github/workflows/ossf-scorecard.yml b/.github/workflows/ossf-scorecard.yml index 9d55751c1..65e1472ea 100644 --- a/.github/workflows/ossf-scorecard.yml +++ b/.github/workflows/ossf-scorecard.yml @@ -43,6 +43,6 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 + uses: github/codeql-action/upload-sarif@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # v3 with: sarif_file: results.sarif diff --git a/.github/workflows/sast.yml b/.github/workflows/sast.yml index eef65c05a..a8f0ece4a 100644 --- a/.github/workflows/sast.yml +++ b/.github/workflows/sast.yml @@ -34,12 +34,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 + uses: github/codeql-action/init@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # v3 with: languages: go build-mode: autobuild - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@883d8588e56d1753a8a58c1c86e88976f0c23449 # v3 + uses: github/codeql-action/analyze@f0f3afee809481da311ca3a6ff1ff51d81dbeb24 # v3 with: category: "/language:go" diff --git a/.github/workflows/tests.yml b/.github/workflows/validate.yml similarity index 50% rename from .github/workflows/tests.yml rename to .github/workflows/validate.yml index e56750eb1..c725d7208 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/validate.yml @@ -13,8 +13,110 @@ concurrency: permissions: read-all jobs: + ############################################################################## + # Run all the code generators; and refresh the LICENSES-3rdparty.csv file + generate: + runs-on: ubuntu-latest + name: Run all generators + outputs: + has-patch: ${{ steps.is-tree-dirty.outputs.result }} + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - name: Setup go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 + with: + go-version: stable + cache-dependency-path: '**/go.mod' + + - name: Run 'go generate ./...' + run: |- + mkdir -p ${GOCOVERDIR} + go generate ./... + go -C _integration-tests generate ./... + env: + GOFLAGS: -covermode=atomic -coverpkg=github.com/datadog/orchestrion/... + GOCOVERDIR: ${{ github.workspace }}/coverage + - name: Consolidate coverage report + if: always() && github.event_name != 'merge_group' + run: go tool covdata textfmt -i ./coverage -o ./coverage/generator.out + - name: Upload coverage report + # We want this even if the tests failed + if: always() && github.event_name != 'merge_group' + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: ${{ runner.os }},${{ runner.arch }},generator + file: ./coverage/generator.out + name: Generators + + - name: Run 'go mod tidy' + # Don't run for push, it's not necessary + if: github.event_name != 'push' + run: find . -iname go.mod -execdir go mod tidy \; + + - name: Refresh LICENSE-3rdparty.csv + run: ./tools/make-licenses.sh + env: + TMPDIR: ${{ runner.temp }} + + - name: Check if working tree is dirty + # Don't run for push, it's not necessary + if: github.event_name != 'push' + id: is-tree-dirty + run: |- + git add . + git diff --staged --patch --exit-code > .repo.patch || echo "result=true" >> ${GITHUB_OUTPUT} + - name: Upload patch + if: github.event_name != 'push' && steps.is-tree-dirty.outputs.result == 'true' + uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a # v4 + with: + name: repo.patch + path: .repo.patch + - name: Fail build if working tree is dirty + if: github.event_name == 'push' && steps.is-tree-dirty.outputs.result == 'true' + run: |- + echo "::error::Files have been modified by 'go generate ./...' (see logs)." + cat .repo.patch + exit 1 + ############################################################################## + # If the generators changed anything, and we can update the PR, then we'll + # proactively do it with the mutator token. + self-mutation: + needs: generate + runs-on: ubuntu-latest + name: Update PR with generated files + if: always() && needs.generate.outputs.has-patch == 'true' && github.event_name == 'pull_request' && (github.event.pull_request.head.repo.full_name == github.repository || github.event.pull_request.maintainer_can_modify) + steps: + - name: Checkout + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + - name: Download patch + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 + with: + name: repo.patch + path: ${{ runner.temp }} + - name: Apply patch + run: |- + [ -s '${{ runner.temp }}/.repo.patch' ] && git apply '${{ runner.temp }}/.repo.patch' || echo 'Empty patch. Skipping.' + # We use ghcommit to create signed commits directly using the GitHub API + - name: Push changes + uses: planetscale/ghcommit-action@c7915d6c18d5ce4eb42b0eff3f10a29fe0766e4c # v0.1.44 + with: + commit_message: "chore: update generated files" + repo: ${{ github.event.pull_request.head.repo.full_name }} + branch: ${{ github.event.pull_request.head.ref }} + env: + GITHUB_TOKEN: ${{ secrets.MUTATOR_GITHUB_TOKEN }} + + ############################################################################## + # Run the various linters we have set up... lint: + needs: generate runs-on: ubuntu-latest + name: Go Linters steps: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 @@ -33,15 +135,21 @@ jobs: - name: vet run: go vet ./... + ############################################################################## + # Verify all GitHub workflows have hash-pinned actions lint-workflows: runs-on: ubuntu-latest + name: GitHub Workflow Linters steps: - name: Checkout uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 - name: Ensure SHA pinned actions uses: zgosalvez/github-actions-ensure-sha-pinned-actions@b88cd0aad2c36a63e42c71f81cb1958fed95ac87 # v3 + ############################################################################## + # Run all unit tests with coverage enabled unit-tests: + needs: generate runs-on: ubuntu-latest strategy: fail-fast: false @@ -76,7 +184,10 @@ jobs: files: ./coverage/unit.out,./coverage/integration.out name: Unit Tests (go ${{ matrix.go-version }}) + ############################################################################## + # Run all integration tests and gather extensive coverage integration-tests: + needs: generate strategy: fail-fast: false matrix: @@ -104,7 +215,7 @@ jobs: - name: Setup python uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 with: - python-version: '>=3.9 <3.13' + python-version: 3.x cache: pip cache-dependency-path: _integration-tests/utils/agent/requirements.txt - name: Install python dependencies @@ -151,16 +262,53 @@ jobs: files: ./coverage/integration.out name: Integration Tests (go ${{ matrix.go-version }}, ${{ matrix.runs-on }}, ${{ matrix.build-mode }}) - # This is just a join point intended to simplify branch protection settings + ############################################################################## + # Assert everything is complete. This simplifies branch protection settings + # and allows us to have one single trigger for CodeCov reporting. complete: runs-on: ubuntu-latest + name: Complete needs: + - generate - lint - lint-workflows - unit-tests - integration-tests if: '!cancelled()' steps: + - name: Checkout + if: github.event_name == 'pull_request' + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - name: Download codecov CLI + if: github.event_name == 'pull_request' + run: |- + set -euo pipefail + + curl -fSsL "${BASE_URL}" -o "./codecov" + curl -fSsL "${BASE_URL}.SHA256SUM" -o "./codecov.SHA256SUM" + curl -fSsL "${BASE_URL}.SHA256SUM.sig" -o "./codecov.SHA256SUM.sig" + + # Import the CodeCov security key + curl -fSsL "https://keybase.io/codecovsecurity/pgp_keys.asc" | gpg --no-default-keyring --keyring trustedkeys.gpg --import + + # Verify the downloaded binary matches expected signatures + gpgv "./codecov.SHA256SUM.sig" "./codecov.SHA256SUM" + shasum -a 256 -c "./codecov.SHA256SUM" + + chmod a+x "./codecov" + env: + BASE_URL: https://cli.codecov.io/latest/linux${{ runner.arch == 'ARM64' && '-arm64' || '' }}/codecov + working-directory: ${{ runner.temp }} + - name: Trigger CodeCov notifications + if: github.event_name == 'pull_request' + run: |- + ${{ runner.temp }}/codecov send-notifications \ + --token="${CODECOV_TOKEN}" \ + --fail-on-error \ + --slug=${{ github.event.pull_request.base.repo.full_name }} \ + --sha=${{ github.event.pull_request.head.sha }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - name: Done if: needs.lint.result == 'success' && needs.lint-workflows.result == 'success' && needs.unit-tests.result == 'success' && needs.integration-tests.result == 'success' run: echo "OK" diff --git a/.github/workflows/workflow_call.yml b/.github/workflows/workflow_call.yml index d95b9b59a..91c8c458a 100644 --- a/.github/workflows/workflow_call.yml +++ b/.github/workflows/workflow_call.yml @@ -44,7 +44,7 @@ jobs: - name: Setup python uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5 with: - python-version: '>=3.9 <3.13' + python-version: 3.x cache: pip cache-dependency-path: orchestrion/_integration-tests/utils/agent/requirements.txt - name: Install python dependencies diff --git a/_integration-tests/utils/agent/requirements.txt b/_integration-tests/utils/agent/requirements.txt index c6c293e01..5a3c8d83b 100644 --- a/_integration-tests/utils/agent/requirements.txt +++ b/_integration-tests/utils/agent/requirements.txt @@ -1 +1,20 @@ -ddapm-test-agent~=1.17.0 +ddapm-test-agent==1.17.0 +## The following requirements were added by pip freeze: +aiohappyeyeballs==2.4.0 +aiohttp==3.10.5 +aiosignal==1.3.1 +async-timeout==4.0.3 +attrs==24.2.0 +certifi==2024.7.4 +charset-normalizer==3.3.2 +ddsketch==3.0.1 +frozenlist==1.4.1 +idna==3.7 +msgpack==1.0.8 +multidict==6.0.5 +protobuf==5.27.3 +requests==2.32.3 +six==1.16.0 +typing_extensions==4.12.2 +urllib3==2.2.2 +yarl==1.9.4 diff --git a/codecov.yml b/codecov.yml index 5ab368bf9..114c2a4c1 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,7 +3,11 @@ codecov: require_ci_to_pass: true notify: - wait_for_ci: true + manual_trigger: true + +comment: + layout: diff, components, files + behavior: new ignore: - '**/generator/main.go' # Generators are not actually part of the product @@ -23,9 +27,6 @@ coverage: target: auto informational: true -comment: - require_changes: true - component_management: individual_components: - component_id: instruments diff --git a/internal/injector/builtin/generator/doc.go b/internal/injector/builtin/generator/doc.go index d49cce00e..164465805 100644 --- a/internal/injector/builtin/generator/doc.go +++ b/internal/injector/builtin/generator/doc.go @@ -8,7 +8,6 @@ package main import ( "bytes" "fmt" - "io" "os" "path/filepath" "text/template" @@ -37,15 +36,3 @@ func documentConfiguration(dir, yamlFile string, config *ConfigurationFile) erro } return os.WriteFile(filename, buf.Bytes(), 0o644) } - -func writeFmt(buf io.Writer, format string, args ...any) { - if _, err := fmt.Fprintf(buf, format, args...); err != nil { - panic(err) - } -} - -func writeLine(buf io.Writer, line string) { - if _, err := fmt.Fprintln(buf, line); err != nil { - panic(err) - } -}