/
config.go
763 lines (665 loc) · 25.5 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
package otelcli
import (
"encoding/csv"
"encoding/json"
"errors"
"fmt"
"log"
"net/url"
"os"
"path"
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"
)
var detectBrokenRFC3339PrefixRe *regexp.Regexp
var epochNanoTimeRE *regexp.Regexp
func init() {
detectBrokenRFC3339PrefixRe = regexp.MustCompile(`^\d{4}-\d{2}-\d{2} `)
epochNanoTimeRE = regexp.MustCompile(`^\d+\.\d+$`)
}
// DefaultConfig returns a Config with all defaults set.
func DefaultConfig() Config {
return Config{
Endpoint: "",
Protocol: "",
Timeout: "1s",
Headers: map[string]string{},
Insecure: false,
Blocking: false,
TlsNoVerify: false,
TlsCACert: "",
TlsClientKey: "",
TlsClientCert: "",
ServiceName: "otel-cli",
SpanName: "todo-generate-default-span-names",
Kind: "client",
ForceTraceId: "",
ForceSpanId: "",
ForceParentSpanId: "",
Attributes: map[string]string{},
TraceparentCarrierFile: "",
TraceparentIgnoreEnv: false,
TraceparentPrint: false,
TraceparentPrintExport: false,
TraceparentRequired: false,
BackgroundParentPollMs: 10,
BackgroundSockdir: "",
BackgroundWait: false,
BackgroundSkipParentPidCheck: false,
ExecCommandTimeout: "",
ExecTpDisableInject: false,
StatusCanaryCount: 1,
StatusCanaryInterval: "",
SpanStartTime: "now",
SpanEndTime: "now",
EventName: "todo-generate-default-event-names",
EventTime: "now",
CfgFile: "",
Verbose: false,
Fail: false,
StatusCode: "unset",
StatusDescription: "",
Version: "unset",
}
}
// Config stores the runtime configuration for otel-cli.
// Data structure is public so that it can serialize to json easily.
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:"-"`
}
// LoadFile reads the file specified by -c/--config and overwrites the
// current config values with any found in the file.
func (c *Config) LoadFile() error {
if c.CfgFile == "" {
return nil
}
js, err := os.ReadFile(c.CfgFile)
if err != nil {
return fmt.Errorf("failed to read file '%s': %w", c.CfgFile, err)
}
if err := json.Unmarshal(js, c); err != nil {
return fmt.Errorf("failed to parse json data in file '%s': %w", c.CfgFile, err)
}
return nil
}
// 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 (c *Config) LoadEnv(getenv func(string) string) error {
// loop over each field of the Config
structType := reflect.TypeOf(c).Elem()
cValue := reflect.ValueOf(c).Elem()
for i := 0; i < structType.NumField(); i++ {
field := structType.Field(i)
envVars := field.Tag.Get("env")
if envVars == "" {
continue
}
// a field can have multiple comma-delimiated env vars to look in
for _, envVar := range strings.Split(envVars, ",") {
// call the provided func(string)string provided to get the
// envvar, usually os.Getenv but can be a fake for testing
envVal := getenv(envVar)
if envVal == "" {
continue
}
// type switch and write the value into the struct
target := cValue.Field(i)
switch target.Interface().(type) {
case string:
target.SetString(envVal)
case int:
intVal, err := strconv.ParseInt(envVal, 10, 64)
if err != nil {
return fmt.Errorf("could not parse %s value %q as an int: %w", envVar, envVal, err)
}
target.SetInt(intVal)
case bool:
boolVal, err := strconv.ParseBool(envVal)
if err != nil {
return fmt.Errorf("could not parse %s value %q as an bool: %w", envVar, envVal, err)
}
target.SetBool(boolVal)
case map[string]string:
mapVal, err := parseCkvStringMap(envVal)
if err != nil {
return fmt.Errorf("could not parse %s value %q as a map: %w", envVar, envVal, err)
}
mapValVal := reflect.ValueOf(mapVal)
target.Set(mapValVal)
}
}
}
return nil
}
// ToStringMap flattens the configuration into a stringmap that is easy to work
// with in tests especially with cmp.Diff. See test_main.go.
func (c Config) ToStringMap() map[string]string {
return map[string]string{
"endpoint": c.Endpoint,
"protocol": c.Protocol,
"timeout": c.Timeout,
"headers": flattenStringMap(c.Headers, "{}"),
"insecure": strconv.FormatBool(c.Insecure),
"blocking": strconv.FormatBool(c.Blocking),
"tls_no_verify": strconv.FormatBool(c.TlsNoVerify),
"tls_ca_cert": c.TlsCACert,
"tls_client_key": c.TlsClientKey,
"tls_client_cert": c.TlsClientCert,
"service_name": c.ServiceName,
"span_name": c.SpanName,
"span_kind": c.Kind,
"span_attributes": flattenStringMap(c.Attributes, "{}"),
"span_status_code": c.StatusCode,
"span_status_description": c.StatusDescription,
"traceparent_carrier_file": c.TraceparentCarrierFile,
"traceparent_ignore_env": strconv.FormatBool(c.TraceparentIgnoreEnv),
"traceparent_print": strconv.FormatBool(c.TraceparentPrint),
"traceparent_print_export": strconv.FormatBool(c.TraceparentPrintExport),
"traceparent_required": strconv.FormatBool(c.TraceparentRequired),
"background_parent_poll_ms": strconv.Itoa(c.BackgroundParentPollMs),
"background_socket_directory": c.BackgroundSockdir,
"background_wait": strconv.FormatBool(c.BackgroundWait),
"background_skip_pid_check": strconv.FormatBool(c.BackgroundSkipParentPidCheck),
"exec_command_timeout": c.ExecCommandTimeout,
"exec_tp_disable_inject": strconv.FormatBool(c.ExecTpDisableInject),
"span_start_time": c.SpanStartTime,
"span_end_time": c.SpanEndTime,
"event_name": c.EventName,
"event_time": c.EventTime,
"config_file": c.CfgFile,
"verbose": strconv.FormatBool(c.Verbose),
}
}
// 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 (c Config) GetIsRecording() bool {
if c.Endpoint == "" && c.TracesEndpoint == "" {
Diag.IsRecording = false
return false
}
Diag.IsRecording = true
return true
}
// ParseCliTimeout parses the --timeout string value to a time.Duration.
func (c Config) ParseCliTimeout() time.Duration {
out, err := parseDuration(c.Timeout)
Diag.ParsedTimeoutMs = out.Milliseconds()
c.SoftFailIfErr(err)
return out
}
// 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 (c Config) ParseExecCommandTimeout() time.Duration {
if c.ExecCommandTimeout == "" {
return 0
}
out, err := parseDuration(c.ExecCommandTimeout)
c.SoftFailIfErr(err)
return out
}
// ParseStatusCanaryInterval parses the --canary-interval string value to a time.Duration.
func (c Config) ParseStatusCanaryInterval() time.Duration {
out, err := parseDuration(c.StatusCanaryInterval)
c.SoftFailIfErr(err)
return out
}
// parseDuration parses a string duration into a time.Duration.
// When no duration letter is provided (e.g. ms, s, m, h), seconds are assumed.
// It logs an error and returns time.Duration(0) if the string is empty or unparseable.
func parseDuration(d string) (time.Duration, error) {
var out time.Duration
if d == "" {
out = time.Duration(0)
} else if parsed, err := time.ParseDuration(d); err == nil {
out = parsed
} else if secs, serr := strconv.ParseInt(d, 10, 0); serr == nil {
out = time.Second * time.Duration(secs)
} else {
return time.Duration(0), fmt.Errorf("unable to parse duration string %q: %w", d, err)
}
return out, nil
}
// 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 Config) ParseEndpoint() (*url.URL, string) {
var endpoint, source string
var epUrl *url.URL
var err error
// signal-specific configs get precedence over general endpoint per OTel spec
if config.TracesEndpoint != "" {
endpoint = config.TracesEndpoint
source = "signal"
} else if config.Endpoint != "" {
endpoint = config.Endpoint
source = "general"
} else {
config.SoftFail("no endpoint configuration available")
}
parts := strings.Split(endpoint, ":")
// bare hostname? can only be grpc, prepend
if len(parts) == 1 {
epUrl, err = url.Parse("grpc://" + endpoint + ":4317")
if err != nil {
config.SoftFail("error parsing (assumed) gRPC bare host address '%s': %s", endpoint, err)
}
} else if len(parts) > 1 { // could be URI or host:port
// actual URIs
// grpc:// is only an otel-cli thing, maybe should drop it?
if parts[0] == "grpc" || parts[0] == "http" || parts[0] == "https" {
epUrl, err = url.Parse(endpoint)
if err != nil {
config.SoftFail("error parsing provided %s URI '%s': %s", source, endpoint, err)
}
} else {
// gRPC host:port
epUrl, err = url.Parse("grpc://" + endpoint)
if err != nil {
config.SoftFail("error parsing (assumed) gRPC host:port address '%s': %s", endpoint, err)
}
}
}
// Per spec, /v1/traces is the default, appended to any url passed
// to the general endpoint
if strings.HasPrefix(epUrl.Scheme, "http") && source != "signal" && !strings.HasSuffix(epUrl.Path, "/v1/traces") {
epUrl.Path = path.Join(epUrl.Path, "/v1/traces")
}
Diag.EndpointSource = source
Diag.Endpoint = epUrl.String()
return epUrl, source
}
// 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 (c Config) SoftLog(format string, a ...interface{}) {
if !c.Verbose {
return
}
log.Printf(format, a...)
}
// 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 (c Config) SoftLogIfErr(err error) {
if err != nil {
c.SoftLog(err.Error())
}
}
// 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 (c Config) SoftFail(format string, a ...interface{}) {
c.SoftLog(format, a...)
if c.Fail {
os.Exit(1)
} else {
os.Exit(0)
}
}
// 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 (c Config) SoftFailIfErr(err error) {
if err != nil {
c.SoftFail(err.Error())
}
}
// flattenStringMap takes a string map and returns it flattened into a string with
// keys sorted lexically so it should be mostly consistent enough for comparisons
// and printing. Output is k=v,k=v style like attributes input.
func flattenStringMap(mp map[string]string, emptyValue string) string {
if len(mp) == 0 {
return emptyValue
}
var out string
keys := make([]string, len(mp)) // for sorting
var i int
for k := range mp {
keys[i] = k
i++
}
sort.Strings(keys)
for i, k := range keys {
out = out + k + "=" + mp[k]
if i == len(keys)-1 {
break
}
out = out + ","
}
return out
}
// parseCkvStringMap parses key=value,foo=bar formatted strings as a line of CSV
// and returns it as a string map.
func parseCkvStringMap(in string) (map[string]string, error) {
r := csv.NewReader(strings.NewReader(in))
pairs, err := r.Read()
if err != nil {
return map[string]string{}, err
}
out := make(map[string]string)
for _, pair := range pairs {
parts := strings.SplitN(pair, "=", 2)
if parts[0] != "" && parts[1] != "" {
out[parts[0]] = parts[1]
} else {
return map[string]string{}, fmt.Errorf("kv pair %s must be in key=value format", pair)
}
}
return out, nil
}
// ParseSpanStartTime returns config.SpanStartTime as time.Time.
func (c Config) ParseSpanStartTime() time.Time {
t, err := c.parseTime(c.SpanStartTime, "start")
c.SoftFailIfErr(err)
return t
}
// ParseSpanEndTime returns config.SpanEndTime as time.Time.
func (c Config) ParseSpanEndTime() time.Time {
t, err := c.parseTime(c.SpanEndTime, "end")
c.SoftFailIfErr(err)
return t
}
// ParsedEventTime returns config.EventTime as time.Time.
func (c Config) ParsedEventTime() time.Time {
t, err := c.parseTime(c.EventTime, "event")
c.SoftFailIfErr(err)
return t
}
// parseTime tries to parse Unix epoch, then RFC3339, both with/without nanoseconds
func (c Config) parseTime(ts, which string) (time.Time, error) {
// errors accumulate as parsing methods are attempted
// thrown away when one succeeds, joined & returned if none succeed
errs := []error{}
if ts == "now" {
return time.Now(), nil
}
// Unix epoch time
if i, err := strconv.ParseInt(ts, 10, 64); err == nil {
return time.Unix(i, 0), nil
} else {
errs = append(errs, fmt.Errorf("could not parse span %s time %q as Unix Epoch: %w", which, ts, err))
}
// date --rfc-3339 returns an invalid format for Go because it has a
// space instead of 'T' between date and time
if detectBrokenRFC3339PrefixRe.MatchString(ts) {
ts = strings.Replace(ts, " ", "T", 1)
}
// Unix epoch time with nanoseconds
if epochNanoTimeRE.MatchString(ts) {
parts := strings.Split(ts, ".")
if len(parts) == 2 {
secs, secsErr := strconv.ParseInt(parts[0], 10, 64)
nsecs, usecsErr := strconv.ParseInt(parts[1], 10, 64)
if secsErr == nil && usecsErr == nil && secs > 0 {
return time.Unix(secs, nsecs), nil
} else {
errs = append(errs, fmt.Errorf("could not parse span %s time %q as Unix Epoch: %w", which, ts, secsErr))
errs = append(errs, fmt.Errorf("could not parse span %s time %q as Unix Epoch.Nano: %w", which, ts, usecsErr))
}
}
}
// try RFC3339 then again with nanos
t, err := time.Parse(time.RFC3339, ts)
if err != nil {
// try again with nanos
if t, innerErr := time.Parse(time.RFC3339Nano, ts); innerErr == nil {
return t, nil
} else {
errs = append(errs, fmt.Errorf("could not parse span %s time %q as RFC3339 %w", which, ts, err))
errs = append(errs, fmt.Errorf("could not parse span %s time %q as RFC3339Nano %w", which, ts, innerErr))
}
} else {
return t, nil
}
errs = append(errs, fmt.Errorf("could not parse span %s time %q as any supported format", which, ts))
return time.Time{}, errors.Join(errs...)
}
func (c Config) GetEndpoint() *url.URL {
ep, _ := c.ParseEndpoint()
return ep
}
// WithEndpoint returns the config with Endpoint set to the provided value.
func (c Config) WithEndpoint(with string) Config {
c.Endpoint = with
return c
}
// WithTracesEndpoint returns the config with TracesEndpoint set to the provided value.
func (c Config) WithTracesEndpoint(with string) Config {
c.TracesEndpoint = with
return c
}
// WithProtocol returns the config with protocol set to the provided value.
func (c Config) WithProtocol(with string) Config {
c.Protocol = with
return c
}
// GetTimeout returns the parsed --timeout value as a time.Duration.
func (c Config) GetTimeout() time.Duration {
return c.ParseCliTimeout()
}
// WithTimeout returns the config with Timeout set to the provided value.
func (c Config) WithTimeout(with string) Config {
c.Timeout = with
return c
}
// GetHeaders returns the stringmap of configured headers.
func (c Config) GetHeaders() map[string]string {
return c.Headers
}
// WithHeades returns the config with Heades set to the provided value.
func (c Config) WithHeaders(with map[string]string) Config {
c.Headers = with
return c
}
// WithInsecure returns the config with Insecure set to the provided value.
func (c Config) WithInsecure(with bool) Config {
c.Insecure = with
return c
}
// WithBlocking returns the config with Blocking set to the provided value.
func (c Config) WithBlocking(with bool) Config {
c.Blocking = with
return c
}
// WithTlsNoVerify returns the config with NoTlsVerify set to the provided value.
func (c Config) WithTlsNoVerify(with bool) Config {
c.TlsNoVerify = with
return c
}
// WithTlsCACert returns the config with TlsCACert set to the provided value.
func (c Config) WithTlsCACert(with string) Config {
c.TlsCACert = with
return c
}
// WithTlsClientKey returns the config with NoTlsClientKey set to the provided value.
func (c Config) WithTlsClientKey(with string) Config {
c.TlsClientKey = with
return c
}
// WithTlsClientCert returns the config with NoTlsClientCert set to the provided value.
func (c Config) WithTlsClientCert(with string) Config {
c.TlsClientCert = with
return c
}
// GetServiceName returns the configured OTel service name.
func (c Config) GetServiceName() string {
return c.ServiceName
}
// WithServiceName returns the config with ServiceName set to the provided value.
func (c Config) WithServiceName(with string) Config {
c.ServiceName = with
return c
}
// WithSpanName returns the config with SpanName set to the provided value.
func (c Config) WithSpanName(with string) Config {
c.SpanName = with
return c
}
// WithKind returns the config with Kind set to the provided value.
func (c Config) WithKind(with string) Config {
c.Kind = with
return c
}
// WithAttributes returns the config with Attributes set to the provided value.
func (c Config) WithAttributes(with map[string]string) Config {
c.Attributes = with
return c
}
// WithStatusCode returns the config with StatusCode set to the provided value.
func (c Config) WithStatusCode(with string) Config {
c.StatusCode = with
return c
}
// WithStatusDescription returns the config with StatusDescription set to the provided value.
func (c Config) WithStatusDescription(with string) Config {
c.StatusDescription = with
return c
}
// WithTraceparentCarrierFile returns the config with TraceparentCarrierFile set to the provided value.
func (c Config) WithTraceparentCarrierFile(with string) Config {
c.TraceparentCarrierFile = with
return c
}
// WithTraceparentIgnoreEnv returns the config with TraceparentIgnoreEnv set to the provided value.
func (c Config) WithTraceparentIgnoreEnv(with bool) Config {
c.TraceparentIgnoreEnv = with
return c
}
// WithTraceparentPrint returns the config with TraceparentPrint set to the provided value.
func (c Config) WithTraceparentPrint(with bool) Config {
c.TraceparentPrint = with
return c
}
// WithTraceparentPrintExport returns the config with TraceparentPrintExport set to the provided value.
func (c Config) WithTraceparentPrintExport(with bool) Config {
c.TraceparentPrintExport = with
return c
}
// WithTraceparentRequired returns the config with TraceparentRequired set to the provided value.
func (c Config) WithTraceparentRequired(with bool) Config {
c.TraceparentRequired = with
return c
}
// WithBackgroundParentPollMs returns the config with BackgroundParentPollMs set to the provided value.
func (c Config) WithBackgroundParentPollMs(with int) Config {
c.BackgroundParentPollMs = with
return c
}
// WithBackgroundSockdir returns the config with BackgroundSockdir set to the provided value.
func (c Config) WithBackgroundSockdir(with string) Config {
c.BackgroundSockdir = with
return c
}
// WithBackgroundWait returns the config with BackgroundWait set to the provided value.
func (c Config) WithBackgroundWait(with bool) Config {
c.BackgroundWait = with
return c
}
// WithBackgroundSkipParentPidCheck returns the config with BackgroundSkipParentPidCheck set to the provided value.
func (c Config) WithBackgroundSkipParentPidCheck(with bool) Config {
c.BackgroundSkipParentPidCheck = with
return c
}
// WithStatusCanaryCount returns the config with StatusCanaryCount set to the provided value.
func (c Config) WithStatusCanaryCount(with int) Config {
c.StatusCanaryCount = with
return c
}
// WithStatusCanaryInterval returns the config with StatusCanaryInterval set to the provided value.
func (c Config) WithStatusCanaryInterval(with string) Config {
c.StatusCanaryInterval = with
return c
}
// WithSpanStartTime returns the config with SpanStartTime set to the provided value.
func (c Config) WithSpanStartTime(with string) Config {
c.SpanStartTime = with
return c
}
// WithSpanEndTime returns the config with SpanEndTime set to the provided value.
func (c Config) WithSpanEndTime(with string) Config {
c.SpanEndTime = with
return c
}
// WithEventName returns the config with EventName set to the provided value.
func (c Config) WithEventName(with string) Config {
c.EventName = with
return c
}
// WithEventTIme returns the config with EventTIme set to the provided value.
func (c Config) WithEventTime(with string) Config {
c.EventTime = with
return c
}
// WithCfgFile returns the config with CfgFile set to the provided value.
func (c Config) WithCfgFile(with string) Config {
c.CfgFile = with
return c
}
// WithVerbose returns the config with Verbose set to the provided value.
func (c Config) WithVerbose(with bool) Config {
c.Verbose = with
return c
}
// WithFail returns the config with Fail set to the provided value.
func (c Config) WithFail(with bool) Config {
c.Fail = with
return c
}
// Version returns the program version stored in the config.
func (c Config) GetVersion() string {
return c.Version
}
// WithVersion returns the config with Version set to the provided value.
func (c Config) WithVersion(with string) Config {
c.Version = with
return c
}