-
Notifications
You must be signed in to change notification settings - Fork 989
Add propertiesSupplier support to EmfMetricLoggingPublisher #6735
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
Open
humanzz
wants to merge
7
commits into
aws:master
Choose a base branch
from
humanzz:emf-props-supplier
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+323
−7
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c98f9ab
Add propertiesSupplier support to EmfMetricLoggingPublisher
humanzz 40d3017
Merge branch 'master' into emf-props-supplier
dagnir e8d055c
Filter out colliding keys when writing custom properties
humanzz 47f0798
Merge branch 'emf-props-supplier' of https://github.com/humanzz/aws-s…
humanzz 64f42ba
Drop blank lines
humanzz cb95036
Drop unused import
humanzz 0b08d7b
Merge branch 'master' into emf-props-supplier
humanzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changes/next-release/feature-AmazonCloudWatchEMFMetricPublisher-33792c9.json
This file contains hidden or 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,6 @@ | ||
| { | ||
| "type": "feature", | ||
| "category": "Amazon CloudWatch EMF Metric Publisher", | ||
| "contributor": "humanzz", | ||
| "description": "Add `propertiesSupplier` to `EmfMetricLoggingPublisher.Builder`, enabling users to enrich EMF records with custom key-value properties that are searchable in CloudWatch Logs Insights. See [#6595](https://github.com/aws/aws-sdk-java-v2/issues/6595)." | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm what is the advantage of taking a
Supplieras opposed to aMapdirectly in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the properties are not necessarily static and known at publisher initialization time. An example is if I want to include a request id to correlate to other log lines/metrics within the same overall request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense but it seems like it would be hard in many scenarios to correctly determine that data, especially in a multi tenant or highly concurrent environment given that it doesn't have take any input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm taking inspiration but simplifying what's happening in aws-embedded-metrics-java for injecting ambient context into EMF output.
In that library, the
Environmentinterface defines aconfigureContext(MetricsContext)method that each environment implementation uses to enrich EMF records with runtime properties. For example,LambdaEnvironment.configureContext()injectsexecutionEnvironment,functionVersion,logStreamId, andtraceIdby reading environment variables — notably, it also takes no per-request input, it just reads from ambient state. These properties end up as top-level keys in the EMF JSON.The
Supplier<Map<String, String>>is the same concept, just simplified. Instead of requiring users to implement a fullEnvironmentinterface, we provide a lightweightSuppliercallback that does the same thing — provide ambient context at publish time. The supplier implementer would have the responsibility to define their own strategy for dealing with multi-tenancy or concurrency, if required — though in Lambda environments, where this publisher makes the most sense, each invocation runs in its own execution context so ambient state is naturally request-scoped.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, another thing I wanna call out — I went with
Map<String, String>rather thanMap<String, Object>. The EMF spec allows any valid JSON type for root node members, and the aws-embedded-metrics-java library usesMap<String, Object>for itsputProperty. I choseStringto keep the implementation simple — the primary use case is contextual metadata like request IDs and trace IDs, andStringcovers that well. UsingObjectwould require type-dispatching in the serializer sinceJsonWriterhas separate overloads forString,long,double,boolean, etc., plus handling for unsupported types. If needed, we can always widen toObjectlater without breaking backward compatibility (narrowing would be a breaking change). Happy to change if you'd preferObjectfrom the start.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed reply!
Map<String, String>overMap<String, Object>as it does greatly simplify the interface while addressing what we foresee as the majority use case. And as you said, it's not a one-way door.Supplieris more than sufficient; I was imagining other scenarios where the interface might benefit from information in order to compute the correct map values to enter. One thing I could think of is if a user may want to emit some high cardinality information like ServiceEndpoint as a property, which would be difficult to plumb through with this interface. I think even in this case though this isn't a one way door since we could overload it with aFunctionor something similar in the future. Let me take this discussion back to the rest of the team to get their input and get back to you.