otelcli

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute()

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 to the rootCmd.

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.

Types

type BgEnd

type BgEnd struct{}

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.

func (BgSpan) End

func (bs BgSpan) End(in *BgEnd, reply *BgSpan) error

End takes a BgEnd (empty) struct, replies with the usual trace info, then ends the span end exits the background process.

func (BgSpan) Wait

func (bs BgSpan) Wait(in, reply *struct{}) error

Wait is a no-op RPC for validating the background server is up and running.

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"`
	Timeout     string            `json:"timeout"`
	Headers     map[string]string `json:"headers"` // TODO: needs json marshaler hook to mask tokens
	Insecure    bool              `json:"insecure"`
	Blocking    bool              `json:"blocking"`
	NoTlsVerify bool              `json:"no_tls_verify"`

	ServiceName string            `json:"service_name"`
	SpanName    string            `json:"span_name"`
	Kind        string            `json:"span_kind"`
	Attributes  map[string]string `json:"span_attributes"`

	TraceparentCarrierFile string `json:"traceparent_carrier_file"`
	TraceparentIgnoreEnv   bool   `json:"traceparent_ignore_env"`
	TraceparentPrint       bool   `json:"traceparent_print"`
	TraceparentPrintExport bool   `json:"traceparent_print_export"`
	TraceparentRequired    bool   `json:"traceparent_required"`

	BackgroundParentPollMs int    `json:"background_parent_poll_ms"`
	BackgroundSockdir      string `json:"background_socket_directory"`
	BackgroundWait         bool   `json:"background_wait"`

	SpanStartTime string `json:"span_start_time"`
	SpanEndTime   string `json:"span_end_time"`
	EventName     string `json:"event_name"`
	EventTime     string `json:"event_time"`

	CfgFile string `json:"config_file"`
	Verbose bool   `json:"verbose"`
}

Config stores the runtime configuration for otel-cli. This is used as a singleton as "config" and accessed from many other files. 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) ToStringMap

func (c Config) ToStringMap() map[string]string

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) UnmarshalJSON

func (c *Config) UnmarshalJSON(js []byte) error

UnmarshalJSON makes sure that any Config loaded from JSON has its default values set. This is critical to comparisons in the otel-cli test suite.

func (Config) WithAttributes

func (c Config) WithAttributes(with map[string]string) Config

WithAttributes returns the config with Attributes set to the provided value.

func (Config) WithBackgroundParentPollMs

func (c Config) WithBackgroundParentPollMs(with int) Config

WithBackgroundParentPollMs returns the config with BackgroundParentPollMs set to the provided value.

func (Config) WithBackgroundSockdir

func (c Config) WithBackgroundSockdir(with string) Config

WithBackgroundSockdir returns the config with BackgroundSockdir set to the provided value.

func (Config) WithBackgroundWait

func (c Config) WithBackgroundWait(with bool) Config

WithBackgroundWait returns the config with BackgroundWait set to the provided value.

func (Config) WithBlocking

func (c Config) WithBlocking(with bool) Config

WithBlocking returns the config with Blocking set to the provided value.

func (Config) WithCfgFile

func (c Config) WithCfgFile(with string) Config

WithCfgFile returns the config with CfgFile set to the provided value.

func (Config) WithEndpoint

func (c Config) WithEndpoint(with string) Config

WithEndpoint returns the config with Endpoint set to the provided value.

func (Config) WithEventName

func (c Config) WithEventName(with string) Config

WithEventName returns the config with EventName set to the provided value.

func (Config) WithEventTime

func (c Config) WithEventTime(with string) Config

WithEventTIme returns the config with EventTIme set to the provided value.

func (Config) WithHeaders

func (c Config) WithHeaders(with map[string]string) Config

WithHeades returns the config with Heades set to the provided value.

func (Config) WithInsecure

func (c Config) WithInsecure(with bool) Config

WithInsecure returns the config with Insecure set to the provided value.

func (Config) WithKind

func (c Config) WithKind(with string) Config

WithKind returns the config with Kind set to the provided value.

