Skip to content

Commit

Permalink
Use builtin tracing machinery of aws-sdk-go-v2 (#49826)
Browse files Browse the repository at this point in the history
Replaces the use of go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws
with the tracing support now provided directly by the aws sdk.
See aws/aws-sdk-go-v2#2810 for more
details.

Some additional aws clients were also updated to include tracing
support.
  • Loading branch information
rosstimothy authored Dec 6, 2024
1 parent 1bed1ad commit 460ac5e
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 36 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2
github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin v1.1.0
github.com/aws/smithy-go v1.22.1
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20241128053516-b9e7404a33c3
github.com/beevik/etree v1.4.1
github.com/buildkite/bintest/v3 v3.3.0
Expand Down Expand Up @@ -187,7 +188,6 @@ require (
go.etcd.io/etcd/api/v3 v3.5.17
go.etcd.io/etcd/client/v3 v3.5.17
go.mongodb.org/mongo-driver v1.14.0
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0
go.opentelemetry.io/otel v1.32.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin v1.1.0/go.mod h1:AxK
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2 h1:QRzksLadP0+ddubqgdVrmNlGWEwv2c4gyZXG7wrx+V8=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2/go.mod h1:ZQD5d3TZpTct86y+1Q8pvnhp/BB1UTRUZXEyLyV7eC8=
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20241128053516-b9e7404a33c3 h1:Z0GhCczQLlS/GRRS/suhoVxqU4Oz4CftHRd+Kdj22Uo=
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20241128053516-b9e7404a33c3/go.mod h1:7GP/HkcmpkFy6JyDSTKfdN6PNWCpMgsVMpwTkQwvVc4=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
Expand Down Expand Up @@ -2289,8 +2291,6 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 h1:TiaiXB4DpGD3sdzNlYQxruQngn5Apwzi1X0DRhuGvDQ=
go.opentelemetry.io/contrib/detectors/gcp v1.29.0/go.mod h1:GW2aWZNwR2ZxDLdv8OyC2G8zkRoQBuURgV7RPQgcPoU=
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0 h1:G47XgH32CEM1I9kZ8xrVExSxivATGHNE0tdxuqlx9MQ=
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0/go.mod h1:aqXlYGrumc8b/n4z9eDHHoiLN4fq2DAO//wMnqdxPhg=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 h1:qtFISDHKolvIxzSs0gIaiPUPR0Cucb0F2coHC7ZLdps=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0/go.mod h1:Y+Pop1Q6hCOnETWTW4NROK/q1hv50hM7yDaUTjG8lp8=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw=
Expand Down
1 change: 1 addition & 0 deletions integrations/event-handler/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
github.com/aws/smithy-go v1.22.1 // indirect
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2 // indirect
github.com/beevik/etree v1.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions integrations/event-handler/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 h1:s4074ZO1Hk8qv65GqNXqDjmkf4HS
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2/go.mod h1:mVggCnIWoM09jP71Wh+ea7+5gAp53q+49wDFs1SW5z8=
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2 h1:QRzksLadP0+ddubqgdVrmNlGWEwv2c4gyZXG7wrx+V8=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2/go.mod h1:ZQD5d3TZpTct86y+1Q8pvnhp/BB1UTRUZXEyLyV7eC8=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/beevik/etree v1.4.1 h1:PmQJDDYahBGNKDcpdX8uPy1xRCwoCGVUiW669MEirVI=
github.com/beevik/etree v1.4.1/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs=
Expand Down
1 change: 1 addition & 0 deletions integrations/terraform/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.2 // indirect
github.com/aws/smithy-go v1.22.1 // indirect
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2 // indirect
github.com/beevik/etree v1.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integrations/terraform/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin v1.1.0 h1:EJsHUYgFBV
github.com/aws/aws-sigv4-auth-cassandra-gocql-driver-plugin v1.1.0/go.mod h1:AxKuXHc0zv2yYaeueUG7R3ONbcnQIuDj0bkdFmPVRzU=
github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro=
github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2 h1:QRzksLadP0+ddubqgdVrmNlGWEwv2c4gyZXG7wrx+V8=
github.com/aws/smithy-go/tracing/smithyoteltracing v1.0.2/go.mod h1:ZQD5d3TZpTct86y+1Q8pvnhp/BB1UTRUZXEyLyV7eC8=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/beevik/etree v1.4.1 h1:PmQJDDYahBGNKDcpdX8uPy1xRCwoCGVUiW669MEirVI=
github.com/beevik/etree v1.4.1/go.mod h1:gPNJNaBGVZ9AwsidazFZyygnd+0pAU38N4D+WemwKNs=
Expand Down Expand Up @@ -1947,8 +1949,6 @@ go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/detectors/gcp v1.29.0 h1:TiaiXB4DpGD3sdzNlYQxruQngn5Apwzi1X0DRhuGvDQ=
go.opentelemetry.io/contrib/detectors/gcp v1.29.0/go.mod h1:GW2aWZNwR2ZxDLdv8OyC2G8zkRoQBuURgV7RPQgcPoU=
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0 h1:G47XgH32CEM1I9kZ8xrVExSxivATGHNE0tdxuqlx9MQ=
go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0/go.mod h1:aqXlYGrumc8b/n4z9eDHHoiLN4fq2DAO//wMnqdxPhg=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 h1:qtFISDHKolvIxzSs0gIaiPUPR0Cucb0F2coHC7ZLdps=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0/go.mod h1:Y+Pop1Q6hCOnETWTW4NROK/q1hv50hM7yDaUTjG8lp8=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw=
Expand Down
4 changes: 4 additions & 0 deletions lib/auth/join/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/sts"
smithyendpoints "github.com/aws/smithy-go/endpoints"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/gravitational/trace"
"go.opentelemetry.io/otel"

cloudaws "github.com/gravitational/teleport/lib/cloud/imds/aws"
)
Expand Down Expand Up @@ -112,6 +114,8 @@ func CreateSignedSTSIdentityRequest(ctx context.Context, challenge string, opts
// httpRequestRecorder intentionally records the request and returns
// an error, don't retry.
stsOpts.RetryMaxAttempts = 1

stsOpts.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})

