diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e0d625e75..0fdeecf40 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -46,6 +46,15 @@ updates: schedule: interval: weekly day: sunday + - package-ecosystem: docker + directory: /internal/test/e2e/autosdk + labels: + - dependencies + - docker + - Skip Changelog + schedule: + interval: weekly + day: sunday - package-ecosystem: docker directory: /internal/test/e2e/databasesql labels: @@ -154,6 +163,15 @@ updates: schedule: interval: weekly day: sunday + - package-ecosystem: gomod + directory: /internal/test/e2e/autosdk + labels: + - dependencies + - go + - Skip Changelog + schedule: + interval: weekly + day: sunday - package-ecosystem: gomod directory: /internal/test/e2e/databasesql labels: diff --git a/Makefile b/Makefile index 252b39b0f..6605b0d64 100644 --- a/Makefile +++ b/Makefile @@ -152,18 +152,23 @@ license-header-check: exit 1; \ fi -.PHONY: fixture-nethttp fixture-gin fixture-databasesql fixture-nethttp-custom fixture-otelglobal fixture-kafka-go +.PHONY: fixture-nethttp fixture-gin fixture-databasesql fixture-nethttp-custom fixture-otelglobal fixture-autosdk fixture-kafka-go fixture-nethttp-custom: fixtures/nethttp_custom fixture-nethttp: fixtures/nethttp fixture-gin: fixtures/gin fixture-databasesql: fixtures/databasesql fixture-grpc: fixtures/grpc fixture-otelglobal: fixtures/otelglobal +fixture-autosdk: fixtures/autosdk fixture-kafka-go: fixtures/kafka-go fixtures/%: LIBRARY=$* fixtures/%: $(MAKE) docker-build - cd internal/test/e2e/$(LIBRARY) && docker build -t sample-app . + if [ -f ./internal/test/e2e/$(LIBRARY)/build.sh ]; then \ + ./internal/test/e2e/$(LIBRARY)/build.sh; \ + else \ + cd internal/test/e2e/$(LIBRARY) && docker build --build-context ../../../../ -t sample-app . ;\ + fi kind create cluster kind load docker-image otel-go-instrumentation sample-app helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts diff --git a/internal/test/e2e/autosdk/Dockerfile b/internal/test/e2e/autosdk/Dockerfile new file mode 100644 index 000000000..951a88106 --- /dev/null +++ b/internal/test/e2e/autosdk/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.23.1 +# Make sure this dir exists. +WORKDIR /usr/src/go.opentelemetry.io/auto/internal/test/e2e/autosdk + +COPY sdk/ /usr/src/go.opentelemetry.io/auto/sdk/ + +# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading +# them in subsequent builds if they change +COPY internal/test/e2e/autosdk/go.mod internal/test/e2e/autosdk/go.sum ./ +RUN go mod download && go mod verify + +COPY internal/test/e2e/autosdk/main.go . +RUN go build -v -o /sample-app/main + +WORKDIR /sample-app + +CMD ["/sample-app/main"] diff --git a/internal/test/e2e/autosdk/build.sh b/internal/test/e2e/autosdk/build.sh new file mode 100755 index 000000000..d4cfa55b4 --- /dev/null +++ b/internal/test/e2e/autosdk/build.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +usage() { + local progname + progname="$( basename "$0" )" + + cat <<-EOF + Usage: $progname [OPTIONS] + + Builds the SDK end-to-end testing docker image. + + OPTIONS: + -t --tag Docker tag to use ["sample-app"] + -h --help Show this help message + EOF +} + +parse_opts() { + # Make sure getopts starts at the begining + OPTIND=1 + + local deliminator option + local arg= + + # Translate --gnu-long-options to -g (short options) + for arg + do + deliminator="" + case "$arg" in + --tag) + args="${args}-d " + ;; + --help) + args="${args}-h " + ;; + *) + [[ "${arg:0:1}" == "-" ]] || deliminator='"' + args="${args}${deliminator}${arg}${deliminator} " + ;; + esac + done + + # Reset the positional parameters to start parsing short options + eval set -- "$args" + + while getopts ":t:h" option + do + case "$option" in + t) + readonly TAG="$OPTARG" + ;; + h) + usage + exit 0 + ;; + *) + echo "Invalid option: -${option}" >&2 + usage + exit 1 + ;; + esac + done + + # Default values + [ -z "${TAG}" ] \ + && readonly TAG="sample-app" + + return 0 +} + +build() { + local root_dir="$1" + local local_dir="$2" + local dockerfile="${local_dir}/Dockerfile" + local tag_arg + + if [ ! -f "$dockerfile" ]; then + echo "Dockerfile does not exist: $dockerfile" + return 1 + fi + + if [ ! -d "$root_dir" ]; then + echo "Project root directory does not exist: $root_dir" + return 1 + fi + + if [ -n "$TAG" ]; then + tag_arg=("-t" "$TAG") + fi + + (cd "$root_dir" && docker build "${tag_arg[@]}" -f "$dockerfile" .) + return 0 +} + +main() { + local root_dir script_dir + + # Check dependencies + hash git 2>/dev/null\ + || { echo >&2 "Requrired git client not found"; exit 1; } + hash docker 2>/dev/null\ + || { echo >&2 "Requrired docker client not found"; exit 1; } + + parse_opts "$@" + + root_dir=$( git rev-parse --show-toplevel ) + script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + build "$root_dir" "$script_dir" +} + +main "$@" diff --git a/internal/test/e2e/autosdk/go.mod b/internal/test/e2e/autosdk/go.mod new file mode 100644 index 000000000..26745bb69 --- /dev/null +++ b/internal/test/e2e/autosdk/go.mod @@ -0,0 +1,26 @@ +module go.opentelemetry.io/auto/internal/test/e2e/autosdk + +go 1.22.0 + +require ( + go.opentelemetry.io/auto/sdk v0.0.0-00010101000000-000000000000 + go.opentelemetry.io/otel v1.30.0 + go.opentelemetry.io/otel/trace v1.30.0 +) + +require ( + github.com/gogo/protobuf v1.3.2 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + go.opentelemetry.io/collector/pdata v1.15.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + golang.org/x/net v0.26.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.16.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect + google.golang.org/grpc v1.66.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) + +replace go.opentelemetry.io/auto/sdk => ../../../../sdk/ diff --git a/internal/test/e2e/autosdk/go.sum b/internal/test/e2e/autosdk/go.sum new file mode 100644 index 000000000..479eceafe --- /dev/null +++ b/internal/test/e2e/autosdk/go.sum @@ -0,0 +1,74 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.opentelemetry.io/collector/pdata v1.15.0 h1:q/T1sFpRKJnjDrUsHdJ6mq4uSqViR/f92yvGwDby/gY= +go.opentelemetry.io/collector/pdata v1.15.0/go.mod h1:2wcsTIiLAJSbqBq/XUUYbi+cP+N87d0jEJzmb9nT19U= +go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= +go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc= +go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= +go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= +golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 h1:1GBuWVLM/KMVUv1t1En5Gs+gFZCNd360GGb4sSxtrhU= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= +google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/test/e2e/autosdk/main.go b/internal/test/e2e/autosdk/main.go new file mode 100644 index 000000000..704fbd82c --- /dev/null +++ b/internal/test/e2e/autosdk/main.go @@ -0,0 +1,74 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "context" + "errors" + "os" + "os/signal" + "time" + + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/trace" + + "go.opentelemetry.io/auto/sdk" +) + +const pkgName = "go.opentelemetry.io/auto/internal/test/e2e/autosdk" + +// Y2K (January 1, 2000). +var y2k = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) + +type app struct { + tracer trace.Tracer +} + +func (a *app) Run(ctx context.Context, user string, admin bool) error { + opts := []trace.SpanStartOption{ + trace.WithAttributes( + attribute.String("user", user), + attribute.Bool("admin", admin), + ), + trace.WithTimestamp(y2k.Add(500 * time.Microsecond)), + } + _, span := a.tracer.Start(ctx, "Run", opts...) + defer span.End(trace.WithTimestamp(y2k.Add(1 * time.Second))) + + return errors.New("broken") +} + +func main() { + // give time for auto-instrumentation to start up + time.Sleep(5 * time.Second) + + provider := sdk.GetTracerProvider() + tracer := provider.Tracer( + pkgName, + trace.WithInstrumentationVersion("v1.23.42"), + trace.WithSchemaURL("https://some_schema"), + ) + app := app{tracer: tracer} + + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + defer stop() + + ctx, span := tracer.Start(ctx, "main", trace.WithTimestamp(y2k)) + defer span.End(trace.WithTimestamp(y2k.Add(5 * time.Second))) + + err := app.Run(ctx, "Alice", true) + if err != nil { + span.SetStatus(codes.Error, "application error") + span.RecordError( + err, + trace.WithAttributes(attribute.Int("impact", 11)), + trace.WithTimestamp(y2k.Add(2*time.Second)), + trace.WithStackTrace(true), + ) + } + + // give time for auto-instrumentation to report signal + time.Sleep(5 * time.Second) +} diff --git a/internal/test/e2e/autosdk/traces.json b/internal/test/e2e/autosdk/traces.json new file mode 100644 index 000000000..53b97d71f --- /dev/null +++ b/internal/test/e2e/autosdk/traces.json @@ -0,0 +1,86 @@ +{ + "resourceSpans": [ + { + "resource": { + "attributes": [ + { + "key": "process.runtime.description", + "value": { + "stringValue": "go version 1.23.1 linux/amd64" + } + }, + { + "key": "process.runtime.name", + "value": { + "stringValue": "go" + } + }, + { + "key": "process.runtime.version", + "value": { + "stringValue": "1.23.1" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "sample-app" + } + }, + { + "key": "telemetry.distro.name", + "value": { + "stringValue": "opentelemetry-go-instrumentation" + } + }, + { + "key": "telemetry.distro.version", + "value": { + "stringValue": "v0.14.0-alpha" + } + }, + { + "key": "telemetry.sdk.language", + "value": { + "stringValue": "go" + } + } + ] + }, + "scopeSpans": [ + { + "scope": { + "name": "go.opentelemetry.io/auto/internal/test/e2e/autosdk", + "version": "v1.23.42" + }, + "spans": [ + { + "traceId": "xxxxx", + "spanId": "xxxxx", + "parentSpanId": "xxxxx", + "flags": 256, + "name": "Run", + "kind": 3, + "startTimeUnixNano": "946684800500000000", + "endTimeUnixNano": "946684801000000000", + "status": {} + }, + { + "traceId": "xxxxx", + "spanId": "xxxxx", + "parentSpanId": "", + "flags": 256, + "name": "main", + "kind": 3, + "startTimeUnixNano": "946684800000000000", + "endTimeUnixNano": "946684805000000000", + "status": {} + } + ], + "schemaUrl": "https://some_schema" + } + ], + "schemaUrl": "https://opentelemetry.io/schemas/1.26.0" + } + ] +} diff --git a/internal/test/e2e/autosdk/verify.bats b/internal/test/e2e/autosdk/verify.bats new file mode 100644 index 000000000..855c0906c --- /dev/null +++ b/internal/test/e2e/autosdk/verify.bats @@ -0,0 +1,70 @@ +#!/usr/bin/env bats + +load ../../test_helpers/utilities.sh + +SCOPE="go.opentelemetry.io/auto/internal/test/e2e/autosdk" + +@test "autosdk :: includes service.name in resource attributes" { + result=$(resource_attributes_received | jq "select(.key == \"service.name\").value.stringValue") + assert_equal "$result" '"sample-app"' +} + +@test "autosdk :: include tracer name in scope" { + result=$(spans_received | jq ".scopeSpans[].scope.name") + assert_equal "$result" "\"$SCOPE\"" +} + +@test "autosdk :: include tracer version in scope" { + result=$(spans_received | jq ".scopeSpans[].scope.version") + assert_equal "$result" '"v1.23.42"' +} + +@test "autosdk :: include schema url" { + result=$(spans_received | jq ".scopeSpans[].schemaUrl") + assert_equal "$result" '"https://some_schema"' +} + +@test "autosdk :: main span :: trace ID" { + trace_id=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"main\")" | jq ".traceId") + assert_regex "$trace_id" ${MATCH_A_TRACE_ID} +} + +@test "autosdk :: main span :: span ID" { + trace_id=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"main\")" | jq ".spanId") + assert_regex "$trace_id" ${MATCH_A_SPAN_ID} +} + +@test "autosdk :: main span :: start time" { + timestamp=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"main\")" | jq ".startTimeUnixNano") + assert_regex "$timestamp" "946684800000000000" +} + +@test "autosdk :: main span :: end time" { + timestamp=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"main\")" | jq ".endTimeUnixNano") + assert_regex "$timestamp" "946684805000000000" +} + +@test "autosdk :: Run span :: trace ID" { + trace_id=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"Run\")" | jq ".traceId") + assert_regex "$trace_id" ${MATCH_A_TRACE_ID} +} + +@test "autosdk :: Run span :: span ID" { + trace_id=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"Run\")" | jq ".spanId") + assert_regex "$trace_id" ${MATCH_A_SPAN_ID} +} + +@test "autosdk :: Run span :: parent span ID" { + parent_span_id=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"Run\")" | jq ".parentSpanId") + assert_regex "$parent_span_id" ${MATCH_A_SPAN_ID} +} + +@test "autosdk :: Run span :: start time" { + timestamp=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"Run\")" | jq ".startTimeUnixNano") + assert_regex "$timestamp" "946684800000500000" +} + +@test "autosdk :: Run span :: end time" { + timestamp=$(spans_from_scope_named ${SCOPE} | jq "select(.name == \"Run\")" | jq ".endTimeUnixNano") + assert_regex "$timestamp" "946684801000000000" +}