Skip to content

Commit 0d88b0b

Browse files
authored
Support synchronously metrics publishing (#18)
* Support synchronously metrics publishing * Update CHANGELOG.md * Update CHANGELOG.md * Add `Pull Request CI (Snapshot)` to support PRs from external contributors
1 parent 5c15a1f commit 0d88b0b

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

.github/workflows/pull_request_ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Pull Request CI (Snapshot)
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- reopened
9+
10+
jobs:
11+
build:
12+
permissions:
13+
contents: read
14+
uses: ./.github/workflows/build.yml
15+
16+
event_file:
17+
needs: build
18+
name: "Event File"
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Upload
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: Event File
25+
path: ${{ github.event_path }}

.github/workflows/test_results.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_run:
55
workflows:
66
- "Branch CI (Snapshot)"
7+
- "Pull Request CI (Snapshot)"
78
types:
89
- completed
910

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.1] - 2024-09-19
9+
10+
### Changed
11+
12+
- Support for a null `executor`, allowing for synchronous metrics publishing.
13+
- Verify `openTelemetry` and `metricPrefix` are not null in the `OtelMetricPublisher` constructor.
14+
815
## [1.0.0] - 2024-09-17
916

1017
### Added
1118

1219
- Initial release of the AWS SDK Java OpenTelemetry Metrics library.
1320

14-
[1.0.0]: https://github.com/olivierlacan/keep-a-changelog/releases/tag/v1.0.0
21+
[1.0.1]: https://github.com/AppsFlyer/aws-sdk-java-opentelemetry-metrics/compare/aws-sdk-java-opentelemetry-metrics-1.0.0...aws-sdk-java-opentelemetry-metrics-1.0.1
22+
23+
[1.0.0]: https://github.com/AppsFlyer/aws-sdk-java-opentelemetry-metrics/releases/tag/aws-sdk-java-opentelemetry-metrics-1.0.0

src/main/java/com/appsflyer/otelawsmetrics/OtelMetricPublisher.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import java.util.HashMap;
1515
import java.util.Map;
16+
import java.util.Objects;
1617
import java.util.concurrent.ConcurrentHashMap;
1718
import java.util.concurrent.Executor;
1819
import java.util.concurrent.ForkJoinPool;
@@ -45,6 +46,13 @@ public OtelMetricPublisher(OpenTelemetry openTelemetry, String metricPrefix) {
4546
}
4647

4748
public OtelMetricPublisher(OpenTelemetry openTelemetry, String metricPrefix, Executor executor) {
49+
Objects.requireNonNull(metricPrefix, "metricPrefix must not be null");
50+
Objects.requireNonNull(openTelemetry, "openTelemetry must not be null");
51+
52+
if (executor == null) {
53+
log.warn("An executor is not provided. The metrics will be published synchronously on the calling thread.");
54+
}
55+
4856
this.metricPrefix = metricPrefix + ".";
4957
this.executor = executor;
5058

@@ -57,6 +65,11 @@ public OtelMetricPublisher(OpenTelemetry openTelemetry, String metricPrefix, Exe
5765

5866
@Override
5967
public void publish(MetricCollection metricCollection) {
68+
if (executor == null) {
69+
publishInternal(metricCollection);
70+
return;
71+
}
72+
6073
try {
6174
executor.execute(() -> publishInternal(metricCollection));
6275
} catch (RejectedExecutionException ex) {

0 commit comments

Comments
 (0)