Draft
Conversation
|
💚 CLA has been signed |
|
This pull request is now in conflicts. Could you fix it? 🙏 |
# Conflicts:
# internal/uniqueness/leaderelection.go
diff --git a/internal/evaluator/logger.go b/internal/evaluator/logger.go
index fd0ffa72..d8b5a892 100644
--- a/internal/evaluator/logger.go
+++ b/internal/evaluator/logger.go
@@ -18,6 +18,8 @@
package evaluator
import (
+ "context"
+
"github.com/elastic/elastic-agent-libs/logp"
"github.com/open-policy-agent/opa/v1/logging"
"go.uber.org/zap"
@@ -54,7 +56,7 @@ func (l *logger) Info(fmt string, a ...any) {
}
func (l *logger) Error(fmt string, a ...any) {
- l.log.Errorf(fmt, a...)
+ l.log.Errorf(context.TODO(), fmt, a...)
}
func (l *logger) Warn(fmt string, a ...any) {
diff --git a/internal/flavors/assetinventory/strategy_aws.go b/internal/flavors/assetinventory/strategy_aws.go
index ed5b78f8..b3ce4750 100644
--- a/internal/flavors/assetinventory/strategy_aws.go
+++ b/internal/flavors/assetinventory/strategy_aws.go
@@ -103,7 +103,7 @@ func tryListingBuckets(ctx context.Context, log *clog.Logger, roleConfig awssdk.
return true
}
if !strings.Contains(err.Error(), "not authorized to perform: sts:AssumeRole") {
- log.Errorf("Expected a 403 autorization error, but got: %v", err)
+ log.Errorf(ctx, "Expected a 403 autorization error, but got: %v", err)
}
return false
}
diff --git a/internal/flavors/benchmark/aws_org.go b/internal/flavors/benchmark/aws_org.go
index 5e47b88a..a98d59b5 100644
--- a/internal/flavors/benchmark/aws_org.go
+++ b/internal/flavors/benchmark/aws_org.go
@@ -148,7 +148,7 @@ func (a *AWSOrg) getAwsAccounts(ctx context.Context, log *clog.Logger, cfgCloudb
if identity.Account == rootIdentity.Account {
cfg, err := a.pickManagementAccountRole(ctx, log, stsClient, cfgCloudbeatRoot, identity)
if err != nil {
- log.Errorf("error picking roles for account %s: %s", identity.Account, err)
+ log.Errorf(ctx, "error picking roles for account %s: %s", identity.Account, err)
continue
}
awsConfig = cfg
@@ -205,7 +205,7 @@ func (a *AWSOrg) pickManagementAccountRole(ctx context.Context, log *clog.Logger
if foundTagValue == scanSettingTagValue {
_, err := a.IAMProvider.GetRole(ctx, memberRole)
if err != nil {
- log.Errorf("Management Account should be scanned (%s: %s), but %q role is missing: %s", scanSettingTagKey, foundTagValue, memberRole, err)
+ log.Errorf(ctx, "Management Account should be scanned (%s: %s), but %q role is missing: %s", scanSettingTagKey, foundTagValue, memberRole, err)
}
}
diff --git a/internal/flavors/benchmark/eks.go b/internal/flavors/benchmark/eks.go
index d8f3801e..ddece011 100644
--- a/internal/flavors/benchmark/eks.go
+++ b/internal/flavors/benchmark/eks.go
@@ -73,7 +73,7 @@ func (k *EKS) initialize(ctx context.Context, log *clog.Logger, cfg *config.Conf
}
benchmarkHelper := NewK8sBenchmarkHelper(log, cfg, kubeClient)
- k.leaderElector = uniqueness.NewLeaderElector(log, kubeClient)
+ k.leaderElector = uniqueness.NewLeaderElector(log, kubeClient) //nolint:contextcheck
awsConfig, awsIdentity, err := k.getEksAwsConfig(ctx, cfg)
if err != nil {
diff --git a/internal/flavors/benchmark/k8s.go b/internal/flavors/benchmark/k8s.go
index 4617bfc2..fc700f96 100644
--- a/internal/flavors/benchmark/k8s.go
+++ b/internal/flavors/benchmark/k8s.go
@@ -66,7 +66,7 @@ func (k *K8S) initialize(ctx context.Context, log *clog.Logger, cfg *config.Conf
}
benchmarkHelper := NewK8sBenchmarkHelper(log, cfg, kubeClient)
- k.leaderElector = uniqueness.NewLeaderElector(log, kubeClient)
+ k.leaderElector = uniqueness.NewLeaderElector(log, kubeClient) //nolint:contextcheck
dp, err := benchmarkHelper.GetK8sDataProvider(ctx, k8s.KubernetesClusterNameProvider{KubeClient: kubeClient})
if err != nil {
diff --git a/internal/flavors/benchmark/k8s_helper.go b/internal/flavors/benchmark/k8s_helper.go
index 13cbd88f..08f1e751 100644
--- a/internal/flavors/benchmark/k8s_helper.go
+++ b/internal/flavors/benchmark/k8s_helper.go
@@ -48,7 +48,7 @@ func NewK8sBenchmarkHelper(log *clog.Logger, cfg *config.Config, client client_g
func (h *K8SBenchmarkHelper) GetK8sDataProvider(ctx context.Context, clusterNameProvider k8s.ClusterNameProviderAPI) (dataprovider.CommonDataProvider, error) {
clusterName, err := clusterNameProvider.GetClusterName(ctx, h.cfg)
if err != nil {
- h.log.Errorf("failed to get cluster name: %v", err)
+ h.log.Errorf(ctx, "failed to get cluster name: %v", err)
}
serverVersion, err := h.client.Discovery().ServerVersion()
diff --git a/internal/infra/clog/clog.go b/internal/infra/clog/clog.go
index d220a56d..7c7fde88 100644
--- a/internal/infra/clog/clog.go
+++ b/internal/infra/clog/clog.go
@@ -31,13 +31,14 @@ type Logger struct {
*logp.Logger
}
-func (l *Logger) Errorf(template string, args ...any) {
+func (l *Logger) Errorf(ctx context.Context, template string, args ...any) {
+ spanCtx := trace.SpanContextFromContext(ctx)
// Downgrade context.Canceled errors to warning level
if hasErrorType(context.Canceled, args...) {
- l.Warnf(template, args...)
+ l.WithSpanContext(spanCtx).Warnf(template, args...)
return
}
- l.Logger.Errorf(template, args...)
+ l.WithSpanContext(spanCtx).Logger.Errorf(template, args...)
}
func (l *Logger) Error(args ...any) {
diff --git a/internal/infra/clog/clog_test.go b/internal/infra/clog/clog_test.go
index 92469e86..8bd5a11f 100644
--- a/internal/infra/clog/clog_test.go
+++ b/internal/infra/clog/clog_test.go
@@ -46,8 +46,8 @@ func (s *LoggerTestSuite) TestErrorfWithContextCanceled() {
logger := NewLogger("test")
err := context.Canceled
- logger.Errorf("some error: %s", err) // error with context.Canceled
- logger.Errorf("some error: %s", err.Error()) // error string with context Canceled
+ logger.Errorf(context.TODO(), "some error: %s", err) // error with context.Canceled
+ logger.Errorf(context.TODO(), "some error: %s", err.Error()) // error string with context Canceled
logs := logp.ObserverLogs().TakeAll()
if s.Len(logs, 2) {
@@ -62,7 +62,7 @@ func (s *LoggerTestSuite) TestLogErrorfWithoutContextCanceled() {
logger := NewLogger("test")
err := errors.New("oops")
- logger.Errorf("some error: %s", err)
+ logger.Errorf(context.TODO(), "some error: %s", err)
logs := logp.ObserverLogs().TakeAll()
if s.Len(logs, 1) {
diff --git a/internal/inventory/awsfetcher/fetcher_ec2_instance.go b/internal/inventory/awsfetcher/fetcher_ec2_instance.go
index 0c881b2e..d75bd83e 100644
--- a/internal/inventory/awsfetcher/fetcher_ec2_instance.go
+++ b/internal/inventory/awsfetcher/fetcher_ec2_instance.go
@@ -53,7 +53,7 @@ func (e *ec2InstanceFetcher) Fetch(ctx context.Context, assetChannel chan<- inve
instances, err := e.provider.DescribeInstances(ctx)
if err != nil {
- e.logger.Errorf("Could not list ec2 instances: %v", err)
+ e.logger.Errorf(ctx, "Could not list ec2 instances: %v", err)
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_elb.go b/internal/inventory/awsfetcher/fetcher_elb.go
index 5acc55b7..72fa994a 100644
--- a/internal/inventory/awsfetcher/fetcher_elb.go
+++ b/internal/inventory/awsfetcher/fetcher_elb.go
@@ -73,7 +73,7 @@ func (f *elbFetcher) fetch(ctx context.Context, resourceName string, function el
awsResources, err := function(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ f.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_iam_policy.go b/internal/inventory/awsfetcher/fetcher_iam_policy.go
index b04c1db6..36ad2f64 100644
--- a/internal/inventory/awsfetcher/fetcher_iam_policy.go
+++ b/internal/inventory/awsfetcher/fetcher_iam_policy.go
@@ -54,7 +54,7 @@ func (i *iamPolicyFetcher) Fetch(ctx context.Context, assetChannel chan<- invent
policies, err := i.provider.GetPolicies(ctx)
if err != nil {
- i.logger.Errorf("Could not list policies: %v", err)
+ i.logger.Errorf(ctx, "Could not list policies: %v", err)
if len(policies) == 0 {
return
}
@@ -67,7 +67,7 @@ func (i *iamPolicyFetcher) Fetch(ctx context.Context, assetChannel chan<- invent
policy, ok := resource.(iam.Policy)
if !ok {
- i.logger.Errorf("Could not get info about policy: %s", resource.GetResourceArn())
+ i.logger.Errorf(ctx, "Could not get info about policy: %s", resource.GetResourceArn())
continue
}
diff --git a/internal/inventory/awsfetcher/fetcher_iam_role.go b/internal/inventory/awsfetcher/fetcher_iam_role.go
index e2d60459..e3ee419f 100644
--- a/internal/inventory/awsfetcher/fetcher_iam_role.go
+++ b/internal/inventory/awsfetcher/fetcher_iam_role.go
@@ -54,7 +54,7 @@ func (i *iamRoleFetcher) Fetch(ctx context.Context, assetChannel chan<- inventor
roles, err := i.provider.ListRoles(ctx)
if err != nil {
- i.logger.Errorf("Could not list roles: %v", err)
+ i.logger.Errorf(ctx, "Could not list roles: %v", err)
if len(roles) == 0 {
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_iam_user.go b/internal/inventory/awsfetcher/fetcher_iam_user.go
index 6221b765..b6c4ac36 100644
--- a/internal/inventory/awsfetcher/fetcher_iam_user.go
+++ b/internal/inventory/awsfetcher/fetcher_iam_user.go
@@ -53,7 +53,7 @@ func (i *iamUserFetcher) Fetch(ctx context.Context, assetChannel chan<- inventor
users, err := i.provider.GetUsers(ctx)
if err != nil {
- i.logger.Errorf("Could not list users: %v", err)
+ i.logger.Errorf(ctx, "Could not list users: %v", err)
if len(users) == 0 {
return
}
@@ -66,7 +66,7 @@ func (i *iamUserFetcher) Fetch(ctx context.Context, assetChannel chan<- inventor
user, ok := resource.(iam.User)
if !ok {
- i.logger.Errorf("Could not get info about user: %s", resource.GetResourceArn())
+ i.logger.Errorf(ctx, "Could not get info about user: %s", resource.GetResourceArn())
continue
}
diff --git a/internal/inventory/awsfetcher/fetcher_lambda.go b/internal/inventory/awsfetcher/fetcher_lambda.go
index 54698553..10847d03 100644
--- a/internal/inventory/awsfetcher/fetcher_lambda.go
+++ b/internal/inventory/awsfetcher/fetcher_lambda.go
@@ -73,7 +73,7 @@ func (s *lambdaFetcher) fetch(ctx context.Context, resourceName string, function
awsResources, err := function(ctx)
if err != nil {
- s.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ s.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_networking.go b/internal/inventory/awsfetcher/fetcher_networking.go
index 97220b90..ece19ca3 100644
--- a/internal/inventory/awsfetcher/fetcher_networking.go
+++ b/internal/inventory/awsfetcher/fetcher_networking.go
@@ -88,7 +88,7 @@ func (s *networkingFetcher) fetch(ctx context.Context, resourceName string, func
awsResources, err := function(ctx)
if err != nil {
- s.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ s.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_rds.go b/internal/inventory/awsfetcher/fetcher_rds.go
index 85e4f1b7..990cfc1b 100644
--- a/internal/inventory/awsfetcher/fetcher_rds.go
+++ b/internal/inventory/awsfetcher/fetcher_rds.go
@@ -55,7 +55,7 @@ func (s *rdsFetcher) Fetch(ctx context.Context, assetChannel chan<- inventory.As
awsResources, err := s.provider.DescribeDBInstances(ctx)
if err != nil {
- s.logger.Errorf("Could not list RDS Instances: %v", err)
+ s.logger.Errorf(ctx, "Could not list RDS Instances: %v", err)
if len(awsResources) == 0 {
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_s3_bucket.go b/internal/inventory/awsfetcher/fetcher_s3_bucket.go
index 1a0e4fa4..4c349802 100644
--- a/internal/inventory/awsfetcher/fetcher_s3_bucket.go
+++ b/internal/inventory/awsfetcher/fetcher_s3_bucket.go
@@ -55,7 +55,7 @@ func (s *s3BucketFetcher) Fetch(ctx context.Context, assetChannel chan<- invento
awsBuckets, err := s.provider.DescribeBuckets(ctx)
if err != nil {
- s.logger.Errorf("Could not list s3 buckets: %v", err)
+ s.logger.Errorf(ctx, "Could not list s3 buckets: %v", err)
if len(awsBuckets) == 0 {
return
}
diff --git a/internal/inventory/awsfetcher/fetcher_sns.go b/internal/inventory/awsfetcher/fetcher_sns.go
index a6d8819f..0e22d7bd 100644
--- a/internal/inventory/awsfetcher/fetcher_sns.go
+++ b/internal/inventory/awsfetcher/fetcher_sns.go
@@ -52,7 +52,7 @@ func (s *snsFetcher) Fetch(ctx context.Context, assetChannel chan<- inventory.As
awsResources, err := s.provider.ListTopicsWithSubscriptions(ctx)
if err != nil {
- s.logger.Errorf("Could not fetch SNS Topics: %v", err)
+ s.logger.Errorf(ctx, "Could not fetch SNS Topics: %v", err)
return
}
diff --git a/internal/inventory/azurefetcher/fetcher_account.go b/internal/inventory/azurefetcher/fetcher_account.go
index f3481caa..263b75ce 100644
--- a/internal/inventory/azurefetcher/fetcher_account.go
+++ b/internal/inventory/azurefetcher/fetcher_account.go
@@ -67,7 +67,7 @@ func (f *accountFetcher) fetch(ctx context.Context, resourceName string, functio
azureAssets, err := function(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ f.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/inventory/azurefetcher/fetcher_activedirectory.go b/internal/inventory/azurefetcher/fetcher_activedirectory.go
index bc78b6a3..9c8d5219 100644
--- a/internal/inventory/azurefetcher/fetcher_activedirectory.go
+++ b/internal/inventory/azurefetcher/fetcher_activedirectory.go
@@ -63,7 +63,7 @@ func (f *activedirectoryFetcher) fetchServicePrincipals(ctx context.Context, ass
items, err := f.provider.ListServicePrincipals(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch Service Principals: %v", err)
+ f.logger.Errorf(ctx, "Could not fetch Service Principals: %v", err)
}
for _, item := range items {
@@ -94,7 +94,7 @@ func (f *activedirectoryFetcher) fetchDirectoryRoles(ctx context.Context, assetC
items, err := f.provider.ListDirectoryRoles(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch Directory Roles: %v", err)
+ f.logger.Errorf(ctx, "Could not fetch Directory Roles: %v", err)
}
for _, item := range items {
@@ -124,7 +124,7 @@ func (f *activedirectoryFetcher) fetchGroups(ctx context.Context, assetChan chan
items, err := f.provider.ListGroups(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch Groups: %v", err)
+ f.logger.Errorf(ctx, "Could not fetch Groups: %v", err)
}
for _, item := range items {
@@ -160,7 +160,7 @@ func (f *activedirectoryFetcher) fetchUsers(ctx context.Context, assetChan chan<
items, err := f.provider.ListUsers(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch Users: %v", err)
+ f.logger.Errorf(ctx, "Could not fetch Users: %v", err)
}
for _, item := range items {
diff --git a/internal/inventory/azurefetcher/fetcher_resource_graph.go b/internal/inventory/azurefetcher/fetcher_resource_graph.go
index f1a2af13..af0c732b 100644
--- a/internal/inventory/azurefetcher/fetcher_resource_graph.go
+++ b/internal/inventory/azurefetcher/fetcher_resource_graph.go
@@ -78,7 +78,7 @@ func (f *resourceGraphFetcher) fetch(ctx context.Context, resourceName, resource
azureAssets, err := f.provider.ListAllAssetTypesByName(ctx, resourceGroup, []string{resourceType})
if err != nil {
- f.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ f.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/inventory/azurefetcher/fetcher_storage.go b/internal/inventory/azurefetcher/fetcher_storage.go
index 263f1f23..fca2ae5a 100644
--- a/internal/inventory/azurefetcher/fetcher_storage.go
+++ b/internal/inventory/azurefetcher/fetcher_storage.go
@@ -74,7 +74,7 @@ func (f *storageFetcher) Fetch(ctx context.Context, assetChan chan<- inventory.A
storageAccounts, err := f.listStorageAccounts(ctx)
if err != nil {
- f.logger.Errorf("Could not fetch anything: %v", err)
+ f.logger.Errorf(ctx, "Could not fetch anything: %v", err)
return
}
@@ -108,7 +108,7 @@ func (f *storageFetcher) fetch(ctx context.Context, storageAccounts []azurelib.A
azureAssets, err := function(ctx, storageAccounts)
if err != nil {
- f.logger.Errorf("Could not fetch %s: %v", resourceName, err)
+ f.logger.Errorf(ctx, "Could not fetch %s: %v", resourceName, err)
return
}
diff --git a/internal/launcher/launcher.go b/internal/launcher/launcher.go
index 8670dbf3..8c38768b 100644
--- a/internal/launcher/launcher.go
+++ b/internal/launcher/launcher.go
@@ -21,6 +21,7 @@
package launcher
import (
+ "context"
"errors"
"fmt"
"sync"
@@ -99,7 +100,7 @@ func (l *launcher) Run(b *beat.Beat) error {
l.log.Infof("Waiting for initial reconfiguration from Fleet server...")
update, err := l.reconfigureWait(reconfigureWaitTimeout)
if err != nil {
- l.log.Errorf("Failed while waiting for the initial reconfiguration from Fleet server: %v", err)
+ l.log.Errorf(context.TODO(), "Failed while waiting for the initial reconfiguration from Fleet server: %v", err)
return err
}
@@ -122,7 +123,7 @@ func (l *launcher) run() error {
l.log.Info("Launcher stopped after timeout")
case err == nil: // unexpected
default:
- l.log.Errorf("Launcher stopped by error: %v", err)
+ l.log.Errorf(context.TODO(), "Launcher stopped by error: %v", err)
}
l.reloader.Stop()
@@ -298,7 +299,7 @@ func (l *launcher) reconfigureWait(timeout time.Duration) (*config.C, error) {
if l.validator != nil {
err := l.validator.Validate(update)
if err != nil {
- l.log.Errorf("Config update validation failed: %v", err)
+ l.log.Errorf(context.TODO(), "Config update validation failed: %v", err)
healthErr := &BeaterUnhealthyError{}
if errors.As(err, healthErr) {
l.beat.Manager.UpdateStatus(status.Degraded, healthErr.Error())
diff --git a/internal/resources/fetching/cycle/cache.go b/internal/resources/fetching/cycle/cache.go
index 3e2b13cd..040185e4 100644
--- a/internal/resources/fetching/cycle/cache.go
+++ b/internal/resources/fetching/cycle/cache.go
@@ -57,7 +57,7 @@ func (c *Cache[T]) GetValue(ctx context.Context, cycle Metadata, fetch func(cont
if c.lastCycle.Sequence < 0 {
return result, err
}
- c.log.Errorf("Failed to renew, using cached value: %v", err)
+ c.log.Errorf(ctx, "Failed to renew, using cached value: %v", err)
} else {
c.cachedValue = result
c.lastCycle = cycle
diff --git a/internal/resources/fetching/fetchers/aws/ecr_fetcher.go b/internal/resources/fetching/fetchers/aws/ecr_fetcher.go
index d9af08df..2dd77591 100644
--- a/internal/resources/fetching/fetchers/aws/ecr_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/ecr_fetcher.go
@@ -74,7 +74,7 @@ func (f *EcrFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) er
podsList, err := f.kubeClient.CoreV1().Pods("").List(ctx, metav1.ListOptions{})
if err != nil {
- f.log.Errorf("failed to get pods - %v", err)
+ f.log.Errorf(ctx, "failed to get pods - %v", err)
return err
}
@@ -96,7 +96,7 @@ func (f *EcrFetcher) describePodImagesRepositories(ctx context.Context, podsList
// Add configuration
describedRepo, err := describer.Provider.DescribeRepositories(ctx, repositories, region)
if err != nil {
- f.log.Errorf("could not retrieve pod's aws repositories for region %s: %v", region, err)
+ f.log.Errorf(ctx, "could not retrieve pod's aws repositories for region %s: %v", region, err)
} else {
awsRepositories = append(awsRepositories, describedRepo...)
}
diff --git a/internal/resources/fetching/fetchers/aws/iam_fetcher.go b/internal/resources/fetching/fetchers/aws/iam_fetcher.go
index 2490afc8..3ee96bf0 100644
--- a/internal/resources/fetching/fetchers/aws/iam_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/iam_fetcher.go
@@ -62,35 +62,35 @@ func (f IAMFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) err
pwdPolicy, err := f.iamProvider.GetPasswordPolicy(ctx)
if err != nil {
- f.log.Errorf("Unable to fetch PasswordPolicy, error: %v", err)
+ f.log.Errorf(ctx, "Unable to fetch PasswordPolicy, error: %v", err)
} else {
iamResources = append(iamResources, pwdPolicy)
}
users, err := f.iamProvider.GetUsers(ctx)
if err != nil {
- f.log.Errorf("Unable to fetch IAM users, error: %v", err)
+ f.log.Errorf(ctx, "Unable to fetch IAM users, error: %v", err)
} else {
iamResources = append(iamResources, users...)
}
policies, err := f.iamProvider.GetPolicies(ctx)
if err != nil {
- f.log.Errorf("Unable to fetch IAM policies, error: %v", err)
+ f.log.Errorf(ctx, "Unable to fetch IAM policies, error: %v", err)
} else {
iamResources = append(iamResources, policies...)
}
serverCertificates, err := f.iamProvider.ListServerCertificates(ctx)
if err != nil {
- f.log.Errorf("Unable to fetch IAM server certificates, error: %v", err)
+ f.log.Errorf(ctx, "Unable to fetch IAM server certificates, error: %v", err)
} else {
iamResources = append(iamResources, serverCertificates)
}
accessAnalyzers, err := f.iamProvider.GetAccessAnalyzers(ctx)
if err != nil {
- f.log.Errorf("Unable to fetch access access analyzers, error: %v", err)
+ f.log.Errorf(ctx, "Unable to fetch access access analyzers, error: %v", err)
} else {
iamResources = append(iamResources, accessAnalyzers)
}
diff --git a/internal/resources/fetching/fetchers/aws/kms_fetcher.go b/internal/resources/fetching/fetchers/aws/kms_fetcher.go
index 7f6917b5..e829f0de 100644
--- a/internal/resources/fetching/fetchers/aws/kms_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/kms_fetcher.go
@@ -52,7 +52,7 @@ func (f *KmsFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) er
keys, err := f.kms.DescribeSymmetricKeys(ctx)
if err != nil {
- f.log.Errorf("failed to describe keys from KMS: %v", err)
+ f.log.Errorf(ctx, "failed to describe keys from KMS: %v", err)
return nil
}
diff --git a/internal/resources/fetching/fetchers/aws/logging_fetcher.go b/internal/resources/fetching/fetchers/aws/logging_fetcher.go
index b010a8a7..d67ed5b7 100644
--- a/internal/resources/fetching/fetchers/aws/logging_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/logging_fetcher.go
@@ -67,7 +67,7 @@ func (f LoggingFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata)
f.log.Debug("Starting LoggingFetcher.Fetch")
trails, err := f.loggingProvider.DescribeTrails(ctx)
if err != nil {
- f.log.Errorf("failed to describe trails: %v", err)
+ f.log.Errorf(ctx, "failed to describe trails: %v", err)
}
for _, resource := range trails {
@@ -81,7 +81,7 @@ func (f LoggingFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata)
configs, err := f.configserviceProvider.DescribeConfigRecorders(ctx)
if err != nil {
- f.log.Errorf("failed to describe config recorders: %v", err)
+ f.log.Errorf(ctx, "failed to describe config recorders: %v", err)
return nil
}
diff --git a/internal/resources/fetching/fetchers/aws/monitoring_fetcher.go b/internal/resources/fetching/fetchers/aws/monitoring_fetcher.go
index aa667727..10857f29 100644
--- a/internal/resources/fetching/fetchers/aws/monitoring_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/monitoring_fetcher.go
@@ -61,7 +61,7 @@ func (m MonitoringFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metada
m.log.Debug("Starting MonitoringFetcher.Fetch")
out, err := m.provider.AggregateResources(ctx)
if err != nil {
- m.log.Errorf("failed to aggregate monitoring resources: %v", err)
+ m.log.Errorf(ctx, "failed to aggregate monitoring resources: %v", err)
}
if out != nil {
m.resourceCh <- fetching.ResourceInfo{
@@ -71,7 +71,7 @@ func (m MonitoringFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metada
}
hubs, err := m.securityhub.Describe(ctx)
if err != nil {
- m.log.Errorf("failed to describe security hub: %v", err)
+ m.log.Errorf(ctx, "failed to describe security hub: %v", err)
return nil
}
diff --git a/internal/resources/fetching/fetchers/aws/network_fetcher.go b/internal/resources/fetching/fetchers/aws/network_fetcher.go
index 4dd42adc..ed0ed2c1 100644
--- a/internal/resources/fetching/fetchers/aws/network_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/network_fetcher.go
@@ -97,23 +97,23 @@ func (f NetworkFetcher) aggregateResources(ctx context.Context, client ec2.Elast
var resources []awslib.AwsResource
nacl, err := client.DescribeNetworkAcl(ctx)
if err != nil {
- f.log.Errorf("failed to describe network acl: %v", err)
+ f.log.Errorf(ctx, "failed to describe network acl: %v", err)
}
resources = append(resources, nacl...)
securityGroups, err := client.DescribeSecurityGroups(ctx)
if err != nil {
- f.log.Errorf("failed to describe security groups: %v", err)
+ f.log.Errorf(ctx, "failed to describe security groups: %v", err)
}
resources = append(resources, securityGroups...)
vpcs, err := client.DescribeVpcs(ctx)
if err != nil {
- f.log.Errorf("failed to describe vpcs: %v", err)
+ f.log.Errorf(ctx, "failed to describe vpcs: %v", err)
}
resources = append(resources, vpcs...)
ebsEncryption, err := client.GetEbsEncryptionByDefault(ctx)
if err != nil {
- f.log.Errorf("failed to get ebs encryption by default: %v", err)
+ f.log.Errorf(ctx, "failed to get ebs encryption by default: %v", err)
}
if ebsEncryption != nil {
diff --git a/internal/resources/fetching/fetchers/aws/rds_fetcher.go b/internal/resources/fetching/fetchers/aws/rds_fetcher.go
index d2c36837..99f0ab01 100644
--- a/internal/resources/fetching/fetchers/aws/rds_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/rds_fetcher.go
@@ -53,7 +53,7 @@ func (f *RdsFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) er
f.log.Info("Starting RdsFetcher.Fetch")
dbInstances, err := f.provider.DescribeDBInstances(ctx)
if err != nil {
- f.log.Errorf("failed to load some DB instances from rds: %v", err)
+ f.log.Errorf(ctx, "failed to load some DB instances from rds: %v", err)
}
for _, dbInstance := range dbInstances {
diff --git a/internal/resources/fetching/fetchers/aws/s3_fetcher.go b/internal/resources/fetching/fetchers/aws/s3_fetcher.go
index c28a2599..8225956a 100644
--- a/internal/resources/fetching/fetchers/aws/s3_fetcher.go
+++ b/internal/resources/fetching/fetchers/aws/s3_fetcher.go
@@ -49,7 +49,7 @@ func (f *S3Fetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) err
f.log.Info("Starting S3Fetcher.Fetch")
buckets, err := f.s3.DescribeBuckets(ctx)
if err != nil {
- f.log.Errorf("failed to load buckets from S3: %v", err)
+ f.log.Errorf(ctx, "failed to load buckets from S3: %v", err)
return nil
}
diff --git a/internal/resources/fetching/fetchers/azure/assets_fetcher.go b/internal/resources/fetching/fetchers/azure/assets_fetcher.go
index 768e7cb1..7a30164e 100644
--- a/internal/resources/fetching/fetchers/azure/assets_fetcher.go
+++ b/internal/resources/fetching/fetchers/azure/assets_fetcher.go
@@ -92,7 +92,7 @@ func (f *AzureAssetsFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Meta
// Fetching all types even if non-existent in asset group for simplicity
r, err := f.provider.ListAllAssetTypesByName(ctx, assetGroup, slices.Collect(maps.Keys(AzureAssetTypeToTypePair)))
if err != nil {
- f.log.Errorf("AzureAssetsFetcher.Fetch failed to fetch asset group %s: %s", assetGroup, err.Error())
+ f.log.Errorf(ctx, "AzureAssetsFetcher.Fetch failed to fetch asset group %s: %s", assetGroup, err.Error())
errAgg = errors.Join(errAgg, err)
continue
}
@@ -101,7 +101,7 @@ func (f *AzureAssetsFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Meta
subscriptions, err := f.provider.GetSubscriptions(ctx, cycleMetadata)
if err != nil {
- f.log.Errorf("Error fetching subscription information: %v", err)
+ f.log.Errorf(ctx, "Error fetching subscription information: %v", err)
}
for _, e := range f.enrichers {
diff --git a/internal/resources/fetching/fetchers/azure/batch_fetcher.go b/internal/resources/fetching/fetchers/azure/batch_fetcher.go
index 7496552b..182fdf09 100644
--- a/internal/resources/fetching/fetchers/azure/batch_fetcher.go
+++ b/internal/resources/fetching/fetchers/azure/batch_fetcher.go
@@ -70,7 +70,7 @@ func (f *AzureBatchAssetFetcher) Fetch(ctx context.Context, cycleMetadata cycle.
for _, assetGroup := range AzureBatchAssetGroups {
r, err := f.provider.ListAllAssetTypesByName(ctx, assetGroup, slices.Collect(maps.Keys(AzureBatchAssets)))
if err != nil {
- f.log.Errorf("AzureBatchAssetFetcher.Fetch failed to fetch asset group %s: %s", assetGroup, err.Error())
+ f.log.Errorf(ctx, "AzureBatchAssetFetcher.Fetch failed to fetch asset group %s: %s", assetGroup, err.Error())
errAgg = errors.Join(errAgg, err)
continue
}
diff --git a/internal/resources/fetching/fetchers/azure/security_fetcher.go b/internal/resources/fetching/fetchers/azure/security_fetcher.go
index 8e69ca5f..4c27efff 100644
--- a/internal/resources/fetching/fetchers/azure/security_fetcher.go
+++ b/internal/resources/fetching/fetchers/azure/security_fetcher.go
@@ -66,7 +66,7 @@ func (f *AzureSecurityAssetFetcher) Fetch(ctx context.Context, cycleMetadata cyc
for assetType, fn := range fetches {
securityContacts, err := fn(ctx, sub.ShortID)
if err != nil {
- f.log.Errorf("AzureSecurityAssetFetcher.Fetch failed to fetch %s for subscription %s: %s", assetType, sub.ShortID, err.Error())
+ f.log.Errorf(ctx, "AzureSecurityAssetFetcher.Fetch failed to fetch %s for subscription %s: %s", assetType, sub.ShortID, err.Error())
errs = append(errs, err)
continue
}
diff --git a/internal/resources/fetching/fetchers/k8s/file_system_fetcher.go b/internal/resources/fetching/fetchers/k8s/file_system_fetcher.go
index 0bbd9bf8..fd79d813 100644
--- a/internal/resources/fetching/fetchers/k8s/file_system_fetcher.go
+++ b/internal/resources/fetching/fetchers/k8s/file_system_fetcher.go
@@ -99,20 +99,22 @@ func NewFsFetcher(log *clog.Logger, ch chan fetching.ResourceInfo, patterns []st
}
}
-func (f *FileSystemFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadata) error {
+func (f *FileSystemFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) error {
f.log.Debug("Starting FileSystemFetcher.Fetch")
// Input files might contain glob pattern
for _, filePattern := range f.patterns {
matchedFiles, err := Glob(filePattern)
if err != nil {
- f.log.Errorf("Failed to find matched glob for %s, error: %+v", filePattern, err)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Failed to find matched glob for %s, error: %+v", filePattern, err)
}
for _, file := range matchedFiles {
- resource, err := f.fetchSystemResource(file)
+ resource, err := f.fetchSystemResource(ctx, file)
if err != nil {
- f.log.Errorf("Unable to fetch fileSystemResource for file %v", file)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Unable to fetch fileSystemResource for file %v", file)
continue
}
@@ -123,17 +125,17 @@ func (f *FileSystemFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadat
return nil
}
-func (f *FileSystemFetcher) fetchSystemResource(filePath string) (*FSResource, error) {
+func (f *FileSystemFetcher) fetchSystemResource(ctx context.Context, filePath string) (*FSResource, error) {
info, err := os.Stat(filePath)
if err != nil {
return nil, fmt.Errorf("failed to fetch %s, error: %w", filePath, err)
}
- resourceInfo, _ := f.fromFileInfo(info, filePath)
+ resourceInfo, _ := f.fromFileInfo(ctx, info, filePath)
return resourceInfo, nil
}
-func (f *FileSystemFetcher) fromFileInfo(info os.FileInfo, path string) (*FSResource, error) {
+func (f *FileSystemFetcher) fromFileInfo(ctx context.Context, info os.FileInfo, path string) (*FSResource, error) {
if info == nil {
return nil, nil
}
@@ -172,7 +174,7 @@ func (f *FileSystemFetcher) fromFileInfo(info os.FileInfo, path string) (*FSReso
return &FSResource{
EvalResource: data,
- ElasticCommon: f.createFileCommonData(stat, data, path),
+ ElasticCommon: f.createFileCommonData(ctx, stat, data, path),
}, nil
}
@@ -232,7 +234,7 @@ func getFSSubType(fileInfo os.FileInfo) string {
return FileSubType
}
-func (f *FileSystemFetcher) createFileCommonData(stat *syscall.Stat_t, data EvalFSResource, path string) FileCommonData {
+func (f *FileSystemFetcher) createFileCommonData(ctx context.Context, stat *syscall.Stat_t, data EvalFSResource, path string) FileCommonData {
cd := FileCommonData{
Name: data.Name,
Mode: data.Mode,
@@ -250,7 +252,8 @@ func (f *FileSystemFetcher) createFileCommonData(stat *syscall.Stat_t, data Eval
t, err := times.Stat(path)
if err != nil {
- f.log.Errorf("failed to get file time data (file %s), error - %s", path, err.Error())
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "failed to get file time data (file %s), error - %s", path, err.Error())
} else {
cd.Accessed = t.AccessTime()
cd.Mtime = t.ModTime()
diff --git a/internal/resources/fetching/fetchers/k8s/kube_fetcher.go b/internal/resources/fetching/fetchers/k8s/kube_fetcher.go
index ae43039e..f472aef4 100644
--- a/internal/resources/fetching/fetchers/k8s/kube_fetcher.go
+++ b/internal/resources/fetching/fetchers/k8s/kube_fetcher.go
@@ -163,7 +163,7 @@ func (f *KubeFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadata) err
return fmt.Errorf("could not initate Kubernetes watchers: %w", err)
}
- getKubeData(f.log, f.watchers, f.resourceCh, cycleMetadata)
+ getKubeData(f.log, f.watchers, f.resourceCh, cycleMetadata) //nolint:contextcheck
return nil
}
diff --git a/internal/resources/fetching/fetchers/k8s/kube_provider.go b/internal/resources/fetching/fetchers/k8s/kube_provider.go
index c2ca3ad5..b5010907 100644
--- a/internal/resources/fetching/fetchers/k8s/kube_provider.go
+++ b/internal/resources/fetching/fetchers/k8s/kube_provider.go
@@ -18,6 +18,7 @@
package fetchers
import (
+ "context"
"reflect"
"github.com/elastic/elastic-agent-autodiscover/kubernetes"
@@ -54,13 +55,13 @@ func getKubeData(log *clog.Logger, watchers []kubernetes.Watcher, resCh chan fet
resource, ok := r.(kubernetes.Resource)
if !ok {
- log.Errorf("Bad resource: %#v does not implement kubernetes.Resource", r)
+ log.Errorf(context.TODO(), "Bad resource: %#v does not implement kubernetes.Resource", r)
continue
}
err := addTypeInformationToKubeResource(resource)
if err != nil {
- log.Errorf("Bad resource: %v", err)
+ log.Errorf(context.TODO(), "Bad resource: %v", err)
continue
} // See https://github.com/kubernetes/kubernetes/issues/3030
resCh <- fetching.ResourceInfo{Resource: K8sResource{log, resource}, CycleMetadata: cycleMetadata}
@@ -108,7 +109,7 @@ func (r K8sResource) GetElasticCommonData() (map[string]any, error) {
func getK8sObjectMeta(log *clog.Logger, k8sObj reflect.Value) metav1.ObjectMeta {
metadata, ok := k8sObj.FieldByName(k8sObjMetadataField).Interface().(metav1.ObjectMeta)
if !ok {
- log.Errorf("Failed to retrieve object metadata, Resource: %#v", k8sObj)
+ log.Errorf(context.TODO(), "Failed to retrieve object metadata, Resource: %#v", k8sObj)
return metav1.ObjectMeta{}
}
@@ -118,7 +119,7 @@ func getK8sObjectMeta(log *clog.Logger, k8sObj reflect.Value) metav1.ObjectMeta
func getK8sSubType(log *clog.Logger, k8sObj reflect.Value) string {
typeMeta, ok := k8sObj.FieldByName(k8sTypeMetadataField).Interface().(metav1.TypeMeta)
if !ok {
- log.Errorf("Failed to retrieve type metadata, Resource: %#v", k8sObj)
+ log.Errorf(context.TODO(), "Failed to retrieve type metadata, Resource: %#v", k8sObj)
return ""
}
diff --git a/internal/resources/fetching/fetchers/k8s/process_fetcher.go b/internal/resources/fetching/fetchers/k8s/process_fetcher.go
index d1b931af..ff6f6d9d 100644
--- a/internal/resources/fetching/fetchers/k8s/process_fetcher.go
+++ b/internal/resources/fetching/fetchers/k8s/process_fetcher.go
@@ -129,7 +129,7 @@ func NewProcessFetcher(log *clog.Logger, ch chan fetching.ResourceInfo, processe
}
}
-func (f *ProcessesFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadata) error {
+func (f *ProcessesFetcher) Fetch(ctx context.Context, cycleMetadata cycle.Metadata) error {
f.log.Debug("Starting ProcessesFetcher.Fetch")
pids, err := proc.ListFS(f.Fs)
@@ -142,7 +142,8 @@ func (f *ProcessesFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadata
for _, p := range pids {
stat, err := proc.ReadStatFS(f.Fs, p)
if err != nil {
- f.log.Errorf("error while reading /proc/<pid>/stat for process %s: %s", p, err.Error())
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "error while reading /proc/<pid>/stat for process %s: %s", p, err.Error())
continue
}
@@ -159,39 +160,43 @@ func (f *ProcessesFetcher) Fetch(_ context.Context, cycleMetadata cycle.Metadata
continue
}
- fetchedResource := f.fetchProcessData(stat, processConfig, p, cmd)
+ fetchedResource := f.fetchProcessData(ctx, stat, processConfig, p, cmd)
f.resourceCh <- fetching.ResourceInfo{Resource: fetchedResource, CycleMetadata: cycleMetadata}
}
return nil
}
-func (f *ProcessesFetcher) fetchProcessData(procStat proc.ProcStat, processConf ProcessInputConfiguration, processId string, cmd string) fetching.Resource {
- configMap := f.getProcessConfigurationFile(processConf, cmd, procStat.Name)
+func (f *ProcessesFetcher) fetchProcessData(ctx context.Context, procStat proc.ProcStat, processConf ProcessInputConfiguration, processId string, cmd string) fetching.Resource {
+ configMap := f.getProcessConfigurationFile(ctx, processConf, cmd, procStat.Name)
evalRes := EvalProcResource{PID: processId, Cmd: cmd, Stat: procStat, ExternalData: configMap}
- procCd := f.createProcCommonData(procStat, cmd, processId)
+ procCd := f.createProcCommonData(ctx, procStat, cmd, processId)
return ProcResource{EvalResource: evalRes, ElasticCommon: procCd}
}
-func (f *ProcessesFetcher) createProcCommonData(stat proc.ProcStat, cmd string, pid string) ProcCommonData {
+func (f *ProcessesFetcher) createProcCommonData(ctx context.Context, stat proc.ProcStat, cmd string, pid string) ProcCommonData {
processID, err := strconv.ParseInt(pid, 10, 64)
if err != nil {
- f.log.Errorf("Couldn't parse PID, pid: %s", pid)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Couldn't parse PID, pid: %s", pid)
}
startTime, err := strconv.ParseUint(stat.StartTime, 10, 64)
if err != nil {
- f.log.Errorf("Couldn't parse stat.StartTime, startTime: %s", stat.StartTime)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Couldn't parse stat.StartTime, startTime: %s", stat.StartTime)
}
pgid, err := strconv.ParseInt(stat.Group, 10, 64)
if err != nil {
- f.log.Errorf("Couldn't parse stat.Group, Group: %s, Error: %v", stat.Group, err)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Couldn't parse stat.Group, Group: %s, Error: %v", stat.Group, err)
}
ppid, err := strconv.ParseInt(stat.Parent, 10, 64)
if err != nil {
- f.log.Errorf("Couldn't parse stat.Parent, Parent: %s, Error: %v", stat.Parent, err)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Couldn't parse stat.Parent, Parent: %s, Error: %v", stat.Parent, err)
}
sysUptime, err := proc.ReadUptimeFS(f.Fs)
@@ -219,7 +224,7 @@ func (f *ProcessesFetcher) createProcCommonData(stat proc.ProcStat, cmd string,
// getProcessConfigurationFile - reads the configuration file associated with a process.
// As an input this function receives a ProcessInputConfiguration that contains ConfigFileArguments, a string array that represents some process flags
// The function extracts the configuration file associated with each flag and returns it.
-func (f *ProcessesFetcher) getProcessConfigurationFile(processConfig ProcessInputConfiguration, cmd string, processName string) map[string]any {
+func (f *ProcessesFetcher) getProcessConfigurationFile(ctx context.Context, processConfig ProcessInputConfiguration, cmd string, processName string) map[string]any {
configMap := make(map[string]any)
for _, argument := range processConfig.ConfigFileArguments {
// The regex extracts the cmd line flag(argument) value
@@ -232,7 +237,8 @@ func (f *ProcessesFetcher) getProcessConfigurationFile(processConfig ProcessInpu
groupMatches := matcher.FindStringSubmatch(cmd)
if len(groupMatches) < 2 {
- f.log.Errorf("Couldn't find a configuration file associated with flag %s for process %s", argument, processName)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Couldn't find a configuration file associated with flag %s for process %s", argument, processName)
continue
}
argValue := matcher.FindStringSubmatch(cmd)[1]
@@ -240,12 +246,14 @@ func (f *ProcessesFetcher) getProcessConfigurationFile(processConfig ProcessInpu
data, err := fs.ReadFile(f.Fs, argValue)
if err != nil {
- f.log.Errorf("Failed to read file configuration for process %s, error - %+v", processName, err)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Failed to read file configuration for process %s, error - %+v", processName, err)
continue
}
configFile, err := f.readConfigurationFile(argValue, data)
if err != nil {
- f.log.Errorf("Failed to parse file configuration for process %s, error - %+v", processName, err)
+ // FIXME: This should be a context from the function signature.
+ f.log.Errorf(ctx, "Failed to parse file configuration for process %s, error - %+v", processName, err)
continue
}
configMap[argument] = configFile
diff --git a/internal/resources/fetching/manager/manager.go b/internal/resources/fetching/manager/manager.go
index ea6ba252..a52dc4f2 100644
--- a/internal/resources/fetching/manager/manager.go
+++ b/internal/resources/fetching/manager/manager.go
@@ -75,7 +75,7 @@ func (m *Manager) Stop() {
func (m *Manager) fetchAndSleep(ctx context.Context) {
counter, err := observability.MeterFromContext(ctx, scopeName).Int64Counter("cloudbeat.fetcher.manager.cycles")
if err != nil {
- m.log.Errorf("Failed to create fetcher manager cycles counter: %v", err)
+ m.log.Errorf(ctx, "Failed to create fetcher manager cycles counter: %v", err)
}
// set immediate exec for first time run
@@ -124,7 +124,7 @@ func (m *Manager) fetchIteration(ctx context.Context) {
defer wg.Done()
err := m.fetchSingle(ctx, k, cycle.Metadata{Sequence: seq})
if err != nil {
- logger.Errorf("Error running fetcher for key %s: %v", k, err)
+ logger.Errorf(ctx, "Error running fetcher for key %s: %v", k, err)
}
}(key)
}
diff --git a/internal/resources/fetching/registry/registry.go b/internal/resources/fetching/registry/registry.go
index d0257b28..27e17df1 100644
--- a/internal/resources/fetching/registry/registry.go
+++ b/internal/resources/fetching/registry/registry.go
@@ -119,7 +119,7 @@ func (r *registry) Update(ctx context.Context) {
}
fm, err := r.updater(ctx)
if err != nil {
- r.log.Errorf("Failed to update registry: %v", err)
+ r.log.Errorf(ctx, "Failed to update registry: %v", err)
return
}
r.reg = fm
diff --git a/internal/resources/providers/aws_cis/logging/provider.go b/internal/resources/providers/aws_cis/logging/provider.go
index 79d365af..52047294 100644
--- a/internal/resources/providers/aws_cis/logging/provider.go
+++ b/internal/resources/providers/aws_cis/logging/provider.go
@@ -52,17 +52,17 @@ func (p *Provider) DescribeTrails(ctx context.Context) ([]awslib.AwsResource, er
}
bucketPolicy, policyErr := p.s3Provider.GetBucketPolicy(ctx, info.Trail.S3BucketName, *info.Trail.HomeRegion)
if policyErr != nil {
- p.log.Errorf("Error getting bucket policy for bucket %s: %v", *info.Trail.S3BucketName, policyErr)
+ p.log.Errorf(ctx, "Error getting bucket policy for bucket %s: %v", *info.Trail.S3BucketName, policyErr)
}
aclGrants, aclErr := p.s3Provider.GetBucketACL(ctx, info.Trail.S3BucketName, *info.Trail.HomeRegion)
if aclErr != nil {
- p.log.Errorf("Error getting bucket ACL for bucket %s: %v", *info.Trail.S3BucketName, aclErr)
+ p.log.Errorf(ctx, "Error getting bucket ACL for bucket %s: %v", *info.Trail.S3BucketName, aclErr)
}
bucketLogging, loggingErr := p.s3Provider.GetBucketLogging(ctx, info.Trail.S3BucketName, *info.Trail.HomeRegion)
if loggingErr != nil {
- p.log.Errorf("Error getting bucket logging for bucket %s: %v", *info.Trail.S3BucketName, loggingErr)
+ p.log.Errorf(ctx, "Error getting bucket logging for bucket %s: %v", *info.Trail.S3BucketName, loggingErr)
}
enrichedTrails = append(enrichedTrails, EnrichedTrail{
diff --git a/internal/resources/providers/aws_cis/monitoring/monitoring.go b/internal/resources/providers/aws_cis/monitoring/monitoring.go
index 3a0076ab..9bab3203 100644
--- a/internal/resources/providers/aws_cis/monitoring/monitoring.go
+++ b/internal/resources/providers/aws_cis/monitoring/monitoring.go
@@ -98,11 +98,11 @@ func (p *Provider) AggregateResources(ctx context.Context) (*Resource, error) {
}
metrics, err := p.Cloudwatchlogs.DescribeMetricFilters(ctx, info.Trail.HomeRegion, logGroup)
if err != nil {
- p.Log.Errorf("failed to describe metric filters for cloudwatchlog log group arn %s: %v", *info.Trail.CloudWatchLogsLogGroupArn, err)
+ p.Log.Errorf(ctx, "failed to describe metric filters for cloudwatchlog log group arn %s: %v", *info.Trail.CloudWatchLogsLogGroupArn, err)
continue
}
- parsedMetrics := p.parserMetrics(metrics)
+ parsedMetrics := p.parserMetrics(ctx, metrics)
names := filterNamesFromMetrics(metrics)
if len(names) == 0 {
@@ -117,7 +117,7 @@ func (p *Provider) AggregateResources(ctx context.Context) (*Resource, error) {
for _, name := range names {
alarms, err := p.Cloudwatch.DescribeAlarms(ctx, info.Trail.HomeRegion, []string{name})
if err != nil {
- p.Log.Errorf("failed to describe alarms for cloudwatch filter %v: %v", names, err)
+ p.Log.Errorf(ctx, "failed to describe alarms for cloudwatch filter %v: %v", names, err)
continue
}
topics := p.getSubscriptionForAlarms(ctx, info.Trail.HomeRegion, alarms)
@@ -133,7 +133,7 @@ func (p *Provider) AggregateResources(ctx context.Context) (*Resource, error) {
return &Resource{Items: items}, nil
}
-func (p *Provider) parserMetrics(metrics []cloudwatchlogs_types.MetricFilter) []MetricFilter {
+func (p *Provider) parserMetrics(ctx context.Context, metrics []cloudwatchlogs_types.MetricFilter) []MetricFilter {
parsedMetrics := make([]MetricFilter, 0, len(metrics))
for _, m := range metrics {
if m.FilterPattern == nil {
@@ -145,7 +145,8 @@ func (p *Provider) parserMetrics(metrics []cloudwatchlogs_types.MetricFilter) []
exp, err := parseFilterPattern(*m.FilterPattern)
if err != nil {
- p.Log.Errorf("failed to parse metric filter pattern: %v (pattern: %s)", err, *m.FilterPattern)
+ // FIXME: This should be a context from the function signature.
+ p.Log.Errorf(ctx, "failed to parse metric filter pattern: %v (pattern: %s)", err, *m.FilterPattern)
parsedMetrics = append(parsedMetrics, MetricFilter{
MetricFilter: m,
})
@@ -166,7 +167,7 @@ func (p *Provider) getSubscriptionForAlarms(ctx context.Context, region *string,
for _, action := range alarm.AlarmActions {
subscriptions, err := p.Sns.ListSubscriptionsByTopic(ctx, pointers.Deref(region), action)
if err != nil {
- p.Log.Errorf("failed to list subscriptions for topic %s: %v", action, err)
+ p.Log.Errorf(ctx, "failed to list subscriptions for topic %s: %v", action, err)
continue
}
for _, topic := range subscriptions {
diff --git a/internal/resources/providers/awslib/account_provider.go b/internal/resources/providers/awslib/account_provider.go
index 8ccb8cd6..815bfa29 100644
--- a/internal/resources/providers/awslib/account_provider.go
+++ b/internal/resources/providers/awslib/account_provider.go
@@ -64,7 +64,7 @@ func listAccounts(ctx context.Context, log *clog.Logger, client organizationsAPI
organization, err := getOUInfoForAccount(ctx, client, organizationIdToName, account.Id)
if err != nil {
- log.Errorf("failed to get organizational unit info for account %s: %v", *account.Id, err)
+ log.Errorf(ctx, "failed to get organizational unit info for account %s: %v", *account.Id, err)
}
accounts = append(accounts, cloud.Identity{
Provider: "aws",
diff --git a/internal/resources/providers/awslib/all_region_selector.go b/internal/resources/providers/awslib/all_region_selector.go
index 14bad6e1..5ef32be4 100644
--- a/internal/resources/providers/awslib/all_region_selector.go
+++ b/internal/resources/providers/awslib/all_region_selector.go
@@ -47,7 +47,7 @@ func (s *allRegionSelector) Regions(ctx context.Context, cfg aws.Config) ([]stri
output, err := s.client.DescribeRegions(ctx, nil)
if err != nil {
- log.Errorf("Failed getting available regions: %v", err)
+ log.Errorf(ctx, "Failed getting available regions: %v", err)
return nil, err
}
diff --git a/internal/resources/providers/awslib/cached_region_selector.go b/internal/resources/providers/awslib/cached_region_selector.go
index 07a8feae..a7a870ad 100644
--- a/internal/resources/providers/awslib/cached_region_selector.go
+++ b/internal/resources/providers/awslib/cached_region_selector.go
@@ -94,12 +94,12 @@ func (s *cachedRegionSelector) Regions(ctx context.Context, cfg aws.Config) ([]s
var output []string
output, err := s.client.Regions(ctx, cfg)
if err != nil {
- log.Errorf("Failed getting regions: %v", err)
+ log.Errorf(ctx, "Failed getting regions: %v", err)
return nil, err
}
if !s.setCache(output) {
- log.Errorf("Failed setting regions cache")
+ log.Errorf(ctx, "Failed setting regions cache")
}
return output, nil
}
diff --git a/internal/resources/providers/awslib/cloudtrail/provider.go b/internal/resources/providers/awslib/cloudtrail/provider.go
index 02b2102a..6dc8d78d 100644
--- a/internal/resources/providers/awslib/cloudtrail/provider.go
+++ b/internal/resources/providers/awslib/cloudtrail/provider.go
@@ -57,12 +57,12 @@ func (p Provider) DescribeTrails(ctx context.Context) ([]TrailInfo, error) {
}
status, err := p.getTrailStatus(ctx, trail)
if err != nil {
- p.log.Errorf("failed to get trail status %s %v", *trail.TrailARN, err.Error())
+ p.log.Errorf(ctx, "failed to get trail status %s %v", *trail.TrailARN, err.Error())
}
selectors, err := p.getEventSelectors(ctx, trail)
if err != nil {
- p.log.Errorf("failed to get trail event selector %s %v", *trail.TrailARN, err.Error())
+ p.log.Errorf(ctx, "failed to get trail event selector %s %v", *trail.TrailARN, err.Error())
}
result = append(result, TrailInfo{
diff --git a/internal/resources/providers/awslib/configservice/provider.go b/internal/resources/providers/awslib/configservice/provider.go
index 04a42f0e..d773ac3a 100644
--- a/internal/resources/providers/awslib/configservice/provider.go
+++ b/internal/resources/providers/awslib/configservice/provider.go
@@ -29,7 +29,7 @@ func (p *Provider) DescribeConfigRecorders(ctx context.Context) ([]awslib.AwsRes
configs, err := awslib.MultiRegionFetch(ctx, p.clients, func(ctx context.Context, region string, c Client) (awslib.AwsResource, error) {
recorderList, err := c.DescribeConfigurationRecorders(ctx, nil)
if err != nil {
- p.log.Errorf("Error fetching AWS Config recorders: %v", err)
+ p.log.Errorf(ctx, "Error fetching AWS Config recorders: %v", err)
return nil, err
}
diff --git a/internal/resources/providers/awslib/current_region_selector.go b/internal/resources/providers/awslib/current_region_selector.go
index d58ee76e..c3c3d29f 100644
--- a/internal/resources/providers/awslib/current_region_selector.go
+++ b/internal/resources/providers/awslib/current_region_selector.go
@@ -39,7 +39,7 @@ func (s *currentRegionSelector) Regions(ctx context.Context, cfg aws.Config) ([]
metadata, err := s.client.GetMetadata(ctx, cfg)
if err != nil {
- log.Errorf("Failed getting current region: %v", err)
+ log.Errorf(ctx, "Failed getting current region: %v", err)
return nil, err
}
diff --git a/internal/resources/providers/awslib/ec2/provider.go b/internal/resources/providers/awslib/ec2/provider.go
index 31d0bb7d..e7a07c0c 100644
--- a/internal/resources/providers/awslib/ec2/provider.go
+++ b/internal/resources/providers/awslib/ec2/provider.go
@@ -362,7 +362,7 @@ func (p *Provider) IterOwnedSnapshots(ctx context.Context, before time.Time) ite
return nil, nil
})
if err != nil {
- p.log.Errorf("Error listing owned snapshots: %v", err)
+ p.log.Errorf(ctx, "Error listing owned snapshots: %v", err)
}
}
}
@@ -492,7 +492,7 @@ func (p *Provider) DescribeVolumes(ctx context.Context, instances []*Ec2Instance
var result []*Volume
for _, vol := range allVolumes {
if len(vol.Attachments) != 1 {
- p.log.Errorf("Volume %s has %d attachments", *vol.VolumeId, len(vol.Attachments))
+ p.log.Errorf(ctx, "Volume %s has %d attachments", *vol.VolumeId, len(vol.Attachments))
continue
}
@@ -564,7 +564,7 @@ func (p *Provider) DescribeVpcs(ctx context.Context) ([]awslib.AwsResource, erro
},
}})
if err != nil {
- p.log.Errorf("Error fetching flow logs for VPC %s: %v", *vpc.VpcId, err.Error())
+ p.log.Errorf(ctx, "Error fetching flow logs for VPC %s: %v", *vpc.VpcId, err.Error())
continue
}
diff --git a/internal/resources/providers/awslib/elb_v2/provider_v2.go b/internal/resources/providers/awslib/elb_v2/provider_v2.go
index d7e8699d..e719b85c 100644
--- a/internal/resources/providers/awslib/elb_v2/provider_v2.go
+++ b/internal/resources/providers/awslib/elb_v2/provider_v2.go
@@ -54,7 +54,7 @@ func (p *Provider) DescribeLoadBalancers(ctx context.Context) ([]awslib.AwsResou
}
listeners, err := p.describeListeners(ctx, region, loadBalancer.GetResourceArn())
if err != nil {
- p.log.Errorf("Error fetching listeners for %s: %v", loadBalancer.GetResourceArn(), err)
+ p.log.Errorf(ctx, "Error fetching listeners for %s: %v", loadBalancer.GetResourceArn(), err)
} else {
loadBalancer.Listeners = listeners
}
diff --git a/internal/resources/providers/awslib/iam/policy.go b/internal/resources/providers/awslib/iam/policy.go
index f406ea22..9cec7eb1 100644
--- a/internal/resources/providers/awslib/iam/policy.go
+++ b/internal/resources/providers/awslib/iam/policy.go
@@ -223,7 +223,7 @@ func (p Provider) listInlinePolicies(ctx context.Context, identity *string) ([]P
UserName: identity,
})
if err != nil {
- p.log.Errorf("fail to get inline policy for user: %s, policy name: %s", *identity, policyNames[i])
+ p.log.Errorf(ctx, "fail to get inline policy for user: %s, policy name: %s", *identity, policyNames[i])
policies = append(policies, PolicyDocument{PolicyName: policyNames[i]})
continue
}
diff --git a/internal/resources/providers/awslib/iam/role_policy.go b/internal/resources/providers/awslib/iam/role_policy.go
index 65d683c9..a5c0f4ac 100644
--- a/internal/resources/providers/awslib/iam/role_policy.go
+++ b/internal/resources/providers/awslib/iam/role_policy.go
@@ -41,7 +41,7 @@ func (p Provider) GetIAMRolePermissions(ctx context.Context, roleName string) ([
policy, err := p.client.GetRolePolicy(ctx, input)
if err != nil {
- p.log.Errorf("Failed to get policy %s: %v", *policyId.PolicyName, err)
+ p.log.Errorf(ctx, "Failed to get policy %s: %v", *policyId.PolicyName, err)
continue
}
diff --git a/internal/resources/providers/awslib/iam/root_account.go b/internal/resources/providers/awslib/iam/root_account.go
index a2400bf2..67483b3c 100644
--- a/internal/resources/providers/awslib/iam/root_account.go
+++ b/internal/resources/providers/awslib/iam/root_account.go
@@ -27,7 +27,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/iam/types"
)
-func (p Provider) getRootAccountUser(rootAccount *CredentialReport) *types.User {
+func (p Provider) getRootAccountUser(ctx context.Context, rootAccount *CredentialReport) *types.User {
if rootAccount == nil {
p.log.Error("no root account entry was provided")
return nil
@@ -35,7 +35,7 @@ func (p Provider) getRootAccountUser(rootAccount *CredentialReport) *types.User
rootDate, err := time.Parse(time.RFC3339, rootAccount.UserCreation)
if err != nil {
- p.log.Errorf("fail to parse root account user creation, error: %v", err)
+ p.log.Errorf(ctx, "fail to parse root account user creation, error: %v", err)
return nil
}
@@ -45,7 +45,7 @@ func (p Provider) getRootAccountUser(rootAccount *CredentialReport) *types.User
if rootAccount.PasswordLastUsed != "no_information" && rootAccount.PasswordLastUsed != "N/A" {
pwdLastUsed, err = time.Parse(time.RFC3339, rootAccount.PasswordLastUsed)
if err != nil {
- p.log.Errorf("fail to parse root account password last used, error: %v", err)
+ p.log.Errorf(ctx, "fail to parse root account password last used, error: %v", err)
return nil
}
}
diff --git a/internal/resources/providers/awslib/iam/user.go b/internal/resources/providers/awslib/iam/user.go
index 3305bedf..34617a86 100644
--- a/internal/resources/providers/awslib/iam/user.go
+++ b/internal/resources/providers/awslib/iam/user.go
@@ -54,7 +54,7 @@ func (p Provider) GetUsers(ctx context.Context) ([]awslib.AwsResource, error) {
return nil, err
}
- rootUser := p.getRootAccountUser(credentialReport[rootAccount])
+ rootUser := p.getRootAccountUser(ctx, credentialReport[rootAccount])
if rootUser != nil {
apiUsers = append(apiUsers, *rootUser)
}
@@ -80,23 +80,23 @@ func (p Provider) GetUsers(ctx context.Context) ([]awslib.AwsResource, error) {
mfaDevices, err := p.getMFADevices(ctx, apiUser, userAccount)
if err != nil {
- p.log.Errorf("fail to list mfa device for user: %s, error: %v", username, err)
+ p.log.Errorf(ctx, "fail to list mfa device for user: %s, error: %v", username, err)
}
pwdEnabled, err := isPasswordEnabled(userAccount)
if err != nil {
- p.log.Errorf("fail to parse PasswordEnabled for user: %s, error: %v", username, err)
+ p.log.Errorf(ctx, "fail to parse PasswordEnabled for user: %s, error: %v", username, err)
pwdEnabled = false
}
inlinePolicies, err := p.listInlinePolicies(ctx, apiUser.UserName)
if err != nil && !isRootUser(username) {
- p.log.Errorf("fail to list inline policies for user: %s, error: %v", username, err)
+ p.log.Errorf(ctx, "fail to list inline policies for user: %s, error: %v", username, err)
}
attachedPolicies, err := p.listAttachedPolicies(ctx, apiUser.UserName)
if err != nil && !isRootUser(username) {
- p.log.Errorf("fail to list attached policies for user: %s, error: %v", username, err)
+ p.log.Errorf(ctx, "fail to list attached policies for user: %s, error: %v", username, err)
}
users = append(users, User{
diff --git a/internal/resources/providers/awslib/multi_region.go b/internal/resources/providers/awslib/multi_region.go
index 4b2adfb3..07ef6c7b 100644
--- a/internal/resources/providers/awslib/multi_region.go
+++ b/internal/resources/providers/awslib/multi_region.go
@@ -53,7 +53,7 @@ func (w *MultiRegionClientFactory[T]) NewMultiRegionClients(ctx context.Context,
clientsMap := make(map[string]T, 0)
regionList, err := selector.Regions(ctx, cfg)
if err != nil {
- log.Errorf("Region '%s' selected after failure to retrieve aws regions: %v", cfg.Region, err)
+ log.Errorf(ctx, "Region '%s' selected after failure to retrieve aws regions: %v", cfg.Region, err)
regionList = []string{cfg.Region}
}
for _, region := range regionList {
diff --git a/internal/resources/providers/awslib/rds/provider.go b/internal/resources/providers/awslib/rds/provider.go
index f1d133d6..7c0c90ca 100644
--- a/internal/resources/providers/awslib/rds/provider.go
+++ b/internal/resources/providers/awslib/rds/provider.go
@@ -52,7 +52,7 @@ func (p Provider) DescribeDBInstances(ctx context.Context) ([]awslib.AwsResource
for {
output, err := c.DescribeDBInstances(ctx, dbInstancesInput)
if err != nil {
- p.log.Errorf("Could not describe DB instances. Error: %v", err)
+ p.log.Errorf(ctx, "Could not describe DB instances. Error: %v", err)
return result, err
}
@@ -89,7 +89,7 @@ func (p Provider) getDBInstanceSubnets(ctx context.Context, region string, dbIns
resultSubnet := Subnet{ID: *subnet.SubnetIdentifier, RouteTable: nil}
routeTableForSubnet, err := p.ec2.GetRouteTableForSubnet(ctx, region, *subnet.SubnetIdentifier, *dbInstance.DBSubnetGroup.VpcId)
if err != nil {
- p.log.Errorf("Could not get route table for subnet %s of DB %s. Error: %v", *subnet.SubnetIdentifier, *dbInstance.DBInstanceIdentifier, err)
+ p.log.Errorf(ctx, "Could not get route table for subnet %s of DB %s. Error: %v", *subnet.SubnetIdentifier, *dbInstance.DBInstanceIdentifier, err)
} else {
var routes []Route
for _, route := range routeTableForSubnet.Routes {
diff --git a/internal/resources/providers/awslib/s3/provider.go b/internal/resources/providers/awslib/s3/provider.go
index 4d176baf..6f871a8c 100644
--- a/internal/resources/providers/awslib/s3/provider.go
+++ b/internal/resources/providers/awslib/s3/provider.go
@@ -65,7 +65,7 @@ func (p Provider) DescribeBuckets(ctx context.Context) ([]awslib.AwsResource, er
}
clientBuckets, err := defaultClient.ListBuckets(ctx, &s3Client.ListBucketsInput{})
if err != nil {
- p.log.Errorf("Could not list s3 buckets: %v", err)
+ p.log.Errorf(ctx, "Could not list s3 buckets: %v", err)
return nil, err
}
@@ -77,7 +77,7 @@ func (p Provider) DescribeBuckets(ctx context.Context) ([]awslib.AwsResource, er
accountPublicAccessBlockConfig, accountPublicAccessBlockErr := p.getAccountPublicAccessBlock(ctx)
if accountPublicAccessBlockErr != nil {
- p.log.Errorf("Could not get account public access block configuration. Err: %v", accountPublicAccessBlockErr)
+ p.log.Errorf(ctx, "Could not get account public access block configuration. Err: %v", accountPublicAccessBlockErr)
}
bucketsRegionsMapping := p.getBucketsRegionMapping(ctx, clientBuckets.Buckets)
@@ -87,22 +87,22 @@ func (p Provider) DescribeBuckets(ctx context.Context) ([]awslib.AwsResource, er
// of the flow, so we should keep describing the bucket even if getting these objects fails.
sseAlgorithm, encryptionErr := p.getBucketEncryptionAlgorithm(ctx, bucket.Name, region)
if encryptionErr != nil {
- p.log.Errorf("Could not get encryption for bucket %s. Error: %v", *bucket.Name, encryptionErr)
+ p.log.Errorf(ctx, "Could not get encryption for bucket %s. Error: %v", *bucket.Name, encryptionErr)
}
bucketPolicy, policyErr := p.GetBucketPolicy(ctx, bucket.Name, region)
if policyErr != nil {
- p.log.Errorf("Could not get bucket policy for bucket %s. Error: %v", *bucket.Name, policyErr)
+ p.log.Errorf(ctx, "Could not get bucket policy for bucket %s. Error: %v", *bucket.Name, policyErr)
}
bucketVersioning, versioningErr := p.getBucketVersioning(ctx, bucket.Name, region)
if versioningErr != nil {
- p.log.Errorf("Could not get bucket versioning for bucket %s. Err: %v", *bucket.Name, versioningErr)
+ p.log.Errorf(ctx, "Could not get bucket versioning for bucket %s. Err: %v", *bucket.Name, versioningErr)
}
publicAccessBlockConfiguration, publicAccessBlockErr := p.getPublicAccessBlock(ctx, bucket.Name, region)
if publicAccessBlockErr != nil {
- p.log.Errorf("Could not get public access block configuration for bucket %s. Err: %v", *bucket.Name, publicAccessBlockErr)
+ p.log.Errorf(ctx, "Could not get public access block configuration for bucket %s. Err: %v", *bucket.Name, publicAccessBlockErr)
}
result = append(result, BucketDescription{
@@ -191,7 +191,7 @@ func (p Provider) getBucketsRegionMapping(ctx context.Context, buckets []types.B
// If we could not get the Region for a bucket, additional API calls for resources will probably fail, we should
// not describe this bucket.
if regionErr != nil {
- p.log.Errorf("Could not get bucket location for bucket %s. Not describing this bucket. Error: %v", *clientBucket.Name, regionErr)
+ p.log.Errorf(ctx, "Could not get bucket location for bucket %s. Not describing this bucket. Error: %v", *clientBucket.Name, regionErr)
continue
}
diff --git a/internal/resources/providers/awslib/sns/provider.go b/internal/resources/providers/awslib/sns/provider.go
index e6d1c5c2..f17b4407 100644
--- a/internal/resources/providers/awslib/sns/provider.go
+++ b/internal/resources/providers/awslib/sns/provider.go
@@ -48,7 +48,7 @@ func (p *Provider) ListTopics(ctx context.Context) ([]types.Topic, error) {
for {
output, err := c.ListTopics(ctx, input)
if err != nil {
- p.log.Errorf("Could not list SNS Topics. Error: %s", err)
+ p.log.Errorf(ctx, "Could not list SNS Topics. Error: %s", err)
return nil, err
}
all = append(all, output.Topics...)
@@ -93,7 +93,7 @@ func (p *Provider) ListTopicsWithSubscriptions(ctx context.Context) ([]awslib.Aw
for {
output, err := c.Lis…
b100e0a to
fa34dfc
Compare
orestisfl
added a commit
that referenced
this pull request
Aug 12, 2025
### Summary of your changes Simplifies test files by removing direct invocations of the clog package. Benefits: 1. Centralized invocation 2. No manual naming needed 3. Test-related logging configuration can be changed at once across all tests Making a separate PR to help with #3514
5 tasks
Span naming convention: `<package>.<receiver>.<method>` According to elastic/security-team#13322
This commit refactors the OpenTelemetry (OTel) instrumentation to use global tracer and meter providers instead of passing them through the context. This simplifies the observability setup and removes the need for custom wrappers around OTel functions. This approach is idiomatic in OpenTelemetry-Go. OTel uses a delegation pattern where a default, no-op provider is initially present. When the application later configures and sets the actual provider, the default provider delegates all calls to the new, configured one. This design makes the initialization order flexible and robust, ensuring all components use the same fully-configured provider, regardless of when they were initialized. See: https://seth-shi.medium.com/why-can-otel-gettracerprovider-5bfbc73db828 Key changes: - The `internal/infra/observability/context.go` file has been removed, as providers are no longer stored in the context. - `internal/infra/observability/otel.go` now initializes and manages global `TracerProvider` and `MeterProvider` instances using a `sync.Once` to ensure they are set up only once. - The `observability.StartSpan` and `observability.MeterFromContext` helper functions have been removed. Callers now use the standard `otel.Tracer(name).Start()` and `otel.Meter(name)` to create spans and get meters directly. - All call sites have been updated to use the new approach, obtaining tracers and meters from the global OTel instance. - The `SetUpOtel` function no longer returns a context, as it now configures the global providers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of your changes
Screenshot/Data
Related Issues
Checklist
Introducing a new rule?