client

package
v1.16.4 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxRetries is the default number of retries for failed API requests.
	DefaultMaxRetries = 3
)

Variables

This section is empty.

Functions

func HandleAPIError

func HandleAPIError(err error, ctx ...ErrorContext) error

HandleAPIError provides user-friendly error messages for API errors. It checks for common error types and returns descriptive messages. Optional context can be provided to include asset details in error messages.

func IsAlreadyDeleted added in v1.16.2

func IsAlreadyDeleted(err error, force bool, ectx ErrorContext) bool

IsAlreadyDeleted implements idempotent `delete --force` semantics: when the delete API call returned 404 and force was set, the desired end-state ("asset is gone") already holds, so callers should treat the response as success. As a side effect, a short "was already deleted" line is written to stderr so the operator (or agent) sees that nothing was actually removed. Returns false when the caller should fall through to the normal error path.

func NewClientFromContext

func NewClientFromContext(ctx context.Context, apiUrl, authToken string) (dash0api.Client, error)

NewClientFromContext creates a new Dash0 API client using configuration from context. Flag overrides (apiUrl, authToken) are applied on top of the context configuration.

func NewOtlpClientFromContext added in v1.1.0

func NewOtlpClientFromContext(ctx context.Context, otlpUrl, authToken string) (dash0api.Client, error)

NewOtlpClientFromContext creates a new Dash0 API client configured for OTLP using configuration from context. Flag overrides (otlpUrl, authToken) are applied on top of the context configuration.

func ResolveApiUrl added in v1.2.0

func ResolveApiUrl(ctx context.Context, flagApiUrl string) string

ResolveApiUrl returns the effective API URL from context and flag overrides. This is useful when the resolved URL is needed outside of client creation (e.g. for constructing deeplink URLs).

func ResolveDataset added in v1.1.0

func ResolveDataset(ctx context.Context, flagDataset string) *string

ResolveDataset returns the dataset to use for API calls, checking (in order): 1. The CLI flag value (flagDataset) 2. The configuration from context (profile + DASH0_DATASET env var) 3. The DASH0_DATASET env var, then a freshly resolved configuration, when the context carries no configuration at all Returns nil when no dataset is configured or when the dataset is "default", since the API uses "default" implicitly when no dataset parameter is sent.

Step 3 exists because NewClientFromContext falls back to profiles.ResolveConfiguration when the context configuration is missing. Without the same fallback here, a command whose config failed to load would still reach the API with credentials recovered from flags or env vars, but silently without a dataset — so the request would hit the default dataset instead of the configured one.

func WithMaxRetries added in v1.13.0

func WithMaxRetries(ctx context.Context, maxRetries *int) context.Context

WithMaxRetries stores the --max-retries flag value in the context.

Types

type ErrorContext

type ErrorContext struct {
	AssetType string // e.g., "dashboard", "check rule"
	AssetID   string // e.g., "a1b2c3d4-..." (optional, empty for create/list)
	AssetName string // e.g., "Production Overview" (optional, for user-friendly messages)
}

ErrorContext provides context about the asset involved in an error. This context is used to generate more specific and actionable error messages.

type RawHTTPConfig added in v1.10.0

type RawHTTPConfig struct {
	// HTTPClient is a plain net/http client ready to perform requests.
	HTTPClient *http.Client
	// ApiUrl is the resolved API base URL.
	ApiUrl string
	// AuthToken is the resolved bearer token.
	AuthToken string
	// Dataset is the dataset resolved from environment or active profile.
	// Flag overrides are the caller's responsibility so that "explicitly
	// unset" can be distinguished from "not provided".
	Dataset string
	// UserAgent is the User-Agent string to send with requests.
	UserAgent string
}

RawHTTPConfig holds the resolved configuration for raw HTTP calls against the Dash0 API.

func NewRawHTTPConfig added in v1.10.0

func NewRawHTTPConfig(ctx context.Context, apiUrl, authToken string) (*RawHTTPConfig, error)

NewRawHTTPConfig resolves the API URL, auth token and profile dataset from context, environment and flag overrides, returning a ready-to-use configuration for raw HTTP requests against the Dash0 API.

This sits beside NewClientFromContext rather than wrapping the generated typed client: the typed client does not expose its underlying transport, and raw mode needs to emit arbitrary requests without the constraints of the generated surface.

Jump to

Keyboard shortcuts

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