Skip to content

Commit

Permalink
fix: skip if litmus-go not received trace_parent
Browse files Browse the repository at this point in the history
Signed-off-by: namkyu1999 <[email protected]>
  • Loading branch information
namkyu1999 committed Sep 16, 2024
1 parent e9be0ec commit a6a77d1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 22 deletions.
3 changes: 1 addition & 2 deletions bin/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import (
cli "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/sirupsen/logrus"
)

Expand All @@ -83,7 +82,7 @@ func main() {
ctx := context.Background()

// Set up Observability.
if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint)
if err != nil {
return
Expand Down
6 changes: 2 additions & 4 deletions bin/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import (
networkChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/helper"
dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper"
stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"

cli "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/sirupsen/logrus"
)

Expand All @@ -41,7 +39,7 @@ func init() {
func main() {
ctx := context.Background()
// Set up Observability.
if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint)
if err != nil {
return
Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/container-kill/lib/container-kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"

"github.com/litmuschaos/litmus-go/pkg/clients"
Expand Down Expand Up @@ -282,7 +281,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("STATUS_CHECK_TIMEOUT", strconv.Itoa(experimentsDetails.Timeout)).
SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName).
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/disk-fill/lib/disk-fill.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"

"github.com/litmuschaos/litmus-go/pkg/clients"
Expand Down Expand Up @@ -290,7 +289,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
SetEnv("SOCKET_PATH", experimentsDetails.SocketPath).
SetEnv("CONTAINER_RUNTIME", experimentsDetails.ContainerRuntime).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/http-chaos/lib/http-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"

"github.com/litmuschaos/litmus-go/pkg/clients"
Expand Down Expand Up @@ -284,7 +283,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("TARGET_SERVICE_PORT", strconv.Itoa(experimentsDetails.TargetServicePort)).
SetEnv("PROXY_PORT", strconv.Itoa(experimentsDetails.ProxyPort)).
SetEnv("TOXICITY", strconv.Itoa(experimentsDetails.Toxicity)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/network-chaos/lib/network-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

Expand Down Expand Up @@ -296,7 +295,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("DESTINATION_IPS_SERVICE_MESH", destIpsSvcMesh).
SetEnv("SOURCE_PORTS", experimentsDetails.SourcePorts).
SetEnv("DESTINATION_PORTS", experimentsDetails.DestinationPorts).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"

"github.com/litmuschaos/litmus-go/pkg/clients"
Expand Down Expand Up @@ -284,7 +283,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("MATCH_SCHEME", experimentsDetails.MatchScheme).
SetEnv("CHAOS_TYPE", experimentsDetails.ChaosType).
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
3 changes: 1 addition & 2 deletions chaoslib/litmus/stress-chaos/lib/stress-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/litmuschaos/litmus-go/pkg/cerrors"
"github.com/litmuschaos/litmus-go/pkg/telemetry"
"github.com/litmuschaos/litmus-go/pkg/utils"
"github.com/palantir/stacktrace"

"github.com/litmuschaos/litmus-go/pkg/clients"
Expand Down Expand Up @@ -329,7 +328,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath).
SetEnv("STRESS_TYPE", experimentsDetails.StressType).
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
1 change: 1 addition & 0 deletions pkg/telemetry/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
const (
OTELExperimentJobServiceName = "chaos_experiment_job"
OTELExperimentJobHelperServiceName = "chaos_experiment_job_helper"
OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
)

func InitOTelSDK(ctx context.Context, isExperiment bool, endpoint string) (shutdown func(context.Context) error, err error) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/telemetry/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func StartTracing(clients clients.ClientSets, spanName string) trace.Span {
func GetTraceParentContext() context.Context {
traceParent := os.Getenv(TraceParent)

if traceParent == "" {
return context.Background()
}

pro := otel.GetTextMapPropagator()
carrier := make(map[string]string)
if err := json.Unmarshal([]byte(traceParent), &carrier); err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package utils

import "net/url"

const (
OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
)

func HttpTimeout(err error) bool {
httpErr := err.(*url.Error)
if httpErr != nil {
Expand Down

0 comments on commit a6a77d1

Please sign in to comment.