Repository: istio/istio
File: pilot/pkg/networking/core/v1alpha3/tracing.go (Go)

Code before:
				Uri: te,
				HttpUpstreamType: &core.HttpUri_Cluster{
					Cluster: cluster,
				},
				Timeout: httpService.GetTimeout(),
			},
		}
		for _, h := range httpService.GetHeaders() {
			hvo := &core.HeaderValueOption{
				AppendAction: core.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD,
				Header: &core.HeaderValue{
					Key:   h.GetName(),
					Value: h.GetValue(),
				},
			}
			oc.GetHttpService().RequestHeadersToAdd = append(oc.GetHttpService().GetRequestHeadersToAdd(), hvo)
		}
	}

	// Add configured resource detectors
	if otelProvider.ResourceDetectors != nil {
		res := []*core.TypedExtensionConfig{}
		rd := otelProvider.ResourceDetectors

		if rd.Environment != nil {
			res = append(res, &core.TypedExtensionConfig{
				Name:        "envoy.tracers.opentelemetry.resource_detectors.environment",
				TypedConfig: protoconv.MessageToAny(&resourcedetectors.EnvironmentResourceDetectorConfig{}),
			})
		}
		if rd.Dynatrace != nil {
			res = append(res, &core.TypedExtensionConfig{
				Name:        "envoy.tracers.opentelemetry.resource_detectors.dynatrace",
				TypedConfig: protoconv.MessageToAny(&resourcedetectors.DynatraceResourceDetectorConfig{}),
			})
		}
		oc.ResourceDetectors = res
	}

	return anypb.New(oc)
}

func opencensusConfig(opencensusProvider *meshconfig.MeshConfig_ExtensionProvider_OpenCensusAgentTracingProvider) (*anypb.Any, error) {
	oc := &tracingcfg.OpenCensusConfig{
		OcagentAddress:         fmt.Sprintf("%s:%d", opencensusProvider.GetService(), opencensusProvider.GetPort()),
		OcagentExporterEnabled: true,
		// this is incredibly dangerous for proxy stability, as switching provider config for OC providers
		// is not allowed during the lifetime of a proxy.
		IncomingTraceContext: convert(opencensusProvider.GetContext()),
		OutgoingTraceContext: convert(opencensusProvider.GetContext()),
	}

Review comment (performance):
can you add to `pilot/pkg/xds/filters/filters.go`? This is, surprisingly, expensive to compute each time

Code after:
				Uri: te,
				HttpUpstreamType: &core.HttpUri_Cluster{
					Cluster: cluster,
				},
				Timeout: httpService.GetTimeout(),
			},
		}
		for _, h := range httpService.GetHeaders() {
			hvo := &core.HeaderValueOption{
				AppendAction: core.HeaderValueOption_OVERWRITE_IF_EXISTS_OR_ADD,
				Header: &core.HeaderValue{
					Key:   h.GetName(),
					Value: h.GetValue(),
				},
			}
			oc.GetHttpService().RequestHeadersToAdd = append(oc.GetHttpService().GetRequestHeadersToAdd(), hvo)
		}
	}

	// Add configured resource detectors
	if otelProvider.ResourceDetectors != nil {
		res := []*core.TypedExtensionConfig{}
		rd := otelProvider.ResourceDetectors

		if rd.Environment != nil {
			res = append(res, xdsfilters.EnvironmentResourceDetector)
		}
		if rd.Dynatrace != nil {
			res = append(res, xdsfilters.DynatraceResourceDetector)
		}
		oc.ResourceDetectors = res
	}

	return anypb.New(oc)
}

func opencensusConfig(opencensusProvider *meshconfig.MeshConfig_ExtensionProvider_OpenCensusAgentTracingProvider) (*anypb.Any, error) {
	oc := &tracingcfg.OpenCensusConfig{
		OcagentAddress:         fmt.Sprintf("%s:%d", opencensusProvider.GetService(), opencensusProvider.GetPort()),
		OcagentExporterEnabled: true,
		// this is incredibly dangerous for proxy stability, as switching provider config for OC providers
		// is not allowed during the lifetime of a proxy.
		IncomingTraceContext: convert(opencensusProvider.GetContext()),
		OutgoingTraceContext: convert(opencensusProvider.GetContext()),
	}

	return protoconv.MessageToAnyWithError(oc)
}

func stackdriverConfig(proxyMetaData *model.NodeMetadata, sdProvider *meshconfig.MeshConfig_ExtensionProvider_StackdriverProvider) (*anypb.Any, error) {
	proj, ok := proxyMetaData.PlatformMetadata[platform.GCPProject]