-
Notifications
You must be signed in to change notification settings - Fork 893
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
Allow adding multiple ContextStore fields to one key class, part 1 #4067
Merged
trask
merged 1 commit into
open-telemetry:main
from
mateuszrzeszutek:contextStore-pairs-1
Sep 9, 2021
Merged
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions
32
...a/io/opentelemetry/javaagent/extension/instrumentation/InstrumentationContextBuilder.java
This file contains 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,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.extension.instrumentation; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.api.ContextStore; | ||
import io.opentelemetry.javaagent.instrumentation.api.InstrumentationContext; | ||
|
||
/** | ||
* This interface allows registering {@link ContextStore} class pairs. | ||
* | ||
* <p>This interface should not be implemented by the javaagent extension developer - the javaagent | ||
* will provide the implementation of all transformations described here. | ||
*/ | ||
public interface InstrumentationContextBuilder { | ||
|
||
/** | ||
* Register the association between the {@code keyClassName} and the {@code contextClassName}. | ||
* Class pairs registered using this method will be available as {@link ContextStore}s in the | ||
* runtime; obtainable by calling {@link InstrumentationContext#get(Class, Class)}. | ||
* | ||
* @param keyClassName The name of the class that an instance of class named {@code | ||
* contextClassName} will be attached to. | ||
* @param contextClassName The instrumentation context class name. | ||
* @return {@code this}. | ||
* @see InstrumentationContext | ||
* @see ContextStore | ||
*/ | ||
InstrumentationContextBuilder register(String keyClassName, String contextClassName); | ||
} |
This file contains 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 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
35 changes: 35 additions & 0 deletions
35
...ooling/src/main/java/io/opentelemetry/javaagent/tooling/context/ContextStoreMappings.java
This file contains 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,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.context; | ||
|
||
import java.util.AbstractMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class ContextStoreMappings { | ||
private final Set<Map.Entry<String, String>> entrySet; | ||
|
||
public ContextStoreMappings(Set<Map.Entry<String, String>> entrySet) { | ||
this.entrySet = entrySet; | ||
} | ||
|
||
public int size() { | ||
return entrySet.size(); | ||
} | ||
|
||
public boolean isEmpty() { | ||
return entrySet.isEmpty(); | ||
} | ||
|
||
public boolean hasMapping(String keyClassName, String contextClassName) { | ||
return entrySet.contains( | ||
new AbstractMap.SimpleImmutableEntry<>(keyClassName, contextClassName)); | ||
} | ||
|
||
public Set<Map.Entry<String, String>> entrySet() { | ||
return entrySet; | ||
} | ||
} |
This file contains 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
26 changes: 26 additions & 0 deletions
26
...in/java/io/opentelemetry/javaagent/tooling/context/InstrumentationContextBuilderImpl.java
This file contains 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,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.tooling.context; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationContextBuilder; | ||
import java.util.AbstractMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class InstrumentationContextBuilderImpl implements InstrumentationContextBuilder { | ||
private final Set<Map.Entry<String, String>> entrySet = new HashSet<>(); | ||
|
||
@Override | ||
public InstrumentationContextBuilder register(String keyClassName, String contextClassName) { | ||
entrySet.add(new AbstractMap.SimpleImmutableEntry<>(keyClassName, contextClassName)); | ||
return this; | ||
} | ||
|
||
public ContextStoreMappings build() { | ||
return new ContextStoreMappings(entrySet); | ||
} | ||
} |
This file contains 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
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.
i didn't know about this public Map.Entry implementation!
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 just learned about it yesterday too 😄