func (Config) WithNoTlsVerify

func (c Config) WithNoTlsVerify(with bool) Config

WithNoTlsVerify returns the config with NoTlsVerify set to the provided value.

func (Config) WithServiceName

func (c Config) WithServiceName(with string) Config

WithServiceName returns the config with ServiceName set to the provided value.

func (Config) WithSpanEndTime

func (c Config) WithSpanEndTime(with string) Config

WithSpanEndTime returns the config with SpanEndTime set to the provided value.

func (Config) WithSpanName

func (c Config) WithSpanName(with string) Config

WithSpanName returns the config with SpanName set to the provided value.

func (Config) WithSpanStartTime

func (c Config) WithSpanStartTime(with string) Config

WithSpanStartTime returns the config with SpanStartTime set to the provided value.

func (Config) WithTimeout

func (c Config) WithTimeout(with string) Config

WithTimeout returns the config with Timeout set to the provided value.

func (Config) WithTraceparentCarrierFile

func (c Config) WithTraceparentCarrierFile(with string) Config

WithTraceparentCarrierFile returns the config with TraceparentCarrierFile set to the provided value.

func (Config) WithTraceparentIgnoreEnv

func (c Config) WithTraceparentIgnoreEnv(with bool) Config

WithTraceparentIgnoreEnv returns the config with TraceparentIgnoreEnv set to the provided value.

func (Config) WithTraceparentPrint

func (c Config) WithTraceparentPrint(with bool) Config

WithTraceparentPrint returns the config with TraceparentPrint set to the provided value.

func (Config) WithTraceparentPrintExport

func (c Config) WithTraceparentPrintExport(with bool) Config

WithTraceparentPrintExport returns the config with TraceparentPrintExport set to the provided value.

func (Config) WithTraceparentRequired

func (c Config) WithTraceparentRequired(with bool) Config

WithTraceparentRequired returns the config with TraceparentRequired set to the provided value.

func (Config) WithVerbose

func (c Config) WithVerbose(with bool) Config

WithVerbose returns the config with Verbose 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"`
	ParsedTimeoutMs   int64    `json:"parsed_timeout_ms"`
	OtelError         string   `json:"otel_error"`
	ExecExitCode      int      `json:"exec_exit_code"`
}

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.

func (Diagnostics) Handle

func (Diagnostics) Handle(err error)

Handle complies with the otel error handler interface to capture errors both for diagnostics and to make sure the error output goes through softLog so it doesn't pollute output of caller scripts. hack: ignores the Diagnostics assigned to it and writes to the global

func (*Diagnostics) ToStringMap

func (d *Diagnostics) ToStringMap() map[string]string

ToMap returns the Diagnostics struct as a string map for testing.

type OtelCliCarrier

type OtelCliCarrier struct{}

OtelCliCarrier implements the OpenTelemetry TextMapCarrier interface that supports only one key/value for the traceparent and does nothing else

func NewOtelCliCarrier

func NewOtelCliCarrier() OtelCliCarrier

func (OtelCliCarrier) Clear

func (ec OtelCliCarrier) Clear()

Clear sets the traceparent to empty string. Mainly for testing.

func (OtelCliCarrier) Get

func (ec OtelCliCarrier) Get(key string) string

Get returns the traceparent string if key is "traceparent" otherwise nothing

func (OtelCliCarrier) Keys

func (ec OtelCliCarrier) Keys() []string

Keys returns a list of strings containing just "traceparent"

func (OtelCliCarrier) Set

func (ec OtelCliCarrier) Set(key string, value string)

Set sets the global traceparent if key is "traceparent" otherwise nothing

type StatusOutput

type StatusOutput struct {
	Config      Config            `json:"config"`
	SpanData    map[string]string `json:"span_data"`
	Env         map[string]string `json:"env"`
	Diagnostics Diagnostics       `json:"diagnostics"`
}

StatusOutput captures all the data we want to print out for this subcommand and is also is used in ../main_test.go for automated testing.

Jump to

Keyboard shortcuts

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