feat(ledger): use anonymousId for segementprovider (#94)

#### Features

- Add getDistinctID() using the machineid library to generate a stable,
non-reversible HMAC-SHA256 hash of the OS machine ID for Segment's
AnonymousId, enabling cross-session event correlation without collecting
PII.

Related: https://github.com/SigNoz/platform-pod/issues/1910
This commit is contained in:
Nageshbansal
2026-04-07 22:45:43 +05:30
committed by GitHub
parent 6c6168c53c
commit 886d36c806
4 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ Each command execution sends a single event with the following properties:
### Identity
Events are attributed to the machine hostname as an anonymous identifier. No usernames, emails, IP addresses, or file contents are sent.
Events are attributed using a hashed machine ID (HMAC-SHA256 of the OS machine ID with an application-specific salt). The hash is not reversible and cannot be correlated across different applications. No usernames, emails, IP addresses, hostnames, or file contents are sent.
## Tracked commands
+2 -1
View File
@@ -4,6 +4,7 @@ go 1.25.3
require (
github.com/Masterminds/sprig/v3 v3.3.0
github.com/denisbrodbeck/machineid v1.0.1
github.com/evanphx/json-patch/v5 v5.9.11
github.com/olekukonko/tablewriter v1.1.4
github.com/segmentio/analytics-go/v3 v3.3.0
@@ -108,7 +109,7 @@ require (
golang.org/x/net v0.48.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/sys v0.42.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
golang.org/x/time v0.12.0 // indirect
+4 -2
View File
@@ -64,6 +64,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN6UX90KJc4HjyM=
@@ -375,8 +377,8 @@ golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
+8 -5
View File
@@ -3,9 +3,9 @@ package segmentledger
import (
"context"
"fmt"
"os"
"runtime"
"github.com/denisbrodbeck/machineid"
segment "github.com/segmentio/analytics-go/v3"
"github.com/signoz/foundry/internal/ledger"
"github.com/signoz/foundry/internal/ledger/noopledger"
@@ -59,12 +59,15 @@ func (p *provider) Close() error {
return p.client.Close()
}
// getDistinctID returns a stable anonymous identifier for the machine.
// It uses the hostname so there is no PII stored.
// getDistinctID returns a hashed machine ID for anonymous attribution.
// The ID is stable across sessions and not reversible to the original machine ID.
func getDistinctID() string {
hostname, err := os.Hostname()
id, err := machineid.ProtectedID("foundryctl")
if err != nil {
return "unknown"
}
return hostname
if len(id) > 32 {
return id[:32]
}
return id
}