-
Notifications
You must be signed in to change notification settings - Fork 45
More opamp identity changes #2788
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
Merged
robsunday
merged 7 commits into
signalfx:main
from
breedx-splk:more_opamp_identity_changes
Apr 27, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
75e53d0
rework identifying and non-identifying attributes.
breedx-splk 276bbb1
test improvements
breedx-splk 84e0f6f
split responsibility and test separately
breedx-splk 1d275fb
remove braces
breedx-splk 9770b7d
temp rename
breedx-splk 3e26f0f
rename back
breedx-splk 8ee46ea
simplify tests
breedx-splk 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
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
163 changes: 163 additions & 0 deletions
163
opamp/src/main/java/com/splunk/opentelemetry/opamp/OpampAgentAttributes.java
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,163 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed 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. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.opamp; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.AttributeType; | ||
| import io.opentelemetry.opamp.client.OpampClientBuilder; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
|
|
||
| class OpampAgentAttributes { | ||
| private static final List<String> IDENTIFYING_ATTRIBUTES = | ||
| Arrays.asList("service.name", "service.namespace", "service.instance.id"); | ||
|
|
||
| private final Resource resource; | ||
|
|
||
| OpampAgentAttributes(Resource resource) { | ||
| this.resource = resource; | ||
| } | ||
|
|
||
| void addIdentifyingAttributes(OpampClientBuilder builder) { | ||
| resource.getAttributes().asMap().entrySet().stream() | ||
| .filter(entry -> IDENTIFYING_ATTRIBUTES.contains(entry.getKey().getKey())) | ||
| .forEach(putIdentifyingAttribute(builder)); | ||
| } | ||
|
|
||
| void addNonIdentifyingAttributes(OpampClientBuilder builder) { | ||
| resource.getAttributes().asMap().entrySet().stream() | ||
| .filter(entry -> !IDENTIFYING_ATTRIBUTES.contains(entry.getKey().getKey())) | ||
| .forEach(putNonIdentifyingAttribute(builder)); | ||
| } | ||
|
|
||
| private Consumer<? super Map.Entry<AttributeKey<?>, Object>> putIdentifyingAttribute( | ||
| OpampClientBuilder builder) { | ||
| return entry -> { | ||
| AttributeKey<?> key = entry.getKey(); | ||
| Object value = entry.getValue(); | ||
| AttributeType type = key.getType(); | ||
|
|
||
| // The java type system is truly insufferable. | ||
| switch (type) { | ||
| case STRING: | ||
| case VALUE: | ||
| builder.putIdentifyingAttribute(key.getKey(), (String) makeValue(type, value)); | ||
| break; | ||
| case LONG: | ||
| builder.putIdentifyingAttribute(key.getKey(), (long) makeValue(type, value)); | ||
| break; | ||
| case DOUBLE: | ||
| builder.putIdentifyingAttribute(key.getKey(), (double) makeValue(type, value)); | ||
| break; | ||
| case BOOLEAN: | ||
| builder.putIdentifyingAttribute(key.getKey(), (boolean) makeValue(type, value)); | ||
| break; | ||
| case STRING_ARRAY: | ||
| builder.putIdentifyingAttribute(key.getKey(), (String[]) makeValue(type, value)); | ||
| break; | ||
| case LONG_ARRAY: | ||
| builder.putIdentifyingAttribute(key.getKey(), (long[]) makeValue(type, value)); | ||
| break; | ||
| case DOUBLE_ARRAY: | ||
| builder.putIdentifyingAttribute(key.getKey(), (double[]) makeValue(type, value)); | ||
| break; | ||
| case BOOLEAN_ARRAY: | ||
| builder.putIdentifyingAttribute(key.getKey(), (boolean[]) makeValue(type, value)); | ||
| break; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private Consumer<? super Map.Entry<AttributeKey<?>, Object>> putNonIdentifyingAttribute( | ||
| OpampClientBuilder builder) { | ||
| return entry -> { | ||
| AttributeKey<?> key = entry.getKey(); | ||
| Object value = entry.getValue(); | ||
| AttributeType type = key.getType(); | ||
|
|
||
| // The java type system is truly insufferable. | ||
| switch (type) { | ||
| case STRING: | ||
| case VALUE: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (String) makeValue(type, value)); | ||
| break; | ||
| case LONG: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (long) makeValue(type, value)); | ||
| break; | ||
| case DOUBLE: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (double) makeValue(type, value)); | ||
| break; | ||
| case BOOLEAN: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (boolean) makeValue(type, value)); | ||
| break; | ||
| case STRING_ARRAY: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (String[]) makeValue(type, value)); | ||
| break; | ||
| case LONG_ARRAY: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (long[]) makeValue(type, value)); | ||
| break; | ||
| case DOUBLE_ARRAY: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (double[]) makeValue(type, value)); | ||
| break; | ||
| case BOOLEAN_ARRAY: | ||
| builder.putNonIdentifyingAttribute(key.getKey(), (boolean[]) makeValue(type, value)); | ||
| break; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private Object makeValue(AttributeType attrType, Object value) { | ||
| // More java type insanity | ||
| switch (attrType) { | ||
| case STRING: | ||
| case LONG: | ||
| case DOUBLE: | ||
| case BOOLEAN: | ||
| return value; | ||
| case VALUE: | ||
| return value.toString(); | ||
| case STRING_ARRAY: | ||
| List<String> typedValueList = (List<String>) value; | ||
| return typedValueList.toArray(new String[] {}); | ||
| case LONG_ARRAY: | ||
| List<Long> longList = (List<Long>) value; | ||
| long[] longArray = new long[longList.size()]; | ||
| for (int i = 0; i < longList.size(); i++) { | ||
| longArray[i] = longList.get(i); | ||
| } | ||
| return longArray; | ||
| case DOUBLE_ARRAY: | ||
| List<Double> doubleList = (List<Double>) value; | ||
| double[] doubleArray = new double[doubleList.size()]; | ||
| for (int i = 0; i < doubleList.size(); i++) { | ||
| doubleArray[i] = doubleList.get(i); | ||
| } | ||
| return doubleArray; | ||
| case BOOLEAN_ARRAY: | ||
| List<Boolean> booleanList = (List<Boolean>) value; | ||
| boolean[] booleanArray = new boolean[booleanList.size()]; | ||
| for (int i = 0; i < booleanList.size(); i++) { | ||
| booleanArray[i] = booleanList.get(i); | ||
| } | ||
| return booleanArray; | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.