Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract CWlogs client from EMF exporter and use in Awscloudwatchlogsexporter #6969

Closed
8 changes: 7 additions & 1 deletion cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require (
golang.org/x/mod v0.5.1
)

require go.uber.org/multierr v1.7.0

require (
bitbucket.org/atlassian/go-asap/v2 v2.6.0 // indirect
cloud.google.com/go v0.99.0 // indirect
Expand Down Expand Up @@ -186,6 +188,7 @@ require (
github.com/observiq/go-syslog/v3 v3.0.2 // indirect
github.com/olivere/elastic v6.2.37+incompatible // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/alibabacloudlogserviceexporter v0.41.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter v0.41.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter v0.41.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awskinesisexporter v0.41.0 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsprometheusremotewriteexporter v0.41.0 // indirect
Expand Down Expand Up @@ -393,7 +396,6 @@ require (
go.opentelemetry.io/otel/sdk v1.3.0 // indirect
go.opentelemetry.io/otel/trace v1.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
Expand Down Expand Up @@ -461,6 +463,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/x

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil => ../../internal/aws/awsutil

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cloudwatch => ../../internal/aws/cloudwatch

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight => ../../internal/aws/containerinsight

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s => ../../internal/aws/k8s
Expand All @@ -475,6 +479,8 @@ replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/aliba

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsprometheusremotewriteexporter => ../../exporter/awsprometheusremotewriteexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporterexporter => ../../exporter/awscloudwatchlogsexporterexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter => ../../exporter/awsemfexporter

replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter => ../../exporter/awsxrayexporter
Expand Down
24 changes: 24 additions & 0 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions exporter/awscloudwatchlogsexporter/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# AWS CloudWatch Logs Exporter

AWS CloudWatch Logs Exporter sends logs data to AWS [CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html).
AWS credentials are retrieved from the [default credential chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials).
Region must be configured in the configuration if not set in the default credential chain.
AWS CloudWatch Logs Exporter sends logs data to
AWS [CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html). AWS
credentials are retrieved from
the [default credential chain](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials)
. Region must be configured in the configuration if not set in the default credential chain.

NOTE: OpenTelemetry Logging support is experimental, hence this exporter is subject to change.

Expand All @@ -16,7 +18,8 @@ The following settings are required:
The following settings can be optionally configured:

- `region`: The AWS region where the log stream is in.
- `endpoint`: The CloudWatch Logs service endpoint which the requests are forwarded to. [See the CloudWatch Logs endpoints](https://docs.aws.amazon.com/general/latest/gr/cwl_region.html) for a list.
- `endpoint`: The CloudWatch Logs service endpoint which the requests are forwarded
to. [See the CloudWatch Logs endpoints](https://docs.aws.amazon.com/general/latest/gr/cwl_region.html) for a list.

### Examples

Expand Down
6 changes: 6 additions & 0 deletions exporter/awscloudwatchlogsexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (

"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"

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

// Config represent a configuration for the CloudWatch logs exporter.
Expand All @@ -27,6 +30,7 @@ type Config struct {

exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`

awsutil.AWSSessionSettings `mapstructure:",squash"`
// LogGroupName is the name of CloudWatch log group which defines group of log streams
// that share the same retention, monitoring, and access control settings.
LogGroupName string `mapstructure:"log_group_name"`
Expand All @@ -48,6 +52,8 @@ type Config struct {
// QueueSettings is a subset of exporterhelper.QueueSettings,
// because only QueueSize is user-settable due to how AWS CloudWatch API works
QueueSettings QueueSettings `mapstructure:"sending_queue"`

logger *zap.Logger
}

type QueueSettings struct {
Expand Down
20 changes: 12 additions & 8 deletions exporter/awscloudwatchlogsexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/service/servicetest"

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

func TestLoadConfig(t *testing.T) {
Expand All @@ -45,12 +47,13 @@ func TestLoadConfig(t *testing.T) {

assert.Equal(t,
&Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "e1-defaults")),
RetrySettings: defaultRetrySettings,
LogGroupName: "test-1",
LogStreamName: "testing",
Region: "",
Endpoint: "",
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "e1-defaults")),
RetrySettings: defaultRetrySettings,
LogGroupName: "test-1",
LogStreamName: "testing",
Region: "",
Endpoint: "",
AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
QueueSettings: QueueSettings{
QueueSize: exporterhelper.DefaultQueueSettings().QueueSize,
},
Expand All @@ -69,8 +72,9 @@ func TestLoadConfig(t *testing.T) {
MaxInterval: defaultRetrySettings.MaxInterval,
MaxElapsedTime: defaultRetrySettings.MaxElapsedTime,
},
LogGroupName: "test-2",
LogStreamName: "testing",
AWSSessionSettings: awsutil.CreateDefaultSessionConfig(),
LogGroupName: "test-2",
LogStreamName: "testing",
QueueSettings: QueueSettings{
QueueSize: 2,
},
Expand Down
Loading