Skip to content

Commit a6a77d1

Browse files
committed
fix: skip if litmus-go not received trace_parent
Signed-off-by: namkyu1999 <[email protected]>
1 parent e9be0ec commit a6a77d1

File tree

11 files changed

+14
-22
lines changed

11 files changed

+14
-22
lines changed

bin/experiment/experiment.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import (
6666
cli "github.com/litmuschaos/litmus-go/pkg/clients"
6767
"github.com/litmuschaos/litmus-go/pkg/log"
6868
"github.com/litmuschaos/litmus-go/pkg/telemetry"
69-
"github.com/litmuschaos/litmus-go/pkg/utils"
7069
"github.com/sirupsen/logrus"
7170
)
7271

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

8584
// Set up Observability.
86-
if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
85+
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
8786
shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint)
8887
if err != nil {
8988
return

bin/helper/helper.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import (
2121
networkChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/helper"
2222
dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper"
2323
stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper"
24-
"github.com/litmuschaos/litmus-go/pkg/telemetry"
25-
"github.com/litmuschaos/litmus-go/pkg/utils"
26-
2724
cli "github.com/litmuschaos/litmus-go/pkg/clients"
2825
"github.com/litmuschaos/litmus-go/pkg/log"
26+
"github.com/litmuschaos/litmus-go/pkg/telemetry"
2927
"github.com/sirupsen/logrus"
3028
)
3129

@@ -41,7 +39,7 @@ func init() {
4139
func main() {
4240
ctx := context.Background()
4341
// Set up Observability.
44-
if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
42+
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
4543
shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint)
4644
if err != nil {
4745
return

chaoslib/litmus/container-kill/lib/container-kill.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1111
"github.com/litmuschaos/litmus-go/pkg/telemetry"
12-
"github.com/litmuschaos/litmus-go/pkg/utils"
1312
"github.com/palantir/stacktrace"
1413

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

chaoslib/litmus/disk-fill/lib/disk-fill.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1111
"github.com/litmuschaos/litmus-go/pkg/telemetry"
12-
"github.com/litmuschaos/litmus-go/pkg/utils"
1312
"github.com/palantir/stacktrace"
1413

1514
"github.com/litmuschaos/litmus-go/pkg/clients"
@@ -290,7 +289,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
290289
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
291290
SetEnv("SOCKET_PATH", experimentsDetails.SocketPath).
292291
SetEnv("CONTAINER_RUNTIME", experimentsDetails.ContainerRuntime).
293-
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
292+
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
294293
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
295294
SetEnvFromDownwardAPI("v1", "metadata.name")
296295

chaoslib/litmus/http-chaos/lib/http-chaos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1111
"github.com/litmuschaos/litmus-go/pkg/telemetry"
12-
"github.com/litmuschaos/litmus-go/pkg/utils"
1312
"github.com/palantir/stacktrace"
1413

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

chaoslib/litmus/network-chaos/lib/network-chaos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1212
"github.com/litmuschaos/litmus-go/pkg/telemetry"
13-
"github.com/litmuschaos/litmus-go/pkg/utils"
1413
"github.com/palantir/stacktrace"
1514
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1615

@@ -296,7 +295,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
296295
SetEnv("DESTINATION_IPS_SERVICE_MESH", destIpsSvcMesh).
297296
SetEnv("SOURCE_PORTS", experimentsDetails.SourcePorts).
298297
SetEnv("DESTINATION_PORTS", experimentsDetails.DestinationPorts).
299-
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
298+
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
300299
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
301300
SetEnvFromDownwardAPI("v1", "metadata.name")
302301

chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1111
"github.com/litmuschaos/litmus-go/pkg/telemetry"
12-
"github.com/litmuschaos/litmus-go/pkg/utils"
1312
"github.com/palantir/stacktrace"
1413

1514
"github.com/litmuschaos/litmus-go/pkg/clients"
@@ -284,7 +283,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
284283
SetEnv("MATCH_SCHEME", experimentsDetails.MatchScheme).
285284
SetEnv("CHAOS_TYPE", experimentsDetails.ChaosType).
286285
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
287-
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
286+
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
288287
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
289288
SetEnvFromDownwardAPI("v1", "metadata.name")
290289

chaoslib/litmus/stress-chaos/lib/stress-chaos.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1111
"github.com/litmuschaos/litmus-go/pkg/telemetry"
12-
"github.com/litmuschaos/litmus-go/pkg/utils"
1312
"github.com/palantir/stacktrace"
1413

1514
"github.com/litmuschaos/litmus-go/pkg/clients"
@@ -329,7 +328,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime
329328
SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath).
330329
SetEnv("STRESS_TYPE", experimentsDetails.StressType).
331330
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
332-
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)).
331+
SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)).
333332
SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)).
334333
SetEnvFromDownwardAPI("v1", "metadata.name")
335334

pkg/telemetry/otel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
const (
1717
OTELExperimentJobServiceName = "chaos_experiment_job"
1818
OTELExperimentJobHelperServiceName = "chaos_experiment_job_helper"
19+
OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT"
1920
)
2021

2122
func InitOTelSDK(ctx context.Context, isExperiment bool, endpoint string) (shutdown func(context.Context) error, err error) {

pkg/telemetry/tracing.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func StartTracing(clients clients.ClientSets, spanName string) trace.Span {
2626
func GetTraceParentContext() context.Context {
2727
traceParent := os.Getenv(TraceParent)
2828

29+
if traceParent == "" {
30+
return context.Background()
31+
}
32+
2933
pro := otel.GetTextMapPropagator()
3034
carrier := make(map[string]string)
3135
if err := json.Unmarshal([]byte(traceParent), &carrier); err != nil {

0 commit comments

Comments
 (0)