-
Notifications
You must be signed in to change notification settings - Fork 452
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
Add autoinstrumentation of NodeJS #507
Merged
jpkrohling
merged 20 commits into
open-telemetry:main
from
anuraaga:nodejs-autoinstrumentatioon
Nov 10, 2021
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ba0bede
Add autoinstrumentation of NodeJS
8a3770a
Drift
c54a5bc
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
ae74544
Switch to single annotation
3c5c95e
Fix merge
21d5433
Fix
9b7a81e
Hurts
b0239d6
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
7cc5182
Format
fb23588
Revert autogen
a302e31
Drift
1bbe523
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
293a8e0
Revert autogen
b02d1d9
autogen
0b72fa3
Drift
50785ae
Add doc
cff5521
e2e
d063917
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operat…
d51b0aa
Less doc
b4b8cbb
Cleanup
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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,68 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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 instrumentation | ||
|
||
import ( | ||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/open-telemetry/opentelemetry-operator/apis/instrumentation/v1alpha1" | ||
) | ||
|
||
const ( | ||
envNodeOptions = "NODE_OPTIONS" | ||
nodeRequireArgument = " --require /otel-auto-instrumentation/autoinstrumentation.js" | ||
) | ||
|
||
func injectNodeJSSDK(logger logr.Logger, nodeJSSpec v1alpha1.NodeJSSpec, pod corev1.Pod) corev1.Pod { | ||
// caller checks if there is at least one container | ||
container := &pod.Spec.Containers[0] | ||
idx := getIndexOfEnv(container.Env, envNodeOptions) | ||
if idx == -1 { | ||
container.Env = append(container.Env, corev1.EnvVar{ | ||
Name: envNodeOptions, | ||
Value: nodeRequireArgument, | ||
}) | ||
} else if idx > -1 { | ||
if container.Env[idx].ValueFrom != nil { | ||
// TODO add to status object or submit it as an event | ||
logger.Info("Skipping NodeJS SDK injection, the container defines NODE_OPTIONS env var value via ValueFrom", "container", container.Name) | ||
return pod | ||
} | ||
container.Env[idx].Value = container.Env[idx].Value + nodeRequireArgument | ||
} | ||
container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ | ||
Name: volumeName, | ||
MountPath: "/otel-auto-instrumentation", | ||
}) | ||
|
||
pod.Spec.Volumes = append(pod.Spec.Volumes, corev1.Volume{ | ||
Name: volumeName, | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}}) | ||
|
||
pod.Spec.InitContainers = append(pod.Spec.InitContainers, corev1.Container{ | ||
Name: initContainerName, | ||
Image: nodeJSSpec.Image, | ||
Command: []string{"cp", "-a", "/autoinstrumentation/.", "/otel-auto-instrumentation/"}, | ||
VolumeMounts: []corev1.VolumeMount{{ | ||
Name: volumeName, | ||
MountPath: "/otel-auto-instrumentation", | ||
}}, | ||
}) | ||
|
||
return pod | ||
} |
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.
can you explain the intentions for changing this annotation?
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 I'm happy to split out the annotation change if it makes sense.
I found our current, SDK-agnostic (?) sdk.go uses this Java annotation. I need it to be able to support multiple languages and came up with this change. Any idea that could work better?
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.
Could you please explain why we need two annotations?
We can have
"instrumentation.opentelemetry.io/inject-java"
,"instrumentation.opentelemetry.io/inject-node"
and then `"instrumentation.opentelemetry.io/inject" - to just inject the basic configuration (users could use the operator as a control plane to manage instrumentations).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 don't think we want to allow multiple languages on the same pod as that shouldn't ever be a use case I think. While we could check the annotations and fail if there are multiple this split seemed to model more directly that only one language can be injected.
I made language required without thinking too much but could definitely remove that to allow the control plane only injection if this otherwise makes sense.
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 don't see much value of limiting it to only a single language, quite the opposite.
What I don't like is to have two annotations from the UX perspective.
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 believe these sort of annotations are always copy-pasted or frameworked, so I don't think there is a usability difference between the two patterns. If we think there is a use case for multiple annotations, then it makes sense but for example having both
otel.inject=true
andotel.inject-java=true
on the same pod would be redundant and I think that leads to some cognitive dissonance.Great to hear everyone's ideas on the matter :)
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.
Discussed with @pavolloffay offline and for now sticking to the current annotation format, but we'll need to address it soon. We can see the awkwardness here
https://github.com/open-telemetry/opentelemetry-operator/pull/507/files#diff-92f790ce871022e5e7de195a2f96235dac6ac3fb04337974f8584c7c020a67cbR48
where common config can be injected from different instrumentations in a surprising way. Having separate annotations for the instrumentation config and what languages to use in the future will hopefully solve that.
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.
+1 let's discuss it in a separate issue. maybe there are other ways we can mitigate the issue