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

Initial Implementation of OpenTelemetry Metrics Publisher for Java AWS SDK #1

Merged
merged 53 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6647945
Initial commit
evg-tso Sep 15, 2024
d2d40d6
Add CI
evg-tso Sep 15, 2024
fb61435
Add missing files
evg-tso Sep 15, 2024
7275816
Remove java 24
evg-tso Sep 15, 2024
a1141e8
Add `deploy`
evg-tso Sep 15, 2024
e25be9c
Update
evg-tso Sep 15, 2024
f367b92
Add tests
evg-tso Sep 15, 2024
7a9da6b
Push snapshot
evg-tso Sep 15, 2024
4203e4c
Skip win and mac for now
evg-tso Sep 15, 2024
b3961d2
Duplicate metrics-spi
evg-tso Sep 15, 2024
1f674aa
Build to GitHub
evg-tso Sep 15, 2024
f55cf7a
Skip GPG
evg-tso Sep 15, 2024
84d8a9b
Skip GPG
evg-tso Sep 15, 2024
c3a4cf8
Fix owner
evg-tso Sep 15, 2024
89da5a6
Skip unit tests in the CI
evg-tso Sep 15, 2024
9f41094
Update README
evg-tso Sep 15, 2024
d261f21
Update README
evg-tso Sep 15, 2024
748a33e
Add back all OSs
evg-tso Sep 15, 2024
ce7a653
Simplify POM
evg-tso Sep 15, 2024
ed19a52
DEFAULT_METRIC_PREFIX
evg-tso Sep 15, 2024
9e3101c
Publish test results
evg-tso Sep 15, 2024
ba5e6d9
Add maven compiler plugin
evg-tso Sep 15, 2024
95d31f5
Unique name to upload
evg-tso Sep 15, 2024
056f565
Generic cI
evg-tso Sep 15, 2024
050fd18
Wrong common file
evg-tso Sep 15, 2024
3d2e8f3
Reuse branch name
evg-tso Sep 15, 2024
78e139d
Add mock my_test
evg-tso Sep 15, 2024
86aa6ac
WIP: test
evg-tso Sep 15, 2024
a93143e
Fix
evg-tso Sep 15, 2024
1fd35f1
Remove version
evg-tso Sep 15, 2024
6ff9c00
Remove `GITHUB_TOKEN` references
evg-tso Sep 15, 2024
0d3be37
mvnw
evg-tso Sep 15, 2024
a2e5469
Expect GITHUB_TOKEN
evg-tso Sep 15, 2024
4214b7f
Remove `GITHUB_TOKEN` references
evg-tso Sep 15, 2024
d68240e
Remove profiel
evg-tso Sep 15, 2024
7d27375
Separate build and deploy
evg-tso Sep 15, 2024
df95034
Pass permissions
evg-tso Sep 15, 2024
2de568f
version_regex
evg-tso Sep 15, 2024
ca36030
mvnw
evg-tso Sep 15, 2024
2fd3333
No need to download
evg-tso Sep 15, 2024
08960fd
No profile
evg-tso Sep 15, 2024
cb79208
Bo pull_request
evg-tso Sep 15, 2024
9e6497d
Bump upload-artifact
evg-tso Sep 15, 2024
bc6bef5
Setup JDK 17
evg-tso Sep 15, 2024
10e71f2
Update test results
evg-tso Sep 15, 2024
0e3a6b8
DRY
evg-tso Sep 15, 2024
0a351e9
Add missing newlines
evg-tso Sep 15, 2024
7847e72
Support Java 8+
evg-tso Sep 16, 2024
9f781f4
release 8
evg-tso Sep 16, 2024
0c3b40f
Java 8 code
evg-tso Sep 16, 2024
3e0e26e
Update maven-compiler-plugin
evg-tso Sep 16, 2024
713c9b3
Fix code to support for Java 8
evg-tso Sep 16, 2024
b9d73ca
Slight refactor
evg-tso Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/branch_ci.yml
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
91 changes: 91 additions & 0 deletions .github/workflows/build_and_deploy.yml
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 }}
16 changes: 16 additions & 0 deletions .github/workflows/main_ci.yml
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
36 changes: 36 additions & 0 deletions .github/workflows/test_results.yml
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"
35 changes: 35 additions & 0 deletions .gitignore
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
19 changes: 19 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
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
53 changes: 53 additions & 0 deletions CONTRIBUTING.md
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
59 changes: 57 additions & 2 deletions README.md
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.

Loading