Skip to content

Commit 220650b

Browse files
committed
fix rebase
1 parent 8e11cb4 commit 220650b

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

pkg/instrumentation/sdk_test.go

+114
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,120 @@ func TestSDKInjection(t *testing.T) {
658658
},
659659
},
660660
},
661+
{
662+
name: "Resource attribute propagate",
663+
inst: v1alpha1.Instrumentation{
664+
Spec: v1alpha1.InstrumentationSpec{
665+
Exporter: v1alpha1.Exporter{
666+
Endpoint: "https://collector:4317",
667+
},
668+
Resource: v1alpha1.Resource{
669+
Attributes: map[string]string{
670+
"fromcr": "val",
671+
},
672+
},
673+
Propagators: []v1alpha1.Propagator{"jaeger"},
674+
Sampler: v1alpha1.Sampler{
675+
Type: "parentbased_traceidratio",
676+
Argument: "0.25",
677+
},
678+
},
679+
},
680+
pod: corev1.Pod{
681+
ObjectMeta: metav1.ObjectMeta{
682+
Annotations: map[string]string{
683+
"resource.opentelemetry.io/fromtest": "val",
684+
"resource.opentelemetry.io/foo": "test",
685+
},
686+
Namespace: "project1",
687+
Name: "app",
688+
},
689+
Spec: corev1.PodSpec{
690+
Containers: []corev1.Container{
691+
{
692+
Image: "app:latest",
693+
Env: []corev1.EnvVar{
694+
{
695+
Name: "OTEL_SERVICE_NAME",
696+
Value: "explicitly_set",
697+
},
698+
{
699+
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
700+
Value: "explicitly_set",
701+
},
702+
{
703+
Name: "OTEL_PROPAGATORS",
704+
Value: "b3",
705+
},
706+
{
707+
Name: "OTEL_TRACES_SAMPLER",
708+
Value: "always_on",
709+
},
710+
{
711+
Name: "OTEL_RESOURCE_ATTRIBUTES",
712+
Value: "foo=bar,k8s.container.name=other,service.version=explicitly_set,",
713+
},
714+
},
715+
},
716+
},
717+
},
718+
},
719+
expected: corev1.Pod{
720+
ObjectMeta: metav1.ObjectMeta{
721+
Namespace: "project1",
722+
Name: "app",
723+
Annotations: map[string]string{
724+
"resource.opentelemetry.io/fromtest": "val",
725+
"resource.opentelemetry.io/foo": "test",
726+
},
727+
},
728+
Spec: corev1.PodSpec{
729+
Containers: []corev1.Container{
730+
{
731+
Image: "app:latest",
732+
Env: []corev1.EnvVar{
733+
{
734+
Name: "OTEL_SERVICE_NAME",
735+
Value: "explicitly_set",
736+
},
737+
{
738+
Name: "OTEL_EXPORTER_OTLP_ENDPOINT",
739+
Value: "explicitly_set",
740+
},
741+
{
742+
Name: "OTEL_PROPAGATORS",
743+
Value: "b3",
744+
},
745+
{
746+
Name: "OTEL_TRACES_SAMPLER",
747+
Value: "always_on",
748+
},
749+
{
750+
Name: "OTEL_RESOURCE_ATTRIBUTES_POD_NAME",
751+
ValueFrom: &corev1.EnvVarSource{
752+
FieldRef: &corev1.ObjectFieldSelector{
753+
FieldPath: "metadata.name",
754+
},
755+
},
756+
},
757+
{
758+
Name: "OTEL_RESOURCE_ATTRIBUTES_NODE_NAME",
759+
ValueFrom: &corev1.EnvVarSource{
760+
FieldRef: &corev1.ObjectFieldSelector{
761+
FieldPath: "spec.nodeName",
762+
},
763+
},
764+
},
765+
{
766+
Name: "OTEL_RESOURCE_ATTRIBUTES",
767+
Value: "foo=bar,k8s.container.name=other,service.version=explicitly_set,fromcr=val,fromtest=val,k8s.namespace.name=project1,k8s.node.name=$(OTEL_RESOURCE_ATTRIBUTES_NODE_NAME),k8s.pod.name=$(OTEL_RESOURCE_ATTRIBUTES_POD_NAME)",
768+
},
769+
},
770+
},
771+
},
772+
},
773+
},
774+
},
661775
}
662776

663777
for _, test := range tests {

0 commit comments

Comments
 (0)