devtelemetry

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package devtelemetry records where a local env's telemetry goes, as `forge env up` decided it, so `forge obs` reads the decision instead of re-deriving it from ambient login state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BrowserHeadersPath

func BrowserHeadersPath(projectDir string) string

BrowserHeadersPath is the browser token's headers file, read by the frontend dev server's /_otel proxy (FORGE_OTEL_HEADERS_FILE).

func ClearCredentials

func ClearCredentials(projectDir, env string) error

ClearCredentials removes env's token state, and the headers files unless another env of this project is recorded as shipping to the hosted store (the headers files are per project). Called whenever env's telemetry is decided local, so a local stack never keeps a usable hosted token on disk and `forge env status` never reads a stale grant. A missing file is not an error.

func HeadersPath

func HeadersPath(projectDir string) string

HeadersPath is the process token's headers file, in the `authorization=Bearer <token>` form OTEL_EXPORTER_OTLP_HEADERS_FILE names.

func MarkNoticeShown

func MarkNoticeShown(projectDir string, at time.Time) error

MarkNoticeShown records that the first-run notice was shown.

func NoticePath

func NoticePath(projectDir string) string

NoticePath records that the first-run notice of hosted dev telemetry was shown in this project.

func NoticeShown

func NoticeShown(projectDir string) bool

NoticeShown reports whether the first-run notice was already shown.

func Path

func Path(projectDir, env string) string

Path is where env's record lives in projectDir.

func StatePath

func StatePath(projectDir, env string) string

StatePath is env's token state: when the current tokens expire, the retention the control plane granted, and why the last renewal failed.

func Write

func Write(projectDir string, rec Record) error

Write replaces env's record atomically.

func WriteHeaders

func WriteHeaders(projectDir, processToken, browserToken string) error

WriteHeaders replaces both headers files with the two tokens.

func WriteState

func WriteState(projectDir string, st State) error

WriteState replaces env's token state atomically.

Types

type Record

type Record struct {
	Env           string    `json:"env"`
	Backend       string    `json:"backend"` // "cloud" or "local"
	Reason        string    `json:"reason"`
	OrgID         string    `json:"org_id,omitempty"`
	EnvironmentID string    `json:"environment_id,omitempty"`
	InstanceID    string    `json:"instance_id,omitempty"`
	InstanceLabel string    `json:"instance_label,omitempty"`
	InstanceUser  string    `json:"instance_user,omitempty"`
	Endpoint      string    `json:"endpoint,omitempty"`
	DecidedAt     time.Time `json:"decided_at"`
}

Record is .forge/obs/backend-<env>.json.

func Read

func Read(projectDir, env string) (rec Record, ok bool, err error)

Read returns env's record; ok is false when none was written.

type Retention

type Retention struct {
	TracesDays  int `json:"traces_days,omitempty"`
	MetricsDays int `json:"metrics_days,omitempty"`
	LogsDays    int `json:"logs_days,omitempty"`
	BrowserDays int `json:"browser_days,omitempty"`
}

Retention is the effective retention the control plane granted, in days.

type State

type State struct {
	Env       string    `json:"env"`
	ExpiresAt time.Time `json:"expires_at"`
	RenewedAt time.Time `json:"renewed_at"`
	Retention Retention `json:"retention"`
	// RenewError is why the last renewal failed; empty after a success.
	RenewError string `json:"renew_error,omitempty"`
}

State is .forge/obs/telemetry-<env>.json.

func ReadState

func ReadState(projectDir, env string) (st State, ok bool, err error)

ReadState returns env's token state; ok is false when none was written.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL