feat!: Send product metadata in custom header#13
Conversation
| logger.log(System.Logger.Level.WARNING, "Unable to load project properties to determine provider version.", e); | ||
| } | ||
|
|
||
| clientHeaderValueBuilder.append(" openfeature-provider-java/").append(providerVersion); |
There was a problem hiding this comment.
If providerVersion is null this will append "null".
There was a problem hiding this comment.
Pull request overview
Adds consumer-supplied product metadata (name + optional version) into an X-Octopus-Client header on OctoToggle HTTP requests, enabling endpoint/version usage observability for the Java provider. This introduces a breaking change by making ProductMetadata a required part of OctopusConfiguration.
Changes:
- Introduce
ProductMetadatafor cleaning/validating product name/version (RFC 9110 token chars) and add corresponding unit tests. - Make
OctopusConfigurationrequireProductMetadataand plumb it through request-building to emitX-Octopus-Client. - Add Maven resource filtering +
project.propertiesto inject the provider library version into the header, with tests for the composed header value.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/octopus/openfeature/provider/ProductMetadata.java | Adds a value object that sanitizes and validates product name/version inputs. |
| src/main/java/com/octopus/openfeature/provider/OctopusConfiguration.java | Makes ProductMetadata a required configuration field and exposes it to internal components. |
| src/main/java/com/octopus/openfeature/provider/OctopusClient.java | Adds X-Octopus-Client header and builds its value including provider version. |
| src/main/resources/project.properties | New filtered resource to surface ${project.version} at runtime. |
| pom.xml | Enables resource filtering so project.properties is populated during build. |
| src/test/java/com/octopus/openfeature/provider/ProductMetadataTests.java | Unit tests for sanitization/validation rules in ProductMetadata. |
| src/test/java/com/octopus/openfeature/provider/OctopusClientTests.java | Tests for the constructed X-Octopus-Client header value and filtered version injection. |
| src/test/java/com/octopus/openfeature/provider/OctopusConfigurationTests.java | Updates tests for the new OctopusConfiguration constructor signature. |
| src/test/java/com/octopus/openfeature/provider/SpecificationTests.java | Updates spec tests to pass required ProductMetadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static String loadProviderVersion() { | ||
| try { | ||
| var projectProperties = new Properties(); | ||
| try (var resourceStream = OctopusClient.class.getClassLoader().getResourceAsStream("project.properties")) |
There was a problem hiding this comment.
Note: this try is a try-with-resources block; equivalent to C# using(var ...)
|
|
||
| private static final String PROVIDER_VERSION = loadProviderVersion(); | ||
|
|
||
| private static String loadProviderVersion() { |
There was a problem hiding this comment.
Thought from a background thread in my brain: perhaps I should just load this value directly from the pom.xml file in the tests.
Background
We want to be able to observe the usage of the OctoToggle service and its different API endpoints over time. For example, if we wish to deprecate an endpoint or know which customers are using a particular version of a provider library.
This PR is the Java equivalent of OctopusDeploy/openfeature-provider-dotnet#52.
Changes
ProductMetadataclass to clean, validate and contain the consumer provided product name and version values.ProductMetadatarequired argument toOctopusConfiguration(breaking change).project.propertiesfile with resource filtering to allow access to the provider library version (as defined inpom.xml) in the Java code.X-Octopus-Clientheader to HTTP request builder calls.MyProduct/2024.1.0 openfeature-provider-java/0.4.0-SNAPSHOTTesting
In addition to automated tests, I have tested against an OctoToggle ephemeral environment.
With product version
Without product version