Skip to content
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

Skip .NET auto-instrumentation if OTEL_DOTNET_AUTO_HOME env var is already set #1177

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
34127db
skips env var injection and sdk configurations if agent injection is …
avadhut123pisal Oct 5, 2022
134c44e
mutate container at the last of SDK injection step
avadhut123pisal Oct 5, 2022
928b2e0
Merge branch 'main' of github.com:avadhut123pisal/opentelemetry-opera…
avadhut123pisal Oct 8, 2022
ff8d0e3
validate first and then mutate the container with env variables
avadhut123pisal Oct 8, 2022
2a6569c
fixes go lint issues
avadhut123pisal Oct 8, 2022
0b2fce7
incorporates review comments
avadhut123pisal Oct 10, 2022
d703287
fixes go lint issue
avadhut123pisal Oct 10, 2022
cea2e0d
Merge branch 'main' into prevent-incomplete-auto-instrumentation
avadhut123pisal Oct 10, 2022
2710133
removes return statement in case of failed instrumentation
avadhut123pisal Oct 12, 2022
400fc2a
Merge branch 'prevent-incomplete-auto-instrumentation' of github.com:…
avadhut123pisal Oct 12, 2022
04d4b57
Merge branch 'main' of github.com:avadhut123pisal/opentelemetry-opera…
avadhut123pisal Oct 15, 2022
3faad7c
skips auto-instrumentation if OTEL_DOTNET_AUTO_HOME is already set
avadhut123pisal Oct 15, 2022
306e1be
use errors.New() to get the error object
avadhut123pisal Oct 17, 2022
e405425
use errors.New() to get the error object
avadhut123pisal Oct 17, 2022
ee33528
replaces fmt.Errorf with error.New
avadhut123pisal Oct 17, 2022
3e036f4
Merge branch 'skip-instrumentation-if-otel-dotnet-auto-home-set' of g…
avadhut123pisal Oct 17, 2022
88caa92
Merge branch 'main' of github.com:avadhut123pisal/opentelemetry-opera…
avadhut123pisal Oct 19, 2022
906f746
Merge branch 'main' of github.com:avadhut123pisal/opentelemetry-opera…
avadhut123pisal Oct 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/instrumentation/dotnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package instrumentation

import (
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -49,6 +50,18 @@ func injectDotNetSDK(dotNetSpec v1alpha1.DotNet, pod corev1.Pod, index int) (cor
return pod, err
}

// check if OTEL_DOTNET_AUTO_HOME env var is already set in the container
// if it is already set, then we assume that .NET Auto-instrumentation is already configured for this container
if getIndexOfEnv(container.Env, envDotNetOTelAutoHome) > -1 {
return pod, errors.New("OTEL_DOTNET_AUTO_HOME environment variable is already set in the container")
}

// check if OTEL_DOTNET_AUTO_HOME env var is already set in the .NET instrumentatiom spec
// if it is already set, then we assume that .NET Auto-instrumentation is already configured for this container
if getIndexOfEnv(dotNetSpec.Env, envDotNetOTelAutoHome) > -1 {
return pod, errors.New("OTEL_DOTNET_AUTO_HOME environment variable is already set in the .NET instrumentation spec")
}

// inject .NET instrumentation spec env vars.
for _, env := range dotNetSpec.Env {
idx := getIndexOfEnv(container.Env, env.Name)
Expand Down
60 changes: 54 additions & 6 deletions pkg/instrumentation/dotnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestInjectDotNetSDK(t *testing.T) {
err: nil,
},
{
name: "CORECLR_ENABLE_PROFILING, CORECLR_PROFILER, CORECLR_PROFILER_PATH, DOTNET_STARTUP_HOOKS, DOTNET_ADDITIONAL_DEPS, DOTNET_SHARED_STORE, OTEL_DOTNET_AUTO_HOME defined",
name: "CORECLR_ENABLE_PROFILING, CORECLR_PROFILER, CORECLR_PROFILER_PATH, DOTNET_STARTUP_HOOKS, DOTNET_ADDITIONAL_DEPS, DOTNET_SHARED_STORE defined",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1"},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -139,10 +139,6 @@ func TestInjectDotNetSDK(t *testing.T) {
Name: envDotNetSharedStore,
Value: "/foo:/bar",
},
{
Name: envDotNetOTelAutoHome,
Value: "/foo:/bar",
},
},
},
},
Expand Down Expand Up @@ -204,7 +200,7 @@ func TestInjectDotNetSDK(t *testing.T) {
},
{
Name: envDotNetOTelAutoHome,
Value: "/foo:/bar",
Value: dotNetOTelAutoHomePath,
},
},
},
Expand Down Expand Up @@ -312,6 +308,58 @@ func TestInjectDotNetSDK(t *testing.T) {
},
err: fmt.Errorf("the container defines env var value via ValueFrom, envVar: %s", envDotNetSharedStore),
},
{
name: "OTEL_DOTNET_AUTO_HOME already set in the container",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1"},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Env: []corev1.EnvVar{
{
Name: envDotNetOTelAutoHome,
Value: "/otel-dotnet-auto",
},
},
},
},
},
},
expected: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Env: []corev1.EnvVar{
{
Name: envDotNetOTelAutoHome,
Value: "/otel-dotnet-auto",
},
},
},
},
},
},
err: fmt.Errorf("OTEL_DOTNET_AUTO_HOME environment variable is already set in the container"),
},
{
name: "OTEL_DOTNET_AUTO_HOME already set in the .NET instrumentation spec",
DotNet: v1alpha1.DotNet{Image: "foo/bar:1", Env: []corev1.EnvVar{{Name: envDotNetOTelAutoHome, Value: dotNetOTelAutoHomePath}}},
pod: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
},
expected: corev1.Pod{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{},
},
},
},
err: fmt.Errorf("OTEL_DOTNET_AUTO_HOME environment variable is already set in the .NET instrumentation spec"),
},
}

for _, test := range tests {
Expand Down
1 change: 1 addition & 0 deletions pkg/instrumentation/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func TestInjectPythonSDK(t *testing.T) {
},
},
},
err: nil,
},
{
name: "OTEL_METRICS_EXPORTER defined",
Expand Down