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

feat: support SDK metadata loading and setting user-agent headers #127

Merged
merged 8 commits into from
Dec 12, 2024

Conversation

Mohammad-Dwairi
Copy link
Contributor

@Mohammad-Dwairi Mohammad-Dwairi commented Dec 12, 2024

Situation

We need a way to identify the environment the SDK is working in, including the SDK version, artifact name, and other host system properties like OS name and version.

These loaded metadata will typically used as User-Agent header in the outgoing requests.

Task

  1. Build a utility that loads the required SDK metadata with minimal overhead.
  2. Ensure that all requests has correct User-Agent header.

Action

MetadataLoader Object

Utility object for loading SDK metadata from the generated sdk.properties file along with other
system properties like JVM info and host OS info.

Usage

  1. Call MetadataLoader.load() to read the sdk.properties file. The loaded metadata will be cached by default and any subsequent calls will return the same Metadata instance.
  2. Call MetadataLoader.clear() to clear the cached data.

RequestHeadersInterceptor Class

An Interceptor implementation for setting required headers before executing the request within the SDK. Used to set the User-Agent header from the loaded metadata.


Generate sdk.properties File

Created a new Gradle task in code/tasks-gradle/sdk-properties.gradle to generate the sdk.properties file at build time. This file is placed into the artifact resources and visible in the classpath.


code/tasks-gradle/test.gradle File

  1. Moved all test-related Gradle configurations to a separate file code/tasks-gradle/test.gradle and imported it in the root build.gradle.
  2. Added a small script to exclude build resource [build/resources/main/sdk.properties] from being visible during the tests execution for better isolation.

Testing

  1. Manually verified the results on local runs
  2. Manually verified the results by publishing a version to mavenLocal() and install it in a scratch project.
  3. Added unit tests for MetadataLoader and RequestHeadersInterceptor with 100% coverage.

Results

  1. SDK metadata are loaded by the MetadataLoader object.
  2. The sdk.properties file is generated at build time.
  3. The User-Agent header is set in all SDK requests.

User-Agent Header Logs

Screenshot 2024-12-12 at 12 15 30

@Mohammad-Dwairi Mohammad-Dwairi requested a review from a team as a code owner December 12, 2024 09:55
@Mohammad-Dwairi Mohammad-Dwairi changed the title feat: support loading SDK metadata and setting user-agent headers feat: support SDK metadata loading and setting user-agent headers Dec 12, 2024
@OmarAlJarrah
Copy link
Contributor

For this comment, change reverted and to be revisited in the future.

@Mohammad-Dwairi Mohammad-Dwairi merged commit d992ddf into main Dec 12, 2024
1 check passed
@Mohammad-Dwairi Mohammad-Dwairi deleted the mdwairi/generate-sdk-properties-file branch December 12, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants