Documentation
¶
Overview ¶
Package otelcli implements the otel-cli subcommands and argument parsing with Cobra and implements functionality using otlpclient and otlpserver.
Index ¶
- func Execute(version string)
- func FormatVersion(version, commit, date string) string
- func GetExitCode() int
- func StartClient(ctx context.Context, config Config) (context.Context, otlpclient.OTLPClient)
- type BgEnd
- type BgSpan
- type BgSpanEvent
- type Config
- func (c Config) GetEndpoint() *url.URL
- func (c Config) GetHeaders() map[string]string
- func (c Config) GetInsecure() bool
- func (c Config) GetIsRecording() bool
- func (c Config) GetServiceName() string
- func (c Config) GetTimeout() time.Duration
- func (config Config) GetTlsConfig() *tls.Config
- func (c Config) GetVersion() string
- func (c *Config) LoadEnv(getenv func(string) string) error
- func (c *Config) LoadFile() error
- func (c Config) LoadTraceparent() traceparent.Traceparent
- func (c Config) NewProtobufSpan() *tracepb.Span
- func (c Config) ParseCliTimeout() time.Duration
- func (config Config) ParseEndpoint() (*url.URL, string)
- func (c Config) ParseExecCommandTimeout() time.Duration
- func (c Config) ParseSpanEndTime() time.Time
- func (c Config) ParseSpanStartTime() time.Time
- func (c Config) ParseStatusCanaryInterval() time.Duration
- func (c Config) ParsedEventTime() time.Time
- func (c Config) PropagateTraceparent(span *tracepb.Span, target io.Writer)
- func (c Config) SoftFail(format string, a ...interface{})
- func (c Config) SoftFailIfErr(err error)
- func (c Config) SoftLog(format string, a ...interface{})
- func (c Config) SoftLogIfErr(err error)
- func (c Config) ToStringMap() map[string]string
- func (c Config) WithAttributes(with map[string]string) Config
- func (c Config) WithBackgroundParentPollMs(with int) Config
- func (c Config) WithBackgroundSkipParentPidCheck(with bool) Config
- func (c Config) WithBackgroundSockdir(with string) Config
- func (c Config) WithBackgroundWait(with bool) Config
- func (c Config) WithBlocking(with bool) Config
- func (c Config) WithCfgFile(with string) Config
- func (c Config) WithEndpoint(with string) Config
- func (c Config) WithEventName(with string) Config
- func (c Config) WithEventTime(with string) Config
- func (c Config) WithFail(with bool) Config
- func (c Config) WithHeaders(with map[string]string) Config
- func (c Config) WithInsecure(with bool) Config
- func (c Config) WithKind(with string) Config
- func (c Config) WithProtocol(with string) Config
- func (c Config) WithServiceName(with string) Config
- func (c Config) WithSpanEndTime(with string) Config
- func (c Config) WithSpanName(with string) Config
- func (c Config) WithSpanStartTime(with string) Config
- func (c Config) WithStatusCanaryCount(with int) Config
- func (c Config) WithStatusCanaryInterval(with string) Config
- func (c Config) WithStatusCode(with string) Config
- func (c Config) WithStatusDescription(with string) Config
- func (c Config) WithTimeout(with string) Config
- func (c Config) WithTlsCACert(with string) Config
- func (c Config) WithTlsClientCert(with string) Config
- func (c Config) WithTlsClientKey(with string) Config
- func (c Config) WithTlsNoVerify(with bool) Config
- func (c Config) WithTraceparentCarrierFile(with string) Config
- func (c Config) WithTraceparentIgnoreEnv(with bool) Config
- func (c Config) WithTraceparentPrint(with bool) Config
- func (c Config) WithTraceparentPrintExport(with bool) Config
- func (c Config) WithTraceparentRequired(with bool) Config
- func (c Config) WithTracesEndpoint(with string) Config
- func (c Config) WithVerbose(with bool) Config
- func (c Config) WithVersion(with string) Config
- type Diagnostics
- type SpanEventUnion
- type SpanEventUnionList
- type StatusOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Execute ¶
func Execute(version string)
Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once.
func FormatVersion ¶
FormatVersion pretty-prints the global version, commit, and date values into a string to enable the --version flag. Public to be called from main.
func GetExitCode ¶
func GetExitCode() int
GetExitCode() is a helper for Cobra to retrieve the exit code, mainly used by exec to make otel-cli return the child program's exit code.
func StartClient ¶
func StartClient(ctx context.Context, config Config) (context.Context, otlpclient.OTLPClient)
StartClient uses the Config to setup and start either a gRPC or HTTP client, and returns the OTLPClient interface to them.
Types ¶
type BgEnd ¶
type BgEnd struct {
Attributes map[string]string `json:"span_attributes" env:"OTEL_CLI_ATTRIBUTES"`
StatusCode string `json:"status_code"`
StatusDesc string `json:"status_description"`
}
BgEnd is an empty struct that can be sent to call End().
type BgSpan ¶
type BgSpan struct {
TraceID string `json:"trace_id"`
SpanID string `json:"span_id"`
Traceparent string `json:"traceparent"`
Error string `json:"error"`
// contains filtered or unexported fields
}
BgSpan is what is returned to all RPC clients and its methods are exported.
func (BgSpan) AddEvent ¶
func (bs BgSpan) AddEvent(bse *BgSpanEvent, reply *BgSpan) error
AddEvent takes a BgSpanEvent from the client and attaches an event to the span.
type BgSpanEvent ¶
type BgSpanEvent struct {
Name string `json:"name"`
Timestamp string `json:"timestamp"`
Attributes map[string]string
}
BgSpanEvent is a span event that the client will send.
type Config ¶
type Config struct {
Endpoint string `json:"endpoint" env:"OTEL_EXPORTER_OTLP_ENDPOINT"`
TracesEndpoint string `json:"traces_endpoint" env:"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"`
Protocol string `json:"protocol" env:"OTEL_EXPORTER_OTLP_PROTOCOL,OTEL_EXPORTER_OTLP_TRACES_PROTOCOL"`
Timeout string `json:"timeout" env:"OTEL_EXPORTER_OTLP_TIMEOUT,OTEL_EXPORTER_OTLP_TRACES_TIMEOUT"`
Headers map[string]string `json:"otlp_headers" env:"OTEL_EXPORTER_OTLP_HEADERS"` // TODO: needs json marshaler hook to mask tokens
Insecure bool `json:"insecure" env:"OTEL_EXPORTER_OTLP_INSECURE"`
Blocking bool `json:"otlp_blocking" env:"OTEL_EXPORTER_OTLP_BLOCKING"`
TlsCACert string `json:"tls_ca_cert" env:"OTEL_EXPORTER_OTLP_CERTIFICATE,OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE"`
TlsClientKey string `json:"tls_client_key" env:"OTEL_EXPORTER_OTLP_CLIENT_KEY,OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY"`
TlsClientCert string `json:"tls_client_cert" env:"OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE,OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE"`
// OTEL_CLI_NO_TLS_VERIFY is deprecated and will be removed for 1.0
TlsNoVerify bool `json:"tls_no_verify" env:"OTEL_CLI_TLS_NO_VERIFY,OTEL_CLI_NO_TLS_VERIFY"`
ServiceName string `json:"service_name" env:"OTEL_CLI_SERVICE_NAME,OTEL_SERVICE_NAME"`
SpanName string `json:"span_name" env:"OTEL_CLI_SPAN_NAME"`
Kind string `json:"span_kind" env:"OTEL_CLI_TRACE_KIND"`
Attributes map[string]string `json:"span_attributes" env:"OTEL_CLI_ATTRIBUTES"`
StatusCode string `json:"span_status_code" env:"OTEL_CLI_STATUS_CODE"`
StatusDescription string `json:"span_status_description" env:"OTEL_CLI_STATUS_DESCRIPTION"`
ForceSpanId string `json:"force_span_id" env:"OTEL_CLI_FORCE_SPAN_ID"`
ForceParentSpanId string `json:"force_parent_span_id" env:"OTEL_CLI_FORCE_PARENT_SPAN_ID"`
ForceTraceId string `json:"force_trace_id" env:"OTEL_CLI_FORCE_TRACE_ID"`
TraceparentCarrierFile string `json:"traceparent_carrier_file" env:"OTEL_CLI_CARRIER_FILE"`
TraceparentIgnoreEnv bool `json:"traceparent_ignore_env" env:"OTEL_CLI_IGNORE_ENV"`
TraceparentPrint bool `json:"traceparent_print" env:"OTEL_CLI_PRINT_TRACEPARENT"`
TraceparentPrintExport bool `json:"traceparent_print_export" env:"OTEL_CLI_EXPORT_TRACEPARENT"`
TraceparentRequired bool `json:"traceparent_required" env:"OTEL_CLI_TRACEPARENT_REQUIRED"`
BackgroundParentPollMs int `json:"background_parent_poll_ms" env:""`
BackgroundSockdir string `json:"background_socket_directory" env:""`
BackgroundWait bool `json:"background_wait" env:""`
BackgroundSkipParentPidCheck bool `json:"background_skip_parent_pid_check"`
ExecCommandTimeout string `json:"exec_command_timeout" env:"OTEL_CLI_EXEC_CMD_TIMEOUT"`
ExecTpDisableInject bool `json:"exec_tp_disable_inject" env:"OTEL_CLI_EXEC_TP_DISABLE_INJECT"`
StatusCanaryCount int `json:"status_canary_count"`
StatusCanaryInterval string `json:"status_canary_interval"`
SpanStartTime string `json:"span_start_time" env:""`
SpanEndTime string `json:"span_end_time" env:""`
EventName string `json:"event_name" env:""`
EventTime string `json:"event_time" env:""`
CfgFile string `json:"config_file" env:"OTEL_CLI_CONFIG_FILE"`
Verbose bool `json:"verbose" env:"OTEL_CLI_VERBOSE"`
Fail bool `json:"fail" env:"OTEL_CLI_FAIL"`
// not exported, used to get data from cobra to otlpclient internals
Version string `json:"-"`
}
Config stores the runtime configuration for otel-cli. Data structure is public so that it can serialize to json easily.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with all defaults set.
func (Config) GetEndpoint ¶
func (Config) GetHeaders ¶
GetHeaders returns the stringmap of configured headers.
func (Config) GetInsecure ¶
GetInsecure returns true if the configuration expects a non-TLS connection.
func (Config) GetIsRecording ¶
GetIsRecording returns true if an endpoint is set and otel-cli expects to send real spans. Returns false if unconfigured and going to run inert.
func (Config) GetServiceName ¶
GetServiceName returns the configured OTel service name.
func (Config) GetTimeout ¶
GetTimeout returns the parsed --timeout value as a time.Duration.
func (Config) GetTlsConfig ¶
TlsConfig evaluates otel-cli configuration and returns a tls.Config that can be used by grpc or https.
func (Config) GetVersion ¶
Version returns the program version stored in the config.
func (*Config) LoadEnv ¶
LoadEnv loads environment variables into the config, overwriting current values. Environment variable to config key mapping is tagged on the Config struct. Multiple names for envvars is supported, comma-separated. Takes a func(string)string that's usually os.Getenv, and is swappable to make testing easier.
func (*Config) LoadFile ¶
LoadFile reads the file specified by -c/--config and overwrites the current config values with any found in the file.
func (Config) LoadTraceparent ¶
func (c Config) LoadTraceparent() traceparent.Traceparent
LoadTraceparent follows otel-cli's loading rules, start with envvar then file. If both are set, the file will override env. When in non-recording mode, the previous traceparent will be returned if it's available, otherwise, a zero-valued traceparent is returned.
func (Config) NewProtobufSpan ¶
NewProtobufSpan creates a new span and populates it with information from the config struct.
func (Config) ParseCliTimeout ¶
ParseCliTimeout parses the --timeout string value to a time.Duration.
func (Config) ParseEndpoint ¶
ParseEndpoint takes the endpoint or signal endpoint, augments as needed (e.g. bare host:port for gRPC) and then parses as a URL. https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#endpoint-urls-for-otlphttp
func (Config) ParseExecCommandTimeout ¶
ParseExecCommandTimeout parses the --command-timeout string value to a time.Duration. When timeout is unspecified or 0, otel-cli will wait forever for the command to complete.
func (Config) ParseSpanEndTime ¶
ParseSpanEndTime returns config.SpanEndTime as time.Time.
func (Config) ParseSpanStartTime ¶
ParseSpanStartTime returns config.SpanStartTime as time.Time.
func (Config) ParseStatusCanaryInterval ¶
ParseStatusCanaryInterval parses the --canary-interval string value to a time.Duration.
func (Config) ParsedEventTime ¶
ParsedEventTime returns config.EventTime as time.Time.
func (Config) PropagateTraceparent ¶
PropagateTraceparent saves the traceparent to file if necessary, then prints span info to the console according to command-line args.
func (Config) SoftFail ¶
SoftFail calls through to softLog (which logs only if otel-cli was run with the --verbose flag), then immediately exits - with status -1 by default, or 1 if --fail was set (a la `curl --fail`)
func (Config) SoftFailIfErr ¶
SoftFailIfErr calls SoftFail only if err != nil. Written as an interim step to pushing errors up the stack instead of calling SoftLog/SoftFail directly in methods that don't need a config handle.
func (Config) SoftLog ¶
SoftLog only calls through to log if otel-cli was run with the --verbose flag. TODO: does it make any sense to support %w? probably yes, can clean up some diagnostics.Error touch points.
func (Config) SoftLogIfErr ¶
SoftLogIfErr calls SoftLog only if err != nil. Written as an interim step to pushing errors up the stack instead of calling SoftLog/SoftFail directly in methods that don't need a config handle.
func (Config) ToStringMap ¶
ToStringMap flattens the configuration into a stringmap that is easy to work with in tests especially with cmp.Diff. See test_main.go.
func (Config) WithAttributes ¶
WithAttributes returns the config with Attributes set to the provided value.
func (Config) WithBackgroundParentPollMs ¶
WithBackgroundParentPollMs returns the config with BackgroundParentPollMs set to the provided value.
func (Config) WithBackgroundSkipParentPidCheck ¶
WithBackgroundSkipParentPidCheck returns the config with BackgroundSkipParentPidCheck set to the provided value.
func (Config) WithBackgroundSockdir ¶
WithBackgroundSockdir returns the config with BackgroundSockdir set to the provided value.
func (Config) WithBackgroundWait ¶
WithBackgroundWait returns the config with BackgroundWait set to the provided value.
func (Config) WithBlocking ¶
WithBlocking returns the config with Blocking set to the provided value.
func (Config) WithCfgFile ¶
WithCfgFile returns the config with CfgFile set to the provided value.
func (Config) WithEndpoint ¶
WithEndpoint returns the config with Endpoint set to the provided value.
func (Config) WithEventName ¶
WithEventName returns the config with EventName set to the provided value.
func (Config) WithEventTime ¶
WithEventTIme returns the config with EventTIme set to the provided value.
func (Config) WithHeaders ¶
WithHeades returns the config with Heades set to the provided value.
func (Config) WithInsecure ¶
WithInsecure returns the config with Insecure set to the provided value.
func (Config) WithProtocol ¶
WithProtocol returns the config with protocol set to the provided value.
func (Config) WithServiceName ¶
WithServiceName returns the config with ServiceName set to the provided value.
func (Config) WithSpanEndTime ¶
WithSpanEndTime returns the config with SpanEndTime set to the provided value.
func (Config) WithSpanName ¶
WithSpanName returns the config with SpanName set to the provided value.
func (Config) WithSpanStartTime ¶
WithSpanStartTime returns the config with SpanStartTime set to the provided value.
func (Config) WithStatusCanaryCount ¶
WithStatusCanaryCount returns the config with StatusCanaryCount set to the provided value.
func (Config) WithStatusCanaryInterval ¶
WithStatusCanaryInterval returns the config with StatusCanaryInterval set to the provided value.
func (Config) WithStatusCode ¶
WithStatusCode returns the config with StatusCode set to the provided value.
func (Config) WithStatusDescription ¶
WithStatusDescription returns the config with StatusDescription set to the provided value.
func (Config) WithTimeout ¶
WithTimeout returns the config with Timeout set to the provided value.
func (Config) WithTlsCACert ¶
WithTlsCACert returns the config with TlsCACert set to the provided value.
func (Config) WithTlsClientCert ¶
WithTlsClientCert returns the config with NoTlsClientCert set to the provided value.
func (Config) WithTlsClientKey ¶
WithTlsClientKey returns the config with NoTlsClientKey set to the provided value.
func (Config) WithTlsNoVerify ¶
WithTlsNoVerify returns the config with NoTlsVerify set to the provided value.
func (Config) WithTraceparentCarrierFile ¶
WithTraceparentCarrierFile returns the config with TraceparentCarrierFile set to the provided value.
func (Config) WithTraceparentIgnoreEnv ¶
WithTraceparentIgnoreEnv returns the config with TraceparentIgnoreEnv set to the provided value.
func (Config) WithTraceparentPrint ¶
WithTraceparentPrint returns the config with TraceparentPrint set to the provided value.
func (Config) WithTraceparentPrintExport ¶
WithTraceparentPrintExport returns the config with TraceparentPrintExport set to the provided value.
func (Config) WithTraceparentRequired ¶
WithTraceparentRequired returns the config with TraceparentRequired set to the provided value.
func (Config) WithTracesEndpoint ¶
WithTracesEndpoint returns the config with TracesEndpoint set to the provided value.
func (Config) WithVerbose ¶
WithVerbose returns the config with Verbose set to the provided value.
func (Config) WithVersion ¶
WithVersion returns the config with Version set to the provided value.
type Diagnostics ¶
type Diagnostics struct {
CliArgs []string `json:"cli_args"`
IsRecording bool `json:"is_recording"`
ConfigFileLoaded bool `json:"config_file_loaded"`
NumArgs int `json:"number_of_args"`
DetectedLocalhost bool `json:"detected_localhost"`
InsecureSkipVerify bool `json:"insecure_skip_verify"`
ParsedTimeoutMs int64 `json:"parsed_timeout_ms"`
Endpoint string `json:"endpoint"` // the computed endpoint, not the raw config val
EndpointSource string `json:"endpoint_source"`
Error string `json:"error"`
ExecExitCode int `json:"exec_exit_code"`
Retries int `json:"retries"`
}
Diagnostics is a place to put things that are useful for testing and diagnosing issues with otel-cli. The only user-facing feature that should be using these is otel-cli status.
var Diag Diagnostics
package global Diagnostics handle, written to from all over otel-cli and used in e.g. otel-cli status to show internal state
func (*Diagnostics) SetError ¶
func (d *Diagnostics) SetError(err error) error
SetError sets the diagnostics Error to the error's string if it's not nil and returns the same error so it can be inlined in return.
func (*Diagnostics) ToStringMap ¶
func (d *Diagnostics) ToStringMap() map[string]string
ToMap returns the Diag struct as a string map for testing.
type SpanEventUnion ¶
type SpanEventUnion struct {
Span *tracepb.Span
Event *tracepb.Span_Event
}
SpanEventUnion is for server_tui so it can sort spans and events together by timestamp.
func (*SpanEventUnion) IsSpan ¶
func (seu *SpanEventUnion) IsSpan() bool
IsSpan returns true if this union is for an event. Span is always populated but Event is only populated for events.
func (*SpanEventUnion) SpanIdString ¶
func (seu *SpanEventUnion) SpanIdString() string
func (*SpanEventUnion) TraceIdString ¶
func (seu *SpanEventUnion) TraceIdString() string
func (*SpanEventUnion) UnixNanos ¶
func (seu *SpanEventUnion) UnixNanos() uint64
type SpanEventUnionList ¶
type SpanEventUnionList []SpanEventUnion
SpanEventUnionList is a sortable list of SpanEventUnion, sorted on timestamp.
func (SpanEventUnionList) Len ¶
func (sl SpanEventUnionList) Len() int
func (SpanEventUnionList) Less ¶
func (sl SpanEventUnionList) Less(i, j int) bool
func (SpanEventUnionList) Swap ¶
func (sl SpanEventUnionList) Swap(i, j int)
type StatusOutput ¶
type StatusOutput struct {
Config Config `json:"config"`
Spans []map[string]string `json:"spans"`
SpanData map[string]string `json:"span_data"`
Env map[string]string `json:"env"`
Diagnostics Diagnostics `json:"diagnostics"`
Errors otlpclient.ErrorList `json:"errors"`
}
StatusOutput captures all the data we want to print out for this subcommand and is also used in ../main_test.go for automated testing.