-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Implementation of OpenTelemetry Metrics Publisher for Java AW…
…S SDK (#1) * Initial commit * Add CI * Add missing files * Remove java 24 * Add `deploy` * Update * Add tests * Push snapshot * Skip win and mac for now * Duplicate metrics-spi * Build to GitHub * Skip GPG * Skip GPG * Fix owner * Skip unit tests in the CI * Update README * Update README * Add back all OSs * Simplify POM * DEFAULT_METRIC_PREFIX * Publish test results * Add maven compiler plugin * Unique name to upload * Generic cI * Wrong common file * Reuse branch name * Add mock my_test * WIP: test * Fix * Remove version * Remove `GITHUB_TOKEN` references * mvnw * Expect GITHUB_TOKEN * Remove `GITHUB_TOKEN` references * Remove profiel * Separate build and deploy * Pass permissions * version_regex * mvnw * No need to download * No profile * Bo pull_request * Bump upload-artifact * Setup JDK 17 * Update test results * DRY * Add missing newlines * Support Java 8+ * release 8 * Java 8 code * Update maven-compiler-plugin * Fix code to support for Java 8 * Slight refactor
- Loading branch information
Showing
18 changed files
with
1,440 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Branch CI (Snapshot) | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- main | ||
|
||
jobs: | ||
call-build-and-deploy: | ||
permissions: | ||
contents: read | ||
packages: write | ||
uses: ./.github/workflows/build_and_deploy.yml | ||
with: | ||
is_snapshot: true | ||
version_regex: "-SNAPSHOT$" # Ensure the version ends with -SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Build and Deploy | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
is_snapshot: | ||
required: true | ||
type: boolean | ||
version_regex: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-latest, macos-latest ] | ||
java-version: [ '8', '11', '17', '21' ] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK ${{ matrix.java-version }} on ${{ matrix.os }} | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: ${{ matrix.java-version }} | ||
distribution: 'corretto' | ||
cache: maven | ||
|
||
- name: Grant execute permission for mvn-exec.sh | ||
run: chmod +x ./mvnw | ||
|
||
- name: Get Project Version | ||
id: get_version | ||
run: | | ||
VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
echo "VERSION=$VERSION" >> $GITHUB_ENV | ||
- name: Validate Version with Regex | ||
run: | | ||
if [[ "${{ env.VERSION }}" =~ ${{ inputs.version_regex }} ]]; then | ||
echo "Version ${{ env.VERSION }} matches the regex ${{ inputs.version_check }}. Proceeding..." | ||
else | ||
echo "Version ${{ env.VERSION }} does not match the regex ${{ inputs.version_check }}. Failing..." | ||
exit 1 | ||
fi | ||
- name: Build with Maven Wrapper | ||
run: ./mvnw clean verify | ||
|
||
- name: Upload test results | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: test-results - JDK ${{ matrix.java-version }} on ${{ matrix.os }} | ||
path: target/surefire-reports/*.xml | ||
|
||
deploy: | ||
needs: build | ||
permissions: | ||
contents: read | ||
packages: write | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 8 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '8' | ||
distribution: 'corretto' | ||
cache: maven | ||
|
||
- name: Grant execute permission for Maven Wrapper | ||
run: chmod +x ./mvnw | ||
|
||
- name: Deploy SNAPSHOT or Release | ||
run: | | ||
if [[ "$IS_SNAPSHOT" == "true" ]]; then | ||
echo "Deploying SNAPSHOT version..." | ||
./mvnw --batch-mode -DskipTests deploy | ||
else | ||
echo "Deploying RELEASE version..." | ||
./mvnw --batch-mode -DskipTests deploy | ||
fi | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
IS_SNAPSHOT: ${{ inputs.is_snapshot }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Main CI (Release) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
call-build-and-deploy: | ||
permissions: | ||
contents: read | ||
packages: write | ||
uses: ./.github/workflows/build_and_deploy.yml | ||
with: | ||
is_snapshot: false | ||
version_regex: "^[^\\s-]+$" # Ensure the version does not contain -SNAPSHOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Test Results | ||
|
||
on: | ||
workflow_run: | ||
workflows: | ||
- "Branch CI (Snapshot)" | ||
types: | ||
- completed | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
test-results: | ||
name: Test Results | ||
runs-on: ubuntu-latest | ||
if: github.event.workflow_run.conclusion != 'skipped' | ||
|
||
permissions: | ||
checks: write | ||
pull-requests: write | ||
actions: read | ||
|
||
steps: | ||
- name: Download and Extract Artifacts | ||
uses: dawidd6/action-download-artifact@v6 | ||
with: | ||
run_id: ${{ github.event.workflow_run.id }} | ||
path: artifacts | ||
|
||
- name: Publish Test Results | ||
uses: EnricoMi/publish-unit-test-result-action@v2 | ||
with: | ||
commit: ${{ github.event.workflow_run.head_sha }} | ||
event_file: artifacts/Event File/event.json | ||
event_name: ${{ github.event.workflow_run.event }} | ||
files: "artifacts/**/*.xml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
wrapperVersion=3.3.2 | ||
distributionType=only-script | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Contributing to AWS SDK Java OpenTelemetry Metrics | ||
|
||
We welcome contributions to this project! Below are guidelines to help you get started. | ||
|
||
## How to Contribute | ||
|
||
1. **Fork the repository**: | ||
Create your own fork of the repository by clicking the "Fork" button in GitHub. | ||
|
||
2. **Create a feature branch**: | ||
Clone your fork locally, then create a feature branch for your work: | ||
|
||
```bash | ||
git checkout -b feature/my-new-feature | ||
``` | ||
|
||
3. **Make your changes**: | ||
Implement your changes, ensuring that they follow the project’s coding standards and best practices. | ||
|
||
4. **Commit your changes**: | ||
Commit your changes to your feature branch: | ||
|
||
```bash | ||
git commit -am 'Add some feature' | ||
``` | ||
|
||
5. **Push your changes to your fork**: | ||
Push your changes to your fork on GitHub: | ||
|
||
```bash | ||
git push origin feature/my-new-feature | ||
``` | ||
|
||
6. **Create a Pull Request**: | ||
Once your changes are ready, open a pull request (PR) from your branch on GitHub. | ||
- Ensure that your PR description explains what changes you’ve made and why. | ||
- Mention any related issues, if applicable. | ||
|
||
## Running Tests | ||
|
||
Before submitting a PR, make sure all tests pass: | ||
|
||
```bash | ||
./mvnw test | ||
``` | ||
|
||
If you’ve added new features, consider adding appropriate unit tests as well. | ||
|
||
## Code of Conduct | ||
|
||
Please note that this project is governed by a [Code of Conduct]. By participating, you are expected to uphold this code. | ||
|
||
[Code of Conduct]: CODE_OF_CONDUCT.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
# aws-sdk-java-opentelemetry-metrics | ||
OpenTelemetry Metric Publisher for AWS SDK for Java – Export AWS SDK metrics to OpenTelemetry for enhanced observability | ||
# AWS SDK Java OpenTelemetry Metrics | ||
|
||
A lightweight metrics publisher that integrates AWS SDK metrics with OpenTelemetry, allowing you to monitor and collect | ||
AWS client performance metrics in your distributed applications. | ||
|
||
## Usage | ||
|
||
This library integrates AWS SDK Java metrics with OpenTelemetry’s metrics API, allowing you to collect and publish AWS client performance data such as API call durations, retry counts, and more. | ||
|
||
### Basic Example | ||
|
||
Here’s a simple example of how to use the `OtelMetricPublisher`: | ||
|
||
```java | ||
import com.appsflyer.otelawsmetrics.OtelMetricPublisher; | ||
import io.opentelemetry.api.OpenTelemetry; | ||
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; | ||
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; | ||
import software.amazon.awssdk.metrics.MetricPublisher; | ||
|
||
public class MyAwsService { | ||
private final DynamoDbAsyncClient dynamoDbAsyncClient; | ||
|
||
public MyAwsService(OpenTelemetry openTelemetry) { | ||
// Create the metric publisher | ||
MetricPublisher metricPublisher = new OtelMetricPublisher(openTelemetry, "aws.sdk"); | ||
|
||
// Create the DynamoDbAsyncClient with the metric publisher | ||
this.dynamoDbAsyncClient = DynamoDbAsyncClient.builder() | ||
.overrideConfiguration(ClientOverrideConfiguration.builder() | ||
.addMetricPublisher(metricPublisher) | ||
.build()) | ||
.build(); | ||
} | ||
|
||
public void putItemAsync(String tableName, Map<String, AttributeValue> item) { | ||
// Perform DynamoDB operations and automatically collect metrics | ||
dynamoDbAsyncClient.putItem(putItemRequest -> putItemRequest.tableName(tableName).item(item)); | ||
} | ||
} | ||
``` | ||
|
||
### Configuration | ||
|
||
You can configure the OtelMetricPublisher with additional options if needed: | ||
|
||
```java | ||
Executor customExecutor = Executors.newSingleThreadExecutor(); | ||
OtelMetricPublisher metricPublisher = new OtelMetricPublisher(OpenTelemetry.get(), customExecutor); | ||
``` | ||
|
||
This allows you to use a custom executor for asynchronous metrics publishing. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the LICENSE file for details. | ||
|
Oops, something went wrong.