useragent

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package useragent builds the User-Agent the SDK sends to the platform and to the services its collectors and enrichers call:

[<product>/<version> ]openctem-sdk-go/<sdk version>

for example "openctemio-sensor/0.3.1 openctem-sdk-go/0.7.4". Operators use it to tell old agents from new sensors, and one SDK release from another, in proxy and API logs.

The SDK version is read from the binary's build info. The embedding binary names itself once, at startup, with SetProduct; every SDK HTTP client in the process then sends it. pkg/client also takes a per-client product (client.Config.UserAgent, client.WithUserAgent).

Stability: Stable (docs/STABILITY.md).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Product

func Product(name, version string) string

Product formats and sanitizes a "name/version" product token. It returns "" when name is empty after sanitizing.

func ProductName added in v0.10.0

func ProductName() (name, version string)

ProductName returns the name and version of the product set with SetProduct ("" when none was set).

func SDKVersion

func SDKVersion() string

SDKVersion returns the version of github.com/openctemio/sdk-go linked into this binary, without a leading "v": the module version from the build info (set by the release tag the sensor was built against), "<sdk.Version>-devel" for a build from a local checkout, or sdk.Version when the binary has no build info.

func SetProduct

func SetProduct(name, version string)

SetProduct names the binary embedding the SDK, for every SDK HTTP client in the process: SetProduct("openctemio-sensor", "0.3.1"). A leading "v" on the version is dropped; an empty version sends the name alone. Characters not allowed in an HTTP token are removed and the result is bounded, so a value from configuration cannot inject headers. Call it once at startup, before the first request.

func String

func String() string

String returns the User-Agent for the product set with SetProduct.

func Transport

func Transport(base http.RoundTripper) http.RoundTripper

Transport returns a RoundTripper that sets the User-Agent (String, read at request time) on every request that does not carry one, then calls base (http.DefaultTransport when nil). The request is cloned, never modified.

func WithProduct

func WithProduct(p string) string

WithProduct returns the User-Agent for an explicit product token (already formatted as "name/version", possibly several separated by spaces). The token is sanitized and bounded; an empty one yields the SDK token alone.

Types

This section is empty.

Jump to

Keyboard shortcuts

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