diff --git a/pkg/networkservice/core/chain/client.go b/pkg/networkservice/core/chain/client.go index c3fa4424f..59a1e77b6 100644 --- a/pkg/networkservice/core/chain/client.go +++ b/pkg/networkservice/core/chain/client.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco Systems, Inc. -// // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2024 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,11 +23,15 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" + "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" ) // NewNetworkServiceClient - chains together a list of networkservice.NetworkServiceClient with tracing func NewNetworkServiceClient(clients ...networkservice.NetworkServiceClient) networkservice.NetworkServiceClient { - return next.NewNetworkServiceClient( - next.NewWrappedNetworkServiceClient(trace.NewNetworkServiceClient, clients...), - ) + if opentelemetry.IsEnabled() { + return next.NewNetworkServiceClient( + next.NewWrappedNetworkServiceClient(trace.NewNetworkServiceClient, clients...), + ) + } + return next.NewNetworkServiceClient(clients...) } diff --git a/pkg/networkservice/core/chain/server.go b/pkg/networkservice/core/chain/server.go index 3fc07f232..f42cc439c 100644 --- a/pkg/networkservice/core/chain/server.go +++ b/pkg/networkservice/core/chain/server.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020 Cisco Systems, Inc. -// // Copyright (c) 2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2024 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,11 +25,15 @@ import ( "github.com/networkservicemesh/sdk/pkg/networkservice/core/next" "github.com/networkservicemesh/sdk/pkg/networkservice/core/trace" + "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" ) // NewNetworkServiceServer - chains together a list of networkservice.Servers with tracing func NewNetworkServiceServer(servers ...networkservice.NetworkServiceServer) networkservice.NetworkServiceServer { - return next.NewNetworkServiceServer( - next.NewWrappedNetworkServiceServer(trace.NewNetworkServiceServer, servers...), - ) + if opentelemetry.IsEnabled() { + return next.NewNetworkServiceServer( + next.NewWrappedNetworkServiceServer(trace.NewNetworkServiceServer, servers...), + ) + } + return next.NewNetworkServiceServer(servers...) } diff --git a/pkg/networkservice/core/trace/traceconcise/common_test.go b/pkg/networkservice/core/trace/traceconcise/common_test.go index 8007d75c1..ae76b4168 100644 --- a/pkg/networkservice/core/trace/traceconcise/common_test.go +++ b/pkg/networkservice/core/trace/traceconcise/common_test.go @@ -22,6 +22,7 @@ package traceconcise_test import ( "bytes" "context" + "os" "testing" "github.com/sirupsen/logrus" @@ -34,6 +35,7 @@ import ( ) func TestOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") // Configure logging // Set output to buffer var buff bytes.Buffer @@ -76,6 +78,7 @@ func TestOutput(t *testing.T) { } func TestErrorOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") // Configure logging // Set output to buffer var buff bytes.Buffer diff --git a/pkg/networkservice/core/trace/traceverbose/common_test.go b/pkg/networkservice/core/trace/traceverbose/common_test.go index f31404ea0..62e8d11da 100644 --- a/pkg/networkservice/core/trace/traceverbose/common_test.go +++ b/pkg/networkservice/core/trace/traceverbose/common_test.go @@ -25,6 +25,7 @@ import ( "bytes" "context" "encoding/json" + "os" "testing" @@ -104,6 +105,7 @@ func TestDiffPathAdd(t *testing.T) { } func TestTraceOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") // Configure logging // Set output to buffer var buff bytes.Buffer @@ -159,6 +161,7 @@ func TestTraceOutput(t *testing.T) { } func TestErrorOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") // Configure logging // Set output to buffer var buff bytes.Buffer diff --git a/pkg/registry/core/chain/ns_registry.go b/pkg/registry/core/chain/ns_registry.go index 1ef62c804..a2f51b52e 100644 --- a/pkg/registry/core/chain/ns_registry.go +++ b/pkg/registry/core/chain/ns_registry.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2023 Cisco Systems, Inc. -// // Copyright (c) 2020-2023 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2024 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,14 +23,21 @@ import ( "github.com/networkservicemesh/sdk/pkg/registry/core/next" "github.com/networkservicemesh/sdk/pkg/registry/core/trace" + "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" ) // NewNetworkServiceRegistryServer - creates a chain of servers func NewNetworkServiceRegistryServer(servers ...registry.NetworkServiceRegistryServer) registry.NetworkServiceRegistryServer { - return next.NewWrappedNetworkServiceRegistryServer(trace.NewNetworkServiceRegistryServer, servers...) + if opentelemetry.IsEnabled() { + return next.NewWrappedNetworkServiceRegistryServer(trace.NewNetworkServiceRegistryServer, servers...) + } + return next.NewNetworkServiceRegistryServer(servers...) } // NewNetworkServiceRegistryClient - creates a chain of clients func NewNetworkServiceRegistryClient(clients ...registry.NetworkServiceRegistryClient) registry.NetworkServiceRegistryClient { - return next.NewWrappedNetworkServiceRegistryClient(trace.NewNetworkServiceRegistryClient, clients...) + if opentelemetry.IsEnabled() { + return next.NewWrappedNetworkServiceRegistryClient(trace.NewNetworkServiceRegistryClient, clients...) + } + return next.NewNetworkServiceRegistryClient(clients...) } diff --git a/pkg/registry/core/chain/nse_registry.go b/pkg/registry/core/chain/nse_registry.go index 09a191b84..e6d03fcce 100644 --- a/pkg/registry/core/chain/nse_registry.go +++ b/pkg/registry/core/chain/nse_registry.go @@ -1,7 +1,7 @@ -// Copyright (c) 2020-2023 Cisco Systems, Inc. -// // Copyright (c) 2020-2023 Doc.ai and/or its affiliates. // +// Copyright (c) 2020-2024 Cisco Systems, Inc. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,14 +24,21 @@ import ( "github.com/networkservicemesh/sdk/pkg/registry/core/next" "github.com/networkservicemesh/sdk/pkg/registry/core/trace" + "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" ) // NewNetworkServiceEndpointRegistryServer - creates a chain of servers func NewNetworkServiceEndpointRegistryServer(servers ...registry.NetworkServiceEndpointRegistryServer) registry.NetworkServiceEndpointRegistryServer { - return next.NewWrappedNetworkServiceEndpointRegistryServer(trace.NewNetworkServiceEndpointRegistryServer, servers...) + if opentelemetry.IsEnabled() { + return next.NewWrappedNetworkServiceEndpointRegistryServer(trace.NewNetworkServiceEndpointRegistryServer, servers...) + } + return next.NewNetworkServiceEndpointRegistryServer(servers...) } // NewNetworkServiceEndpointRegistryClient - creates a chain of clients func NewNetworkServiceEndpointRegistryClient(clients ...registry.NetworkServiceEndpointRegistryClient) registry.NetworkServiceEndpointRegistryClient { - return next.NewWrappedNetworkServiceEndpointRegistryClient(trace.NewNetworkServiceEndpointRegistryClient, clients...) + if opentelemetry.IsEnabled() { + return next.NewWrappedNetworkServiceEndpointRegistryClient(trace.NewNetworkServiceEndpointRegistryClient, clients...) + } + return next.NewNetworkServiceEndpointRegistryClient(clients...) } diff --git a/pkg/registry/core/trace/traceconcise/traceconcise_test.go b/pkg/registry/core/trace/traceconcise/traceconcise_test.go index 263198ef6..394d43f62 100644 --- a/pkg/registry/core/trace/traceconcise/traceconcise_test.go +++ b/pkg/registry/core/trace/traceconcise/traceconcise_test.go @@ -22,6 +22,7 @@ package traceconcise_test import ( "bytes" "context" + "os" "testing" "github.com/networkservicemesh/api/pkg/api/registry" @@ -41,6 +42,7 @@ import ( ) func TestOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") t.Cleanup(func() { goleak.VerifyNone(t) }) var buff bytes.Buffer @@ -89,6 +91,7 @@ func TestOutput(t *testing.T) { } func TestErrorOutput(t *testing.T) { + _ = os.Setenv("TELEMETRY", "true") t.Cleanup(func() { goleak.VerifyNone(t) }) var buff bytes.Buffer diff --git a/pkg/tools/dnsutils/chain/server.go b/pkg/tools/dnsutils/chain/server.go index 9e8395fbf..ee284b2a1 100644 --- a/pkg/tools/dnsutils/chain/server.go +++ b/pkg/tools/dnsutils/chain/server.go @@ -1,4 +1,4 @@ -// Copyright (c) 2022 Cisco Systems, Inc. +// Copyright (c) 2022-2024 Cisco Systems, Inc. // // SPDX-License-Identifier: Apache-2.0 // @@ -21,11 +21,15 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/dnsutils" "github.com/networkservicemesh/sdk/pkg/tools/dnsutils/next" "github.com/networkservicemesh/sdk/pkg/tools/dnsutils/trace" + "github.com/networkservicemesh/sdk/pkg/tools/opentelemetry" ) // NewDNSHandler - chains together a list of dnsutils.Handler with tracing func NewDNSHandler(handlers ...dnsutils.Handler) dnsutils.Handler { - return next.NewDNSHandler( - next.NewWrappedDNSHandler(trace.NewDNSHandler, handlers...), - ) + if opentelemetry.IsEnabled() { + return next.NewDNSHandler( + next.NewWrappedDNSHandler(trace.NewDNSHandler, handlers...), + ) + } + return next.NewDNSHandler(handlers...) }