if _, err = stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{}); !errors.Is(err, errRequestRecorded) {
Expand Down
10 changes: 8 additions & 2 deletions lib/auth/join_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ec2"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/digitorus/pkcs7"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"go.opentelemetry.io/otel"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/lib/services"
Expand All @@ -61,7 +63,9 @@ func ec2ClientFromConfig(ctx context.Context, cfg aws.Config) ec2Client {
if ok {
return ec2Client
}
return ec2.NewFromConfig(cfg)
return ec2.NewFromConfig(cfg, func(o *ec2.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}

// checkEC2AllowRules checks that the iid matches at least one of the allow
Expand Down Expand Up @@ -96,7 +100,9 @@ func checkInstanceRunning(ctx context.Context, instanceID, region, IAMRole strin

// assume the configured IAM role if necessary
if IAMRole != "" {
stsClient := sts.NewFromConfig(awsClientConfig)
stsClient := sts.NewFromConfig(awsClientConfig, func(o *sts.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
creds := stscreds.NewAssumeRoleProvider(stsClient, IAMRole)
awsClientConfig.Credentials = aws.NewCredentialsCache(creds)
}
Expand Down
10 changes: 8 additions & 2 deletions lib/auth/keystore/aws_kms.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ import (
"github.com/aws/aws-sdk-go-v2/service/kms"
kmstypes "github.com/aws/aws-sdk-go-v2/service/kms/types"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"go.opentelemetry.io/otel"
"golang.org/x/sync/errgroup"

"github.com/gravitational/teleport/api/types"
Expand Down Expand Up @@ -81,10 +83,14 @@ func newAWSKMSKeystore(ctx context.Context, cfg *servicecfg.AWSKMSConfig, opts *
return nil, trace.Wrap(err, "loading default AWS config")
}
if stsClient == nil {
stsClient = sts.NewFromConfig(awsCfg)
stsClient = sts.NewFromConfig(awsCfg, func(o *sts.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}
if kmsClient == nil {
kmsClient = kms.NewFromConfig(awsCfg)
kmsClient = kms.NewFromConfig(awsCfg, func(o *kms.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}
}
id, err := stsClient.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
Expand Down
12 changes: 8 additions & 4 deletions lib/backend/dynamo/dynamodbbk.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ import (
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/aws/aws-sdk-go-v2/service/dynamodbstreams"
streamtypes "github.com/aws/aws-sdk-go-v2/service/dynamodbstreams/types"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
"go.opentelemetry.io/otel"

"github.com/gravitational/teleport"
"github.com/gravitational/teleport/api/utils"
Expand Down Expand Up @@ -282,7 +283,12 @@ func New(ctx context.Context, params backend.Params) (*Backend, error) {
return nil, trace.Wrap(err)
}

dynamoOpts := []func(*dynamodb.Options){dynamodb.WithEndpointResolverV2(dynamoResolver)}
dynamoOpts := []func(*dynamodb.Options){
dynamodb.WithEndpointResolverV2(dynamoResolver),
func(o *dynamodb.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
},
}

// FIPS settings are applied on the individual service instead of the aws config,
// as DynamoDB Streams and Application Auto Scaling do not yet have FIPS endpoints in non-GovCloud.
Expand All @@ -293,8 +299,6 @@ func New(ctx context.Context, params backend.Params) (*Backend, error) {
})
}

otelaws.AppendMiddlewares(&awsConfig.APIOptions, otelaws.WithAttributeSetter(otelaws.DynamoDBAttributeSetter))

dynamoClient := dynamodb.NewFromConfig(awsConfig, dynamoOpts...)

streamsResolver, err := endpoint.NewLoggingResolver(
Expand Down
6 changes: 5 additions & 1 deletion lib/cloud/aws/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/gravitational/trace"
"go.opentelemetry.io/otel"

"github.com/gravitational/teleport/lib/modules"
)
Expand Down Expand Up @@ -221,7 +223,9 @@ func getAWSConfigForRole(ctx context.Context, region string, options awsOptions)
return aws.Config{}, trace.Wrap(err)
}

stsClient := sts.NewFromConfig(*options.baseConfig)
stsClient := sts.NewFromConfig(*options.baseConfig, func(o *sts.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
cred := stscreds.NewAssumeRoleProvider(stsClient, options.assumeRoleARN, func(aro *stscreds.AssumeRoleOptions) {
if options.assumeRoleExternalID != "" {
aro.ExternalID = aws.String(options.assumeRoleExternalID)
Expand Down
18 changes: 14 additions & 4 deletions lib/configurators/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ssm"
ssmtypes "github.com/aws/aws-sdk-go-v2/service/ssm/types"
"github.com/aws/aws-sdk-go-v2/service/sts"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/gravitational/trace"
"go.opentelemetry.io/otel"

"github.com/gravitational/teleport/api/types"
apiutils "github.com/gravitational/teleport/api/utils"
Expand Down Expand Up @@ -388,10 +390,14 @@ func (c *ConfiguratorConfig) CheckAndSetDefaults() error {
}

if c.stsClient == nil {
c.stsClient = sts.NewFromConfig(*c.awsCfg)
c.stsClient = sts.NewFromConfig(*c.awsCfg, func(o *sts.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}
if c.iamClient == nil {
c.iamClient = iam.NewFromConfig(*c.awsCfg)
c.iamClient = iam.NewFromConfig(*c.awsCfg, func(o *iam.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}
if c.Identity == nil {
c.Identity, err = awslib.GetIdentityWithClientV2(context.Background(), c.stsClient)
Expand All @@ -413,7 +419,9 @@ func (c *ConfiguratorConfig) CheckAndSetDefaults() error {
withRegion := func(o *ssm.Options) {
o.Region = region
}
c.ssmClients[region] = ssm.NewFromConfig(*c.awsCfg, withRegion)
c.ssmClients[region] = ssm.NewFromConfig(*c.awsCfg, withRegion, func(o *ssm.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
}
}

Expand All @@ -422,7 +430,9 @@ func (c *ConfiguratorConfig) CheckAndSetDefaults() error {
if c.Policies == nil {
partition := c.Identity.GetPartition()
accountID := c.Identity.GetAccountID()
iamClient := iam.NewFromConfig(*c.awsCfg)
iamClient := iam.NewFromConfig(*c.awsCfg, func(o *iam.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
c.Policies = awslib.NewPolicies(partition, accountID, iamClient)
}
}
Expand Down
3 changes: 0 additions & 3 deletions lib/events/athena/athena.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws"
oteltrace "go.opentelemetry.io/otel/trace"

"github.com/gravitational/teleport"
Expand Down Expand Up @@ -296,7 +295,6 @@ func (cfg *Config) CheckAndSetDefaults(ctx context.Context) error {
if cfg.Region != "" {
awsCfg.Region = cfg.Region
}
otelaws.AppendMiddlewares(&awsCfg.APIOptions)
cfg.PublisherConsumerAWSConfig = &awsCfg
}

Expand Down Expand Up @@ -452,7 +450,6 @@ func (cfg *Config) UpdateForExternalAuditStorage(ctx context.Context, externalAu
if err != nil {
return trace.Wrap(err)
}
otelaws.AppendMiddlewares(&awsCfg.APIOptions)
cfg.StorerQuerierAWSConfig = &awsCfg

cfg.ObserveWriteEventsError = externalAuditStorage.ErrorCounter.ObserveEmitError
Expand Down
20 changes: 17 additions & 3 deletions lib/events/athena/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ import (
s3Types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/aws-sdk-go-v2/service/sqs"
sqsTypes "github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/google/uuid"
"github.com/gravitational/trace"
"github.com/parquet-go/parquet-go"
"go.opentelemetry.io/otel"

"github.com/gravitational/teleport"
apievents "github.com/gravitational/teleport/api/types/events"
Expand Down Expand Up @@ -121,14 +123,26 @@ func newConsumer(cfg Config, cancelFn context.CancelFunc) (*consumer, error) {
t.MaxIdleConns = defaults.HTTPMaxIdleConns
t.MaxIdleConnsPerHost = defaults.HTTPMaxIdleConnsPerHost
})
sqsClient := sqs.NewFromConfig(*cfg.PublisherConsumerAWSConfig, func(o *sqs.Options) { o.HTTPClient = sqsHTTPClient })
sqsClient := sqs.NewFromConfig(*cfg.PublisherConsumerAWSConfig,
func(o *sqs.Options) {
o.HTTPClient = sqsHTTPClient
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})

s3HTTPClient := awshttp.NewBuildableClient().WithTransportOptions(func(t *http.Transport) {
t.MaxIdleConns = defaults.HTTPMaxIdleConns
t.MaxIdleConnsPerHost = defaults.HTTPMaxIdleConnsPerHost
})
publisherS3Client := s3.NewFromConfig(*cfg.PublisherConsumerAWSConfig, func(o *s3.Options) { o.HTTPClient = s3HTTPClient })
storerS3Client := s3.NewFromConfig(*cfg.StorerQuerierAWSConfig, func(o *s3.Options) { o.HTTPClient = s3HTTPClient })
publisherS3Client := s3.NewFromConfig(*cfg.PublisherConsumerAWSConfig,
func(o *s3.Options) {
o.HTTPClient = s3HTTPClient
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})
storerS3Client := s3.NewFromConfig(*cfg.StorerQuerierAWSConfig,
func(o *s3.Options) {
o.HTTPClient = s3HTTPClient
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})

collectCfg := sqsCollectConfig{
sqsReceiver: sqsClient,
Expand Down
9 changes: 7 additions & 2 deletions lib/events/athena/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import (
snstypes "github.com/aws/aws-sdk-go-v2/service/sns/types"
"github.com/aws/aws-sdk-go-v2/service/sqs"
sqstypes "github.com/aws/aws-sdk-go-v2/service/sqs/types"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/google/uuid"
"github.com/gravitational/trace"
"go.opentelemetry.io/otel"

apievents "github.com/gravitational/teleport/api/types/events"
"github.com/gravitational/teleport/lib/defaults"
Expand Down Expand Up @@ -183,18 +185,21 @@ func newPublisherFromAthenaConfig(cfg Config) *publisher {
messagePublisher = SQSPublisherFunc(cfg.QueueURL, sqs.NewFromConfig(*cfg.PublisherConsumerAWSConfig, func(o *sqs.Options) {
o.Retryer = r
o.HTTPClient = hc
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
}))
} else {
messagePublisher = SNSPublisherFunc(cfg.TopicARN, sns.NewFromConfig(*cfg.PublisherConsumerAWSConfig, func(o *sns.Options) {
o.Retryer = r
o.HTTPClient = hc
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
}))
}

return NewPublisher(PublisherConfig{
MessagePublisher: messagePublisher,
// TODO(tobiaszheller): consider reworking lib/observability to work also on s3 sdk-v2.
Uploader: s3manager.NewUploader(s3.NewFromConfig(*cfg.PublisherConsumerAWSConfig)),
Uploader: s3manager.NewUploader(s3.NewFromConfig(*cfg.PublisherConsumerAWSConfig, func(o *s3.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
})),
PayloadBucket: cfg.largeEventsBucket,
PayloadPrefix: cfg.largeEventsPrefix,
})
Expand Down
10 changes: 8 additions & 2 deletions lib/events/athena/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ import (
athenaTypes "github.com/aws/aws-sdk-go-v2/service/athena/types"
"github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/aws/smithy-go/tracing/smithyoteltracing"
"github.com/dustin/go-humanize"
"github.com/google/uuid"
"github.com/gravitational/trace"
"github.com/jonboulle/clockwork"
"github.com/parquet-go/parquet-go"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
oteltrace "go.opentelemetry.io/otel/trace"

Expand Down Expand Up @@ -148,8 +150,12 @@ func newQuerier(cfg querierConfig) (*querier, error) {
return nil, trace.Wrap(err)
}
return &querier{
athenaClient: athena.NewFromConfig(*cfg.awsCfg),
s3Getter: s3.NewFromConfig(*cfg.awsCfg),
athenaClient: athena.NewFromConfig(*cfg.awsCfg, func(o *athena.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
}),
s3Getter: s3.NewFromConfig(*cfg.awsCfg, func(o *s3.Options) {
o.TracerProvider = smithyoteltracing.Adapt(otel.GetTracerProvider())
}),
querierConfig: cfg,
}, nil
}
Expand Down
Loading

0 comments on commit 460ac5e

Please sign in to comment.