Skip to content

Commit 7d8ed05

Browse files
committed
add builder
1 parent 301180e commit 7d8ed05

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 java.io.PrintStream;
19+
import software.amazon.opentelemetry.javaagent.providers.exporter.aws.metrics.common.emitter.ConsoleEmitter;
20+
import software.amazon.opentelemetry.javaagent.providers.exporter.aws.metrics.common.emitter.LogEventEmitter;
21+
22+
public class ConsoleEmfExporterBuilder {
23+
private String namespace;
24+
private LogEventEmitter<PrintStream> emitter;
25+
private boolean shouldAddApplicationSignalsDimensions = false;
26+
27+
public ConsoleEmfExporterBuilder setNamespace(String namespace) {
28+
this.namespace = namespace;
29+
return this;
30+
}
31+
32+
public ConsoleEmfExporterBuilder setEmitter(LogEventEmitter<PrintStream> emitter) {
33+
this.emitter = emitter;
34+
return this;
35+
}
36+
37+
public ConsoleEmfExporterBuilder setShouldAddApplicationSignalsDimensions(
38+
boolean shouldAddApplicationSignalsDimensions) {
39+
this.shouldAddApplicationSignalsDimensions = shouldAddApplicationSignalsDimensions;
40+
return this;
41+
}
42+
43+
public ConsoleEmfExporter build() {
44+
if (this.namespace == null) {
45+
this.namespace = "default";
46+
}
47+
if (this.emitter == null) {
48+
this.emitter = new ConsoleEmitter();
49+
}
50+
return ConsoleEmfExporter.create(
51+
this.namespace, this.emitter, this.shouldAddApplicationSignalsDimensions);
52+
}
53+
}

0 commit comments

Comments
 (0)