8000 feat(provisioner): propagate trace info by coryb · Pull Request #17166 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat(provisioner): propagate trace info #17166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update for feedback, remove unimplemented panics
Simplified the slice copy/update logic.  Removed the panics for non
required interface functions, the impl was trivial, added simple tests
to ensure they work as expected.
  • Loading branch information
coryb committed Apr 7, 2025
commit 228410861961be1768ab3dcf78c4e0f9ebde2f04
32 changes: 23 additions & 9 deletions provisioner/terraform/otelenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,37 @@ func (c *envCarrier) Set(key, value string) {
if strings.HasPrefix(e, key+"=") {
// don't directly update the slice so we don't modify the slice
// passed in
newEnv := slices.Clone(c.Env)
newEnv = append(newEnv[:i], append([]string{fmt.Sprintf("%s=%s", key, value)}, newEnv[i+1:]...)...)
c.Env = newEnv
c.Env = slices.Clone(c.Env)
c.Env[i] = fmt.Sprintf("%s=%s", key, value)
return
}
}
c.Env = append(c.Env, fmt.Sprintf("%s=%s", key, value))
}

func (*envCarrier) Get(_ string) string {
// Get not necessary to inject environment variables
panic("Not implemented")
func (c *envCarrier) Get(key string) string {
if c == nil {
return ""
}
key = toKey(key)
for _, e := range c.Env {
if strings.HasPrefix(e, key+"=") {
return strings.TrimPrefix(e, key+"=")
}
}
return ""
}

func (*envCarrier) Keys() []string {
// Keys not necessary to inject environment variables
panic("Not implemented")
func (c *envCarrier) Keys() []string {
if c == nil {
return nil
}
keys := make([]string, len(c.Env))
for i, e := range c.Env {
k, _, _ := strings.Cut(e, "=")
keys[i] = k
}
return keys
}

// otelEnvInject will add add any necessary environment variables for the span
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package terraform // nolint:testpackage
package terraform

import (
"context"
Expand Down Expand Up @@ -61,3 +61,25 @@ func TestOtelEnvInject(t *testing.T) {
"TERM=xterm",
}, got)
}

func TestEnvCarrierSet(t *testing.T) {
t.Parallel()
c := &envCarrier{
Env: []string{"PATH=/usr/bin:/bin", "TERM=xterm"},
}
c.Set("PATH", "/usr/local/bin")
c.Set("NEWVAR", "newval")
require.Equal(t, []string{
"PATH=/usr/local/bin",
"TERM=xterm",
"NEWVAR=newval",
}, c.Env)
}

func TestEnvCarrierKeys(t *testing.T) {
t.Parallel()
c := &envCarrier{
Env: []string{"PATH=/usr/bin:/bin", "TERM=xterm"},
}
require.Equal(t, []string{"PATH", "TERM"}, c.Keys())
}
0