-
Notifications
You must be signed in to change notification settings - Fork 484
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
Instrumentations support Java extensions #2761
Changes from all commits
6727627
924d6e3
3214fef
f55949d
e0a2323
3aa23db
eb7ec74
a4fed6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) | ||
component: auto-instrumentation | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Support Java auto-instrumentation extensions. | ||
|
||
# One or more tracking issues related to the change | ||
issues: [1785] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,19 @@ type Java struct { | |
// Resources describes the compute resource requirements. | ||
// +optional | ||
Resources corev1.ResourceRequirements `json:"resources,omitempty"` | ||
|
||
// Extensions defines java specific extensions. | ||
// All extensions are copied to a single directory; if a JAR with the same name exists, it will be overwritten. | ||
// +optional | ||
Extensions []Extensions `json:"extensions,omitempty"` | ||
} | ||
|
||
type Extensions struct { | ||
// Image is a container image with extensions auto-instrumentation JAR. | ||
Image string `json:"image"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the extension needs to be rebuild for every java agent version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's necessary; the user just needs to package based on the javaagent version he's using. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some open source extensions, maybe it should provide a compatibility list for javaagent. |
||
|
||
// Dir is a directory with extensions auto-instrumentation JAR. | ||
Dir string `json:"dir"` | ||
} | ||
|
||
// NodeJS defines NodeJS SDK and instrumentation configuration. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,16 @@ | |
package instrumentation | ||
|
||
import ( | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
) | ||
|
||
const ( | ||
envJavaToolsOptions = "JAVA_TOOL_OPTIONS" | ||
javaJVMArgument = " -javaagent:/otel-auto-instrumentation-java/javaagent.jar" | ||
javaAgent = " -javaagent:/otel-auto-instrumentation-java/javaagent.jar" | ||
javaInitContainerName = initContainerName + "-java" | ||
javaVolumeName = volumeName + "-java" | ||
javaInstrMountPath = "/otel-auto-instrumentation-java" | ||
|
@@ -45,6 +47,11 @@ func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1. | |
} | ||
} | ||
|
||
javaJVMArgument := javaAgent | ||
if len(javaSpec.Extensions) > 0 { | ||
javaJVMArgument = javaAgent + fmt.Sprintf(" -Dotel.javaagent.extensions=%s/extensions", javaInstrMountPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://opentelemetry.io/docs/languages/java/automatic/configuration/#extensions If all extensions are copied to the same directory it can cause overrides. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm not sure what the confusion is here. I think the user should make sure that the jars in the |
||
} | ||
|
||
idx := getIndexOfEnv(container.Env, envJavaToolsOptions) | ||
if idx == -1 { | ||
container.Env = append(container.Env, corev1.EnvVar{ | ||
|
@@ -80,6 +87,20 @@ func injectJavaagent(javaSpec v1alpha1.Java, pod corev1.Pod, index int) (corev1. | |
MountPath: javaInstrMountPath, | ||
}}, | ||
}) | ||
|
||
for i, extension := range javaSpec.Extensions { | ||
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ | ||
Name: initContainerName + fmt.Sprintf("-extension-%d", i), | ||
Image: extension.Image, | ||
Command: []string{"cp", "-r", extension.Dir + "/.", javaInstrMountPath + "/extensions"}, | ||
Resources: javaSpec.Resources, | ||
VolumeMounts: []corev1.VolumeMount{{ | ||
Name: javaVolumeName, | ||
MountPath: javaInstrMountPath, | ||
}}, | ||
}) | ||
} | ||
|
||
} | ||
return pod, err | ||
} |
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.
@crossoverJie all extensions are copied to a single directory, therefore we should document it because one extension can override another one.
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 have added related documents.