diff --git a/README.md b/README.md index 15148c3c7e..66b71ed837 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,11 @@ metadata: name: java-instrumentation spec: exporter: - endpoint: http://otel-collector:4318 + endpoint: http://otel-collector:4317 + propagators: + - tracecontext + - baggage + - b3 java: image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest # <1> EOF diff --git a/apis/instrumentation/v1alpha1/instrumentation_types.go b/apis/instrumentation/v1alpha1/instrumentation_types.go index c68737214a..0d5ec4bc5a 100644 --- a/apis/instrumentation/v1alpha1/instrumentation_types.go +++ b/apis/instrumentation/v1alpha1/instrumentation_types.go @@ -28,6 +28,11 @@ type InstrumentationSpec struct { // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true ResourceAttributes map[string]string `json:"resourceAttributes,omitempty"` + // Propagators defines inter-process context propagation configuration. + // +optional + // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true + Propagators []Propagator `json:"propagators,omitempty"` + // Java defines configuration for java auto-instrumentation. // +optional // +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true diff --git a/apis/instrumentation/v1alpha1/propagation.go b/apis/instrumentation/v1alpha1/propagation.go new file mode 100644 index 0000000000..ed759b442d --- /dev/null +++ b/apis/instrumentation/v1alpha1/propagation.go @@ -0,0 +1,40 @@ +// 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 v1alpha1 + +type ( + // Propagator represents the propagation type. + // +kubebuilder:validation:Enum=tracecontext;baggage;b3;b3multi;jaeger;xray;ottrace;no + Propagator string +) + +const ( + // TraceContext represents W3C Trace Context. + TraceContext Propagator = "tracecontext" + // Baggage represents W3C Baggage. + Baggage Propagator = "baggage" + // B3 represents B3 Single. + B3 Propagator = "b3" + // B3Multi represents B3 Multi. + B3Multi Propagator = "b3multi" + // Jaeger represents Jaeger. + Jaeger Propagator = "jaeger" + // XRay represents AWS X-Ray. + XRay Propagator = "xray" + // OTTrace represents OT Trace. + OTTrace Propagator = "ottrace" + // No represents automatically configured propagator. + None Propagator = "no" +) diff --git a/apis/instrumentation/v1alpha1/zz_generated.deepcopy.go b/apis/instrumentation/v1alpha1/zz_generated.deepcopy.go index 61a30ecfdd..bb28546a6e 100644 --- a/apis/instrumentation/v1alpha1/zz_generated.deepcopy.go +++ b/apis/instrumentation/v1alpha1/zz_generated.deepcopy.go @@ -108,6 +108,11 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { (*out)[key] = val } } + if in.Propagators != nil { + in, out := &in.Propagators, &out.Propagators + *out = make([]Propagator, len(*in)) + copy(*out, *in) + } out.Java = in.Java out.NodeJS = in.NodeJS } diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 137ef5439b..8bafc0dc33 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -33,11 +33,11 @@ metadata: containerImage: quay.io/opentelemetry/opentelemetry-operator createdAt: "2020-12-16T13:37:00+00:00" description: Provides the OpenTelemetry components, including the Collector - operators.operatorframework.io/builder: operator-sdk-v1.13.0+git + operators.operatorframework.io/builder: operator-sdk-v1.14.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v2 repository: github.com/open-telemetry/opentelemetry-operator support: OpenTelemetry Community - name: opentelemetry-operator.v0.38.0 + name: opentelemetry-operator.v0.33.0-71-ga302e31 namespace: placeholder spec: apiservicedefinitions: {} @@ -227,7 +227,7 @@ spec: - args: - --metrics-addr=127.0.0.1:8080 - --enable-leader-election - image: quay.io/opentelemetry/opentelemetry-operator:v0.38.0 + image: quay.io/aanuraag/opentelemetry-operator:v0.33.0-71-ga302e31 name: manager ports: - containerPort: 9443 @@ -319,7 +319,7 @@ spec: maturity: alpha provider: name: OpenTelemetry Community - version: 0.38.0 + version: 0.33.0-71-ga302e31 webhookdefinitions: - admissionReviewVersions: - v1 diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index b21be3d9a1..cc75190693 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -57,13 +57,22 @@ spec: description: Image is a container image with javaagent JAR. type: string type: object - nodejs: - description: NodeJS defines configuration for nodejs auto-instrumentation. - properties: - image: - description: Image is a container image with NodeJS SDK and autoinstrumentation. - type: string - type: object + propagators: + description: Propagators defines inter-process context propagation + configuration. + items: + description: Propagator represents the propagation type. + enum: + - tracecontext + - baggage + - b3 + - b3multi + - jaeger + - xray + - ottrace + - "no" + type: string + type: array resourceAttributes: additionalProperties: type: string diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 62e49a112a..1ce85f94ba 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -66,6 +66,22 @@ spec: description: Image is a container image with NodeJS SDK and autoinstrumentation. type: string type: object + propagators: + description: Propagators defines inter-process context propagation + configuration. + items: + description: Propagator represents the propagation type. + enum: + - tracecontext + - baggage + - b3 + - b3multi + - jaeger + - xray + - ottrace + - "no" + type: string + type: array resourceAttributes: additionalProperties: type: string diff --git a/pkg/instrumentation/sdk.go b/pkg/instrumentation/sdk.go index e81a265a6d..c39fdab20b 100644 --- a/pkg/instrumentation/sdk.go +++ b/pkg/instrumentation/sdk.go @@ -18,6 +18,7 @@ import ( "fmt" "sort" "strings" + "unsafe" "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" @@ -32,6 +33,7 @@ const ( envOTELServiceName = "OTEL_SERVICE_NAME" envOTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" envOTELResourceAttrs = "OTEL_RESOURCE_ATTRIBUTES" + envOTELPropagators = "OTEL_PROPAGATORS" ) // inject a new sidecar container to the given pod, based on the given OpenTelemetryCollector. @@ -89,6 +91,14 @@ func injectCommonSDKConfig(otelinst v1alpha1.Instrumentation, ns corev1.Namespac } container.Env[idx].Value += resStr } + idx = getIndexOfEnv(container.Env, envOTELPropagators) + if idx == -1 && len(otelinst.Spec.Propagators) > 0 { + propagators := *(*[]string)((unsafe.Pointer(&otelinst.Spec.Propagators))) + container.Env = append(container.Env, corev1.EnvVar{ + Name: envOTELPropagators, + Value: strings.Join(propagators, ","), + }) + } return pod } diff --git a/pkg/instrumentation/sdk_test.go b/pkg/instrumentation/sdk_test.go index 3e37d18102..15e96605ec 100644 --- a/pkg/instrumentation/sdk_test.go +++ b/pkg/instrumentation/sdk_test.go @@ -37,8 +37,9 @@ func TestSDKInjection(t *testing.T) { inst: v1alpha1.Instrumentation{ Spec: v1alpha1.InstrumentationSpec{ Exporter: v1alpha1.Exporter{ - Endpoint: "https://collector:4318", + Endpoint: "https://collector:4317", }, + Propagators: []v1alpha1.Propagator{"b3", "jaeger"}, }, }, pod: corev1.Pod{ @@ -70,12 +71,16 @@ func TestSDKInjection(t *testing.T) { }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "https://collector:4318", + Value: "https://collector:4317", }, { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "k8s.container.name=application-name,k8s.namespace.name=project1,k8s.pod.name=app", }, + { + Name: "OTEL_PROPAGATORS", + Value: "b3,jaeger", + }, }, }, }, @@ -87,11 +92,12 @@ func TestSDKInjection(t *testing.T) { inst: v1alpha1.Instrumentation{ Spec: v1alpha1.InstrumentationSpec{ Exporter: v1alpha1.Exporter{ - Endpoint: "https://collector:4318", + Endpoint: "https://collector:4317", }, ResourceAttributes: map[string]string{ "fromcr": "val", }, + Propagators: []v1alpha1.Propagator{"jaeger"}, }, }, pod: corev1.Pod{ @@ -115,6 +121,10 @@ func TestSDKInjection(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "foo=bar,k8s.container.name=other,", }, + { + Name: "OTEL_PROPAGATORS", + Value: "b3", + }, }, }, }, @@ -141,6 +151,10 @@ func TestSDKInjection(t *testing.T) { Name: "OTEL_RESOURCE_ATTRIBUTES", Value: "foo=bar,k8s.container.name=other,fromcr=val,k8s.namespace.name=project1,k8s.pod.name=app", }, + { + Name: "OTEL_PROPAGATORS", + Value: "b3", + }, }, }, }, @@ -164,7 +178,7 @@ func TestInjectJava(t *testing.T) { Image: "img:1", }, Exporter: v1alpha1.Exporter{ - Endpoint: "https://collector:4318", + Endpoint: "https://collector:4317", }, }, } @@ -219,7 +233,7 @@ func TestInjectJava(t *testing.T) { }, { Name: "OTEL_EXPORTER_OTLP_ENDPOINT", - Value: "https://collector:4318", + Value: "https://collector:4317", }, { Name: "OTEL_RESOURCE_ATTRIBUTES", diff --git a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml index 2235a3a1ce..48091c25ed 100644 --- a/tests/e2e/instrumentation-java/00-install-instrumentation.yaml +++ b/tests/e2e/instrumentation-java/00-install-instrumentation.yaml @@ -4,6 +4,9 @@ metadata: name: java spec: exporter: - endpoint: http://localhost:4318 + endpoint: http://localhost:4317 + propagators: + - jaeger + - b3 java: image: ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:latest diff --git a/tests/e2e/instrumentation-java/01-assert.yaml b/tests/e2e/instrumentation-java/01-assert.yaml index fc10dfe54a..7049893072 100644 --- a/tests/e2e/instrumentation-java/01-assert.yaml +++ b/tests/e2e/instrumentation-java/01-assert.yaml @@ -13,8 +13,10 @@ spec: - name: OTEL_SERVICE_NAME value: myapp - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4318 + value: http://localhost:4317 - name: OTEL_RESOURCE_ATTRIBUTES + - name: OTEL_PROPAGATORS + value: jaeger,b3 - name: JAVA_TOOL_OPTIONS value: " -javaagent:/otel-auto-instrumentation/javaagent.jar" volumeMounts: