Skip to content
Merged
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
19 changes: 13 additions & 6 deletions pkg/usagemetrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,17 @@ func NewClient(endpoint string) *Client {
// SendMetrics sends the metrics record to the API
func (c *Client) SendMetrics(instanceID string, record MetricRecord) error {
// Use cached anonymous ID (set at client creation)
// Skip sending if anonymous ID is not initialized
if c.anonymousID == "" {
logger.Debugf("Skipping metrics send - anonymous ID not yet initialized")
return nil
// For operator-deployed proxies without filesystem access, anonymous_id will be empty,
// but we still send metrics with a default value.
anonymousID := c.anonymousID
if anonymousID == "" {
// Only use default for operator-deployed proxies (detected via K8s env vars)
if rt.IsKubernetesRuntimeWithEnv(&env.OSReader{}) {
anonymousID = "operator-proxy"
} else {
// For local deployments, empty anonymous_id means file doesn't exist yet - skip sending
return nil
}
}

data, err := json.Marshal(record)
Expand All @@ -71,8 +78,8 @@ func (c *Client) SendMetrics(instanceID string, record MetricRecord) error {
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set(instanceIDHeader, instanceID) // Proxy instance ID
req.Header.Set(anonymousIDHeader, c.anonymousID) // User anonymous ID
req.Header.Set(instanceIDHeader, instanceID) // Proxy instance ID
req.Header.Set(anonymousIDHeader, anonymousID) // User anonymous ID (or default for operator)
req.Header.Set(userAgentHeader, generateUserAgent())

resp, err := c.client.Do(req)
Expand Down
Loading