diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 09e603f46ed..f12d0f0bdf7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -137,6 +137,24 @@ updates: schedule: interval: "weekly" day: "sunday" + - package-ecosystem: "gomod" + directory: "/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws" + labels: + - dependencies + - go + - "Skip Changelog" + schedule: + interval: "weekly" + day: "sunday" + - package-ecosystem: "gomod" + directory: "/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example" + labels: + - dependencies + - go + - "Skip Changelog" + schedule: + interval: "weekly" + day: "sunday" - package-ecosystem: "gomod" directory: "/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache" diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go new file mode 100644 index 00000000000..50c1775b8af --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go @@ -0,0 +1,40 @@ +// Copyright The OpenTelemetry 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. + +package otelaws + +import "go.opentelemetry.io/otel/attribute" + +const ( + OperationKey attribute.Key = "aws.operation" + RegionKey attribute.Key = "aws.region" + ServiceKey attribute.Key = "aws.service" + RequestIDKey attribute.Key = "aws.request_id" +) + +func OperationAttr(operation string) attribute.KeyValue { + return OperationKey.String(operation) +} + +func RegionAttr(region string) attribute.KeyValue { + return RegionKey.String(region) +} + +func ServiceAttr(service string) attribute.KeyValue { + return ServiceKey.String(service) +} + +func RequestIDAttr(requestID string) attribute.KeyValue { + return RequestIDKey.String(requestID) +} diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go new file mode 100644 index 00000000000..f5f8e94f3df --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws.go @@ -0,0 +1,116 @@ +// Copyright The OpenTelemetry 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. + +package otelaws + +import ( + "context" + "time" + + v2Middleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" + + "go.opentelemetry.io/contrib" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/semconv" + "go.opentelemetry.io/otel/trace" +) + +const ( + tracerName = "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws" +) + +type spanTimestampKey struct{} + +type otelMiddlewares struct { + tracer trace.Tracer +} + +func (m otelMiddlewares) initializeMiddlewareBefore(stack *middleware.Stack) error { + return stack.Initialize.Add(middleware.InitializeMiddlewareFunc("OTelInitializeMiddlewareBefore", func( + ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( + out middleware.InitializeOutput, metadata middleware.Metadata, err error) { + + ctx = context.WithValue(ctx, spanTimestampKey{}, time.Now()) + return next.HandleInitialize(ctx, in) + }), + middleware.Before) +} + +func (m otelMiddlewares) initializeMiddlewareAfter(stack *middleware.Stack) error { + return stack.Initialize.Add(middleware.InitializeMiddlewareFunc("OTelInitializeMiddlewareAfter", func( + ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) ( + out middleware.InitializeOutput, metadata middleware.Metadata, err error) { + + serviceID := v2Middleware.GetServiceID(ctx) + opts := []trace.SpanOption{ + trace.WithTimestamp(ctx.Value(spanTimestampKey{}).(time.Time)), + trace.WithSpanKind(trace.SpanKindClient), + trace.WithAttributes(ServiceAttr(serviceID), + RegionAttr(v2Middleware.GetRegion(ctx)), + OperationAttr(v2Middleware.GetOperationName(ctx))), + } + ctx, span := m.tracer.Start(ctx, serviceID, opts...) + defer span.End() + + out, metadata, err = next.HandleInitialize(ctx, in) + if err != nil { + span.RecordError(err) + } + + return out, metadata, err + }), + middleware.After) +} + +func (m otelMiddlewares) deserializeMiddleware(stack *middleware.Stack) error { + return stack.Deserialize.Add(middleware.DeserializeMiddlewareFunc("OTelDeserializeMiddleware", func( + ctx context.Context, in middleware.DeserializeInput, next middleware.DeserializeHandler) ( + out middleware.DeserializeOutput, metadata middleware.Metadata, err error) { + out, metadata, err = next.HandleDeserialize(ctx, in) + resp, ok := out.RawResponse.(*smithyhttp.Response) + if !ok { + // No raw response to wrap with. + return out, metadata, err + } + + span := trace.SpanFromContext(ctx) + span.SetAttributes(semconv.HTTPStatusCodeKey.Int(resp.StatusCode)) + + requestID, ok := v2Middleware.GetRequestIDMetadata(metadata) + if ok { + span.SetAttributes(RequestIDAttr(requestID)) + } + + return out, metadata, err + }), + middleware.Before) +} + +// AppendMiddlewares attaches OTel middlewares to the AWS Go SDK V2 for instrumentation. +// OTel middlewares can be appended to either all aws clients or a specific operation. +// Please see more details in https://aws.github.io/aws-sdk-go-v2/docs/middleware/ +func AppendMiddlewares(apiOptions *[]func(*middleware.Stack) error, opts ...Option) { + cfg := config{ + TracerProvider: otel.GetTracerProvider(), + } + for _, opt := range opts { + opt.Apply(&cfg) + } + + m := otelMiddlewares{tracer: cfg.TracerProvider.Tracer(tracerName, + trace.WithInstrumentationVersion(contrib.SemVersion()))} + *apiOptions = append(*apiOptions, m.initializeMiddlewareBefore, m.initializeMiddlewareAfter, m.deserializeMiddleware) +} diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws_test.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws_test.go new file mode 100644 index 00000000000..fa39df3a6e4 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/aws_test.go @@ -0,0 +1,165 @@ +// Copyright The OpenTelemetry 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. + +package otelaws + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/route53" + "github.com/aws/aws-sdk-go-v2/service/route53/types" + "github.com/stretchr/testify/assert" + + "go.opentelemetry.io/otel/oteltest" + "go.opentelemetry.io/otel/trace" +) + +func TestAppendMiddlewares(t *testing.T) { + cases := map[string]struct { + responseStatus int + responseBody []byte + expectedRegion string + expectedError string + expectedRequestID string + expectedStatusCode int + }{ + "invalidChangeBatchError": { + responseStatus: 500, + responseBody: []byte(` + + + Tried to create resource record set duplicate.example.com. type A, but it already exists + + b25f48e8-84fd-11e6-80d9-574e0c4664cb + `), + expectedRegion: "us-east-1", + expectedError: "Error", + expectedRequestID: "b25f48e8-84fd-11e6-80d9-574e0c4664cb", + expectedStatusCode: 500, + }, + + "standardRestXMLError": { + responseStatus: 404, + responseBody: []byte(` + + + Sender + MalformedXML + 1 validation error detected: Value null at 'route53#ChangeSet' failed to satisfy constraint: Member must not be null + + 1234567890A + + `), + expectedRegion: "us-west-1", + expectedError: "Error", + expectedRequestID: "1234567890A", + expectedStatusCode: 404, + }, + + "Success response": { + responseStatus: 200, + responseBody: []byte(` + + + mockComment + mockID + + `), + expectedRegion: "us-west-2", + expectedStatusCode: 200, + }, + } + + for name, c := range cases { + server := httptest.NewServer(http.HandlerFunc( + func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(c.responseStatus) + _, err := w.Write(c.responseBody) + if err != nil { + t.Fatal(err) + } + })) + defer server.Close() + + t.Run(name, func(t *testing.T) { + sr := new(oteltest.SpanRecorder) + provider := oteltest.NewTracerProvider(oteltest.WithSpanRecorder(sr)) + + svc := route53.NewFromConfig(aws.Config{ + Region: c.expectedRegion, + EndpointResolver: aws.EndpointResolverFunc(func(service, region string) (aws.Endpoint, error) { + return aws.Endpoint{ + URL: server.URL, + SigningName: "route53", + }, nil + }), + Retryer: func() aws.Retryer { + return aws.NopRetryer{} + }, + }) + _, err := svc.ChangeResourceRecordSets(context.Background(), &route53.ChangeResourceRecordSetsInput{ + ChangeBatch: &types.ChangeBatch{ + Changes: []types.Change{}, + Comment: aws.String("mock"), + }, + HostedZoneId: aws.String("zone"), + }, func(options *route53.Options) { + AppendMiddlewares( + &options.APIOptions, WithTracerProvider(provider)) + }) + + spans := sr.Completed() + assert.Len(t, spans, 1) + span := spans[0] + + if e, a := "Route 53", span.Name(); !strings.EqualFold(e, a) { + t.Errorf("expected span name to be %s, got %s", e, a) + } + + if e, a := trace.SpanKindClient, span.SpanKind(); e != a { + t.Errorf("expected span kind to be %v, got %v", e, a) + } + + if e, a := c.expectedError, span.StatusCode().String(); err != nil && !strings.EqualFold(e, a) { + t.Errorf("Span Error is missing.") + } + + if e, a := c.expectedStatusCode, span.Attributes()["http.status_code"].AsInt64(); e != int(a) { + t.Errorf("expected status code to be %v, got %v", e, a) + } + + if e, a := c.expectedRequestID, span.Attributes()["aws.request_id"].AsString(); !strings.EqualFold(e, a) { + t.Errorf("expected request id to be %s, got %s", e, a) + } + + if e, a := "Route 53", span.Attributes()["aws.service"].AsString(); !strings.EqualFold(e, a) { + t.Errorf("expected service to be %s, got %s", e, a) + } + + if e, a := c.expectedRegion, span.Attributes()["aws.region"].AsString(); !strings.EqualFold(e, a) { + t.Errorf("expected region to be %s, got %s", e, a) + } + + if e, a := "ChangeResourceRecordSets", span.Attributes()["aws.operation"].AsString(); !strings.EqualFold(e, a) { + t.Errorf("expected operation to be %s, got %s", e, a) + } + }) + + } +} diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/config.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/config.go new file mode 100755 index 00000000000..e294acaa5d2 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/config.go @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry 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. + +package otelaws + +import ( + "go.opentelemetry.io/otel/trace" +) + +type config struct { + TracerProvider trace.TracerProvider +} + +// Option applies an option value. +type Option interface { + Apply(*config) +} + +// optionFunc provides a convenience wrapper for simple Options +// that can be represented as functions. +type optionFunc func(*config) + +func (o optionFunc) Apply(c *config) { + o(c) +} + +// WithTracerProvider specifies a tracer provider to use for creating a tracer. +// If none is specified, the global TracerProvider is used. +func WithTracerProvider(provider trace.TracerProvider) Option { + return optionFunc(func(cfg *config) { + cfg.TracerProvider = provider + }) +} diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/Dockerfile b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/Dockerfile new file mode 100644 index 00000000000..173bad43ec7 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/Dockerfile @@ -0,0 +1,20 @@ +# Copyright The OpenTelemetry 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. +FROM golang:1.14-alpine AS base +COPY . /src/ +WORKDIR /src/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws + +FROM base AS aws-client +RUN go install ./example/main.go +CMD ["/go/bin/main"] \ No newline at end of file diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/README.md b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/README.md new file mode 100644 index 00000000000..f61d666588c --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/README.md @@ -0,0 +1,24 @@ +# aws/aws-sdk-go-v2 instrumentation example + +A simple example to demonstrate the AWS SDK V2 for Go instrumentation. In this example, container `aws-sdk-client` initializes a S3 client and a DynamoDB client and runs 2 basic operations: `listS3Buckets` and `listDynamodbTables`. + + +These instructions assume you have +[docker-compose](https://docs.docker.com/compose/) installed and setup, and [AWS credential](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) configured. + +1. From within the `example` directory, bring up the project by running: + + ```sh + docker-compose up --detach + ``` + +2. The instrumentation works with a `stdout` exporter. To inspect the output, you can run: + + ```sh + docker-compose logs + ``` +3. After inspecting the client logs, the example can be cleaned up by running: + + ```sh + docker-compose down + ``` diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/docker-compose.yml b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/docker-compose.yml new file mode 100644 index 00000000000..ad037303265 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/docker-compose.yml @@ -0,0 +1,31 @@ +# Copyright The OpenTelemetry 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. +version: "3.7" +services: + aws-sdk-client: + build: + dockerfile: $PWD/Dockerfile + context: ../../../../../.. + ports: + - "8080:80" + command: + - "/bin/sh" + - "-c" + - "/go/bin/main" + volumes: + - ~/.aws:/root/.aws + networks: + - example +networks: + example: diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod new file mode 100644 index 00000000000..6af9e80f2a8 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod @@ -0,0 +1,20 @@ +module go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example + +go 1.14 + +replace ( + go.opentelemetry.io/contrib => ../../../../../.. + go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws => ../ +) + +require ( + github.com/aws/aws-sdk-go-v2 v1.2.0 + github.com/aws/aws-sdk-go-v2/config v1.1.1 + github.com/aws/aws-sdk-go-v2/service/dynamodb v1.1.1 + github.com/aws/aws-sdk-go-v2/service/s3 v1.2.0 + go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.19.0 + go.opentelemetry.io/otel v0.19.0 + go.opentelemetry.io/otel/exporters/stdout v0.19.0 + go.opentelemetry.io/otel/sdk v0.19.0 + go.opentelemetry.io/otel/trace v0.19.0 +) diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum new file mode 100644 index 00000000000..5378a2d5493 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum @@ -0,0 +1,67 @@ +github.com/aws/aws-sdk-go-v2 v1.2.0 h1:BS+UYpbsElC82gB+2E2jiCBg36i8HlubTB/dO/moQ9c= +github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= +github.com/aws/aws-sdk-go-v2/config v1.1.1 h1:ZAoq32boMzcaTW9bcUacBswAmHTbvlvDJICgHFZuECo= +github.com/aws/aws-sdk-go-v2/config v1.1.1/go.mod h1:0XsVy9lBI/BCXm+2Tuvt39YmdHwS5unDQmxZOYe8F5Y= +github.com/aws/aws-sdk-go-v2/credentials v1.1.1 h1:NbvWIM1Mx6sNPTxowHgS2ewXCRp+NGTzUYb/96FZJbY= +github.com/aws/aws-sdk-go-v2/credentials v1.1.1/go.mod h1:mM2iIjwl7LULWtS6JCACyInboHirisUUdkBPoTHMOUo= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2 h1:EtEU7WRaWliitZh2nmuxEXrN0Cb8EgPUFGIoTMeqbzI= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.0.2/go.mod h1:3hGg3PpiEjHnrkrlasTfxFqUsZ2GCk/fMUn4CbKgSkM= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.1.1 h1:rs3qt8vsrOXgm3qfVdjVkwnPiBXI2M7qN1nExoZmJfI= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.1.1/go.mod h1:0xGVqnX5hK8bd/Qnqklpdellx5/6KPSPV7vfno3i1Sk= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.1 h1:q+3dVb1s3piv/Q/Ft0+OjU5iKItBRfCvU5wNLQUyIbA= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.0.1/go.mod h1:zurGx7QI3Bk2OFwswSXl3PtJDdgD3QzjkfskiukJ2Mg= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2 h1:4AH9fFjUlVktQMznF+YN33aWNXaR4VgDXyP28qokJC0= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.0.2/go.mod h1:45MfaXZ0cNbeuT0KQ1XJylq8A6+OpVV2E5kvY/Kq+u8= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.1.0 h1:6yUvdqgAAWoKAotui7AI4QvJASrjI6rkJtweSyjH6M4= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.1.0/go.mod h1:q+4U7Z1uD6Iimym8uPQp0Ong/XICxInhzIKVSwn7bUU= +github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1 h1:cKr6St+CtC3/dl/rEBJvlk7A/IN5D5F02GNkGzfbtVU= +github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4= +github.com/aws/aws-sdk-go-v2/service/s3 v1.2.0 h1:p20kkvl+DwV3wYsnLGcmsspBzWGD6EsWKi/W+09Z1NI= +github.com/aws/aws-sdk-go-v2/service/s3 v1.2.0/go.mod h1:nHAD0aOk81kN3xdNYzKg4g9JISKSwRdUUDEXOgIojf4= +github.com/aws/aws-sdk-go-v2/service/sso v1.1.1 h1:37QubsarExl5ZuCBlnRP+7l1tNwZPBSTqpTBrPH98RU= +github.com/aws/aws-sdk-go-v2/service/sso v1.1.1/go.mod h1:SuZJxklHxLAXgLTc1iFXbEWkXs7QRTQpCLGaKIprQW0= +github.com/aws/aws-sdk-go-v2/service/sts v1.1.1 h1:TJoIfnIFubCX0ACVeJ0w46HEH5MwjwYN4iFhuYIhfIY= +github.com/aws/aws-sdk-go-v2/service/sts v1.1.1/go.mod h1:Wi0EBZwiz/K44YliU0EKxqTCJGUfYTWXrrBwkq736bM= +github.com/aws/smithy-go v1.1.0 h1:D6CSsM3gdxaGaqXnPgOBCeL6Mophqzu7KJOu7zW78sU= +github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= +github.com/benbjohnson/clock v1.0.3 h1:vkLuvpK4fmtSCuo60+yC63p7y0BmQ8gm5ZXGuBCJyXg= +github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= +go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel/exporters/stdout v0.19.0 h1:6+QJvepCJ/YS3rOlsnjhVo527ohlPowOBgsZThR9Hoc= +go.opentelemetry.io/otel/exporters/stdout v0.19.0/go.mod h1:UI2JnNRaSt9ChIHkk4+uqieH27qKt9isV9e2qRorCtg= +go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= +go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= +go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/sdk v0.19.0 h1:13pQquZyGbIvGxBWcVzUqe8kg5VGbTBiKKKXpYCylRM= +go.opentelemetry.io/otel/sdk v0.19.0/go.mod h1:ouO7auJYMivDjywCHA6bqTI7jJMVQV1HdKR5CmH8DGo= +go.opentelemetry.io/otel/sdk/export/metric v0.19.0 h1:9A1PC2graOx3epRLRWbq4DPCdpMUYK8XeCrdAg6ycbI= +go.opentelemetry.io/otel/sdk/export/metric v0.19.0/go.mod h1:exXalzlU6quLTXiv29J+Qpj/toOzL3H5WvpbbjouTBo= +go.opentelemetry.io/otel/sdk/metric v0.19.0 h1:fka1Zc/lpRMS+KlTP/TRXZuaFtSjUg/maHV3U8rt1Mc= +go.opentelemetry.io/otel/sdk/metric v0.19.0/go.mod h1:t12+Mqmj64q1vMpxHlCGXGggo0sadYxEG6U+Us/9OA4= +go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= +go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/main.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/main.go new file mode 100644 index 00000000000..28951cebf05 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/main.go @@ -0,0 +1,100 @@ +// Copyright The OpenTelemetry 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. + +package main + +import ( + "context" + "fmt" + + "github.com/aws/aws-sdk-go-v2/aws" + awsConfig "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/dynamodb" + "github.com/aws/aws-sdk-go-v2/service/s3" + + "go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/stdout" + sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" +) + +var tp *sdktrace.TracerProvider + +func initTracer() { + var err error + exp, err := stdout.NewExporter(stdout.WithPrettyPrint()) + if err != nil { + fmt.Printf("failed to initialize stdout exporter %v\n", err) + return + } + bsp := sdktrace.NewBatchSpanProcessor(exp) + tp = sdktrace.NewTracerProvider( + sdktrace.WithSpanProcessor(bsp), + ) + otel.SetTracerProvider(tp) + +} + +func main() { + initTracer() + // Create a named tracer with package path as its name. + tracer := tp.Tracer("example/aws/main") + + ctx := context.Background() + defer func() { _ = tp.Shutdown(ctx) }() + + var span trace.Span + ctx, span = tracer.Start(ctx, "AWS Example") + defer span.End() + + // init aws config + cfg, err := awsConfig.LoadDefaultConfig(ctx) + if err != nil { + panic("configuration error, " + err.Error()) + } + + // instrument all aws clients + otelaws.AppendMiddlewares(&cfg.APIOptions) + + // S3 + s3Client := s3.NewFromConfig(cfg) + input := &s3.ListBucketsInput{} + result, err := s3Client.ListBuckets(ctx, input) + if err != nil { + fmt.Printf("Got an error retrieving buckets, %v", err) + return + } + + fmt.Println("Buckets:") + for _, bucket := range result.Buckets { + fmt.Println(*bucket.Name + ": " + bucket.CreationDate.Format("2006-01-02 15:04:05 Monday")) + } + + // DynamoDb + dynamoDbClient := dynamodb.NewFromConfig(cfg) + resp, err := dynamoDbClient.ListTables(ctx, &dynamodb.ListTablesInput{ + Limit: aws.Int32(5), + }) + if err != nil { + fmt.Printf("failed to list tables, %v", err) + return + } + + fmt.Println("Tables:") + for _, tableName := range resp.TableNames { + fmt.Println(tableName) + } + +} diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod new file mode 100644 index 00000000000..a85496fc3ec --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod @@ -0,0 +1,19 @@ +module go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws + +go 1.14 + +replace ( + go.opentelemetry.io/contrib => ../../../../../ + go.opentelemetry.io/contrib/propagators => ../../../../../propagators +) + +require ( + github.com/aws/aws-sdk-go-v2 v1.2.0 + github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1 + github.com/aws/smithy-go v1.1.0 + github.com/stretchr/testify v1.7.0 + go.opentelemetry.io/contrib v0.19.0 + go.opentelemetry.io/otel v0.19.0 + go.opentelemetry.io/otel/oteltest v0.19.0 + go.opentelemetry.io/otel/trace v0.19.0 +) diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum new file mode 100644 index 00000000000..e069a1cc438 --- /dev/null +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum @@ -0,0 +1,34 @@ +github.com/aws/aws-sdk-go-v2 v1.2.0 h1:BS+UYpbsElC82gB+2E2jiCBg36i8HlubTB/dO/moQ9c= +github.com/aws/aws-sdk-go-v2 v1.2.0/go.mod h1:zEQs02YRBw1DjK0PoJv3ygDYOFTre1ejlJWl8FwAuQo= +github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1 h1:cKr6St+CtC3/dl/rEBJvlk7A/IN5D5F02GNkGzfbtVU= +github.com/aws/aws-sdk-go-v2/service/route53 v1.1.1/go.mod h1:rLiOUrPLW/Er5kRcQ7NkwbjlijluLsrIbu/iyl35RO4= +github.com/aws/smithy-go v1.1.0 h1:D6CSsM3gdxaGaqXnPgOBCeL6Mophqzu7KJOu7zW78sU= +github.com/aws/smithy-go v1.1.0/go.mod h1:EzMw8dbp/YJL4A5/sbhGddag+NPT7q084agLbB9LgIw= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= +github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +go.opentelemetry.io/otel v0.19.0 h1:Lenfy7QHRXPZVsw/12CWpxX6d/JkrX8wrx2vO8G80Ng= +go.opentelemetry.io/otel v0.19.0/go.mod h1:j9bF567N9EfomkSidSfmMwIwIBuP37AMAIzVW85OxSg= +go.opentelemetry.io/otel/metric v0.19.0 h1:dtZ1Ju44gkJkYvo+3qGqVXmf88tc+a42edOywypengg= +go.opentelemetry.io/otel/metric v0.19.0/go.mod h1:8f9fglJPRnXuskQmKpnad31lcLJ2VmNNqIsx/uIwBSc= +go.opentelemetry.io/otel/oteltest v0.19.0 h1:YVfA0ByROYqTwOxqHVZYZExzEpfZor+MU1rU+ip2v9Q= +go.opentelemetry.io/otel/oteltest v0.19.0/go.mod h1:tI4yxwh8U21v7JD6R3BcA/2+RBoTKFexE/PJ/nSO7IA= +go.opentelemetry.io/otel/trace v0.19.0 h1:1ucYlenXIDA1OlHVLDZKX0ObXV5RLaq06DtUKz5e5zc= +go.opentelemetry.io/otel/trace v0.19.0/go.mod h1:4IXiNextNOpPnRlI4ryK69mn5iC84bjBWZQA5DXz/qg= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=