forked from open-telemetry/opentelemetry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.go
More file actions
43 lines (36 loc) · 1.48 KB
/
env.go
File metadata and controls
43 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package propagation // import "go.opentelemetry.io/otel/propagation"
import (
"os"
"strings"
)
// EnvCarrier is a TextMapCarrier that uses the environment variables as a
// storage medium for propagated key-value pairs. The keys are uppercased
// before being used to access the environment variables.
// This is useful for propagating values that are set in the environment
// and need to be accessed by different processes or services.
// The keys are uppercased to avoid case sensitivity issues across different
// operating systems and environments.
type EnvCarrier struct{}
var _ TextMapCarrier = EnvCarrier{}
// Get returns the value associated with the passed key.
// The key is uppercased before being used to access the environment variable.
func (EnvCarrier) Get(key string) string {
k := strings.ToUpper(key)
return os.Getenv(k)
}
// Set stores the key-value pair in the environment variable.
// The key is uppercased before being used to set the environment variable.
func (EnvCarrier) Set(key, value string) {
k := strings.ToUpper(key)
_ = os.Setenv(k, value)
}
// Keys lists the keys stored in this carrier.
// This method is not implemented for EnvCarrier as it is not possible to
// list all environment variables in a portable way.
func (EnvCarrier) Keys() []string {
// I don't know why TextMapCarrier even has a Keys method.
// It looks like it was some mistake in the original design.
return nil
}