Skip to content

Commit

Permalink
trying to fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Paramadon committed Dec 10, 2024
1 parent 9dce4e2 commit 8a9b9f3
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 42 deletions.
68 changes: 37 additions & 31 deletions exporter/awsemfexporter/emf_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"sync"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/google/uuid"
Expand All @@ -21,7 +23,6 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter/internal/appsignals"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs"
)

Expand All @@ -39,6 +40,7 @@ type emfExporter struct {
pusherMap map[cwlogs.StreamKey]cwlogs.Pusher
svcStructuredLog *cwlogs.Client
config *Config
set exporter.Settings

metricTranslator metricTranslator

Expand All @@ -57,42 +59,18 @@ func newEmfExporter(config *Config, set exporter.Settings) (*emfExporter, error)

config.logger = set.Logger

// create AWS session
awsConfig, session, err := awsutil.GetAWSConfigSession(set.Logger, &awsutil.Conn{}, &config.AWSSessionSettings)
if err != nil {
return nil, err
}

// create CWLogs client with aws session config
svcStructuredLog := cwlogs.NewClient(set.Logger,
awsConfig,
set.BuildInfo,
config.LogGroupName,
config.LogRetention,
config.Tags,
session,
cwlogs.WithEnabledContainerInsights(config.IsEnhancedContainerInsights()),
cwlogs.WithEnabledAppSignals(config.IsAppSignalsEnabled()),
)

collectorIdentifier, err := uuid.NewRandom()
if err != nil {
return nil, err
}

// Initialize emfExporter without AWS session and structured logs
emfExporter := &emfExporter{
svcStructuredLog: svcStructuredLog,
config: config,
metricTranslator: newMetricTranslator(*config),
retryCnt: *awsConfig.MaxRetries,
collectorID: collectorIdentifier.String(),
retryCnt: config.AWSSessionSettings.MaxRetries,
collectorID: uuid.New().String(),
pusherMap: map[cwlogs.StreamKey]cwlogs.Pusher{},
processResourceLabels: func(map[string]string) {},
}

if config.IsAppSignalsEnabled() {
userAgent := appsignals.NewUserAgent()
svcStructuredLog.Handlers().Build.PushBackNamed(userAgent.Handler())
emfExporter.processResourceLabels = userAgent.Process
}

Expand Down Expand Up @@ -140,7 +118,6 @@ func (emf *emfExporter) pushMetricsData(_ context.Context, md pmetric.Metrics) e
return err
}

// Currently we only support two options for "OutputDestination".
if strings.EqualFold(outputDestination, outputDestinationStdout) {
if putLogEvent != nil &&
putLogEvent.InputLogEvent != nil &&
Expand Down Expand Up @@ -196,10 +173,39 @@ func (emf *emfExporter) listPushers() []cwlogs.Pusher {
return pushers
}

func (emf *emfExporter) start(_ context.Context, host component.Host) error {
func (emf *emfExporter) start(ctx context.Context, host component.Host) error {
// Create AWS session here
awsConfig, session, err := awsutil.GetAWSConfigSession(emf.config.logger, &awsutil.Conn{}, &emf.config.AWSSessionSettings)
if err != nil {
return err
}

// create CWLogs client with aws session config
svcStructuredLog := cwlogs.NewClient(emf.config.logger,
awsConfig,
emf.set.BuildInfo,
emf.config.LogGroupName,
emf.config.LogRetention,
emf.config.Tags,
session,
cwlogs.WithEnabledContainerInsights(emf.config.IsEnhancedContainerInsights()),
cwlogs.WithEnabledAppSignals(emf.config.IsAppSignalsEnabled()),
)

// Assign to the struct
emf.svcStructuredLog = svcStructuredLog

if emf.config.IsAppSignalsEnabled() {
userAgent := appsignals.NewUserAgent()
svcStructuredLog.Handlers().Build.PushBackNamed(userAgent.Handler())
emf.processResourceLabels = userAgent.Process
}

// Optionally configure middleware
if emf.config.MiddlewareID != nil {
awsmiddleware.TryConfigure(emf.config.logger, host, *emf.config.MiddlewareID, awsmiddleware.SDKv1(emf.svcStructuredLog.Handlers()))
awsmiddleware.TryConfigure(emf.config.logger, host, *emf.config.MiddlewareID, awsmiddleware.SDKv1(svcStructuredLog.Handlers()))
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/metadataproviders/aws/ec2/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ec2 // import "github.com/open-telemetry/opentelemetry-collector-contrib

import (
"context"

"github.com/aws/aws-sdk-go/aws/request"

override "github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws"
Expand Down
3 changes: 2 additions & 1 deletion processor/resourcedetectionprocessor/internal/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package ec2 // import "github.com/open-telemetry/opentelemetry-collector-contrib
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws/request"
"net/http"
"regexp"

"github.com/aws/aws-sdk-go/aws/request"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ package internal // import "github.com/open-telemetry/opentelemetry-collector-co
import (
"context"
"fmt"
"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"github.com/aws/aws-sdk-go/aws/request"
"go.opentelemetry.io/collector/component"
"net/http"
"sync"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"github.com/aws/aws-sdk-go/aws/request"
"go.opentelemetry.io/collector/component"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/processor"
"go.uber.org/zap"
Expand Down
3 changes: 2 additions & 1 deletion receiver/awscontainerinsightreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
package awscontainerinsightreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver"

import (
"go.opentelemetry.io/collector/component"
"time"

"go.opentelemetry.io/collector/component"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bufio"
"context"
"fmt"
"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"log"
"os"
"path/filepath"
Expand All @@ -17,6 +16,8 @@ import (
"sync"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ package host // import "github.com/open-telemetry/opentelemetry-collector-contri

import (
"context"
"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"log"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"

override "github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws"
"github.com/aws/aws-sdk-go/aws"
awsec2metadata "github.com/aws/aws-sdk-go/aws/ec2metadata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ package host // import "github.com/open-telemetry/opentelemetry-collector-contri

import (
"context"
"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"log"
"strings"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ package host // import "github.com/open-telemetry/opentelemetry-collector-contri
import (
"context"
"fmt"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
"go.uber.org/zap"
"time"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil"
)

// Info contains information about a host
Expand Down
3 changes: 2 additions & 1 deletion receiver/awscontainerinsightreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"context"
"errors"
"fmt"
"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"
"os"
"runtime"
"time"

"github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down

0 comments on commit 8a9b9f3

Please sign in to comment.