Skip to content

Commit

Permalink
Rename some trace attributes; list device_id under both service.insta…
Browse files Browse the repository at this point in the history
…nce.id and k2.device_id (#1232)
  • Loading branch information
RebeccaMahany authored Jun 22, 2023
1 parent a828d36 commit e970e41
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pkg/traces/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,19 @@ func (t *TraceExporter) addDeviceIdentifyingAttributes() {
level.Debug(t.logger).Log("msg", "could not get device id", "err", err)
} else {
t.attrs = append(t.attrs, semconv.ServiceInstanceID(string(deviceId)))
t.attrs = append(t.attrs, attribute.String("k2.device_id", string(deviceId)))
}

if munemo, err := t.knapsack.ServerProvidedDataStore().Get([]byte("munemo")); err != nil {
level.Debug(t.logger).Log("msg", "could not get munemo", "err", err)
} else {
t.attrs = append(t.attrs, attribute.String("launcher.munemo", string(munemo)))
t.attrs = append(t.attrs, attribute.String("k2.munemo", string(munemo)))
}

if orgId, err := t.knapsack.ServerProvidedDataStore().Get([]byte("organization_id")); err != nil {
level.Debug(t.logger).Log("msg", "could not get organization id", "err", err)
} else {
t.attrs = append(t.attrs, attribute.String("launcher.organization_id", string(orgId)))
t.attrs = append(t.attrs, attribute.String("k2.organization_id", string(orgId)))
}

if serialNumber, err := t.knapsack.ServerProvidedDataStore().Get([]byte("serial_number")); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/traces/exporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ func TestNewTraceExporter(t *testing.T) { //nolint:paralleltest
// Wait a few seconds to allow the osquery queries to go through
time.Sleep(5 * time.Second)

// We expect a total of 11 attributes: 3 initial attributes, 4 from the ServerProvidedDataStore, and 4 from osquery
// We expect a total of 12 attributes: 3 initial attributes, 5 from the ServerProvidedDataStore, and 4 from osquery
traceExporter.attrLock.RLock()
defer traceExporter.attrLock.RUnlock()
require.Equal(t, 11, len(traceExporter.attrs))
require.Equal(t, 12, len(traceExporter.attrs))

// Confirm we set a provider
traceExporter.providerLock.Lock()
Expand Down Expand Up @@ -147,14 +147,14 @@ func Test_addDeviceIdentifyingAttributes(t *testing.T) {
traceExporter.addDeviceIdentifyingAttributes()

// Confirm all expected attributes were added
require.Equal(t, 4, len(traceExporter.attrs))
require.Equal(t, 5, len(traceExporter.attrs))
for _, actualAttr := range traceExporter.attrs {
switch actualAttr.Key {
case "service.instance.id":
case "service.instance.id", "k2.device_id":
require.Equal(t, expectedDeviceId, actualAttr.Value.AsString())
case "launcher.munemo":
case "k2.munemo":
require.Equal(t, expectedMunemo, actualAttr.Value.AsString())
case "launcher.organization_id":
case "k2.organization_id":
require.Equal(t, expectedOrganizationId, actualAttr.Value.AsString())
case "launcher.serial":
require.Equal(t, expectedSerialNumber, actualAttr.Value.AsString())
Expand Down

0 comments on commit e970e41

Please sign in to comment.