|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.opentelemetry.javaagent.providers.exporter.aws.metrics; |
| 17 | + |
| 18 | +import static java.util.Objects.requireNonNull; |
| 19 | + |
| 20 | +import software.amazon.awssdk.services.cloudwatchlogs.CloudWatchLogsClient; |
| 21 | +import software.amazon.opentelemetry.javaagent.providers.exporter.aws.metrics.common.emitter.CloudWatchLogsClientEmitter; |
| 22 | +import software.amazon.opentelemetry.javaagent.providers.exporter.aws.metrics.common.emitter.LogEventEmitter; |
| 23 | + |
| 24 | +public class AwsCloudWatchEmfExporterBuilder { |
| 25 | + private String namespace; |
| 26 | + private String logGroupName; |
| 27 | + private String logStreamName; |
| 28 | + private String awsRegion; |
| 29 | + private LogEventEmitter<CloudWatchLogsClient> emitter; |
| 30 | + private boolean shouldAddApplicationSignalsDimensions = false; |
| 31 | + |
| 32 | + public AwsCloudWatchEmfExporterBuilder setNamespace(String namespace) { |
| 33 | + this.namespace = namespace; |
| 34 | + return this; |
| 35 | + } |
| 36 | + |
| 37 | + public AwsCloudWatchEmfExporterBuilder setLogGroupName(String logGroupName) { |
| 38 | + this.logGroupName = logGroupName; |
| 39 | + return this; |
| 40 | + } |
| 41 | + |
| 42 | + public AwsCloudWatchEmfExporterBuilder setLogStreamName(String logStreamName) { |
| 43 | + this.logStreamName = logStreamName; |
| 44 | + return this; |
| 45 | + } |
| 46 | + |
| 47 | + public AwsCloudWatchEmfExporterBuilder setAwsRegion(String awsRegion) { |
| 48 | + this.awsRegion = awsRegion; |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + public AwsCloudWatchEmfExporterBuilder setEmitter(LogEventEmitter<CloudWatchLogsClient> emitter) { |
| 53 | + this.emitter = emitter; |
| 54 | + return this; |
| 55 | + } |
| 56 | + |
| 57 | + public AwsCloudWatchEmfExporterBuilder setShouldAddApplicationSignalsDimensions( |
| 58 | + boolean shouldAddApplicationSignalsDimensions) { |
| 59 | + this.shouldAddApplicationSignalsDimensions = shouldAddApplicationSignalsDimensions; |
| 60 | + return this; |
| 61 | + } |
| 62 | + |
| 63 | + public AwsCloudWatchEmfExporter build() { |
| 64 | + if (this.namespace == null) { |
| 65 | + this.namespace = "default"; |
| 66 | + } |
| 67 | + |
| 68 | + if (this.emitter == null) { |
| 69 | + requireNonNull(logGroupName, "Must set logGroupName when emitter is not provided"); |
| 70 | + requireNonNull(logStreamName, "Must set logStreamName when emitter is not provided"); |
| 71 | + requireNonNull(awsRegion, "Must set awsRegion when emitter is not provided"); |
| 72 | + this.emitter = new CloudWatchLogsClientEmitter(logGroupName, logStreamName, awsRegion); |
| 73 | + } |
| 74 | + return AwsCloudWatchEmfExporter.create( |
| 75 | + this.namespace, this.emitter, this.shouldAddApplicationSignalsDimensions); |
| 76 | + } |
| 77 | +} |
0 commit comments