From 2059ed537a2587f3b39411341dc4e9a35d1ed9f4 Mon Sep 17 00:00:00 2001
From: Amy Tobey
Date: Wed, 29 Sep 2021 15:26:40 -0700
Subject: [PATCH 1/2] explicitly check key exists in SimpleCarrier.Get
Doesn't seem to crash the tests but the old code made me nervous so here
we are.
Signed-off-by: Amy Tobey
---
otelhelpers/simple_carrier.go | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/otelhelpers/simple_carrier.go b/otelhelpers/simple_carrier.go
index 1d2b7d8..a9cacb4 100644
--- a/otelhelpers/simple_carrier.go
+++ b/otelhelpers/simple_carrier.go
@@ -8,7 +8,10 @@ type SimpleCarrier map[string]string
// Get implements the otel interface for propagation.
func (otp SimpleCarrier) Get(key string) string {
- return otp[key]
+ if v, ok := otp[key]; ok {
+ return v
+ }
+ return ""
}
// Set implements the otel interface for propagation.
From c0968ede7e19b6b18b82b869ef1bf841d9b714fd Mon Sep 17 00:00:00 2001
From: Amy Tobey
Date: Wed, 29 Sep 2021 15:35:43 -0700
Subject: [PATCH 2/2] add a comment to Get about returning empty string
Signed-off-by: Amy Tobey
---
otelhelpers/simple_carrier.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/otelhelpers/simple_carrier.go b/otelhelpers/simple_carrier.go
index a9cacb4..c3063c3 100644
--- a/otelhelpers/simple_carrier.go
+++ b/otelhelpers/simple_carrier.go
@@ -6,7 +6,8 @@ package otelhelpers
// but since we're not doing anything else with it, it's fine for this.
type SimpleCarrier map[string]string
-// Get implements the otel interface for propagation.
+// Get implements the otel interface for propagation. Returns empty
+// string if the key doesn't exist.
func (otp SimpleCarrier) Get(key string) string {
if v, ok := otp[key]; ok {
return v