Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

inband otel traceparent propagation #34

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion hardware/hw.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Hardware struct {
logger *log.Logger
mu sync.RWMutex
hw map[id]struct {
j string
j string // raw json record
ips map[netaddr.IP]bool
macs map[mac]bool
}
Expand All @@ -48,6 +48,8 @@ type hardware struct {
MAC string
}
} `json:"network_ports"`
// in-band propagation of w3c traceparent so it can make it to boots
Traceparent string `json:"traceparent"`
}

// The Option type describes functions that operate on Hardeare during New.
Expand Down
31 changes: 31 additions & 0 deletions hardware/hw_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hardware

import (
"encoding/json"
"fmt"
"testing"

Expand Down Expand Up @@ -403,3 +404,33 @@ func TestByMAC(t *testing.T) {
assert.Equal(j2, j)
}
}

func TestTraceparent(t *testing.T) {
assert := require.New(t)

tps := []string{
"",
"00-00000000000000000000000000000000-0000000000000000-00",
"00-6d2cd79aa1c04f5a6f579cdb932e07b3-d376ef33e09b1e05-01",
"00-d538560f791eb96185f34aa2bf6082a9-b98f3fb3157fae01-01",
}

jsons := []string{
`{"id": "` + uuid.New().String() + `", "traceparent": "` + tps[0] + `"}`,
`{"id": "` + uuid.New().String() + `", "traceparent": "` + tps[1] + `"}`,
`{"id": "` + uuid.New().String() + `", "traceparent": "` + tps[2] + `"}`,
`{"id": "` + uuid.New().String() + `", "traceparent": "` + tps[3] + `"}`,
}

hw := New()
for i, j := range jsons {
id, err := hw.Add(j)
assert.Nil(err)
js, err := hw.ByID(id) // retrieve the hw and make sure the tp survives
assert.Nil(err)
inst := hardware{}
err = json.Unmarshal([]byte(js), &inst)
assert.Nil(err)
assert.Equal(tps[i], inst.Traceparent)
}
}