This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new a638cc00b feat(config): add Insecure option to tracing configuration
(#3028)
a638cc00b is described below
commit a638cc00b22b457c01160bf5a8a03561c5ddc34f
Author: Xuetao Li <[email protected]>
AuthorDate: Thu Sep 18 09:28:23 2025 +0800
feat(config): add Insecure option to tracing configuration (#3028)
---
compat.go | 2 ++
config/otel_config.go | 2 ++
global/otel_config.go | 2 ++
otel/trace/exporter.go | 1 +
otel/trace/options.go | 6 ++++++
otel/trace/otlp/exporter.go | 13 ++++++++++++-
6 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/compat.go b/compat.go
index 730eb3367..970f72c41 100644
--- a/compat.go
+++ b/compat.go
@@ -388,6 +388,7 @@ func compatOtelConfig(c *global.OtelConfig)
*config.OtelConfig {
Propagator: c.TracingConfig.Propagator,
SampleMode: c.TracingConfig.SampleMode,
SampleRatio: c.TracingConfig.SampleRatio,
+ Insecure: c.TracingConfig.Insecure,
},
}
}
@@ -903,6 +904,7 @@ func compatGlobalOtelConfig(c *config.OtelConfig)
*global.OtelConfig {
Propagator: c.TraceConfig.Propagator,
SampleMode: c.TraceConfig.SampleMode,
SampleRatio: c.TraceConfig.SampleRatio,
+ Insecure: c.TraceConfig.Insecure,
},
}
}
diff --git a/config/otel_config.go b/config/otel_config.go
index 9e0c600a0..cf7a352e4 100644
--- a/config/otel_config.go
+++ b/config/otel_config.go
@@ -43,6 +43,7 @@ type OtelTraceConfig struct {
Propagator string `default:"w3c" yaml:"propagator"
json:"propagator,omitempty" property:"propagator"` // one of
w3c(standard), b3(for zipkin),
SampleMode string `default:"ratio" yaml:"sample-mode"
json:"sample-mode,omitempty" property:"sample-mode"` // one of always, never,
ratio
SampleRatio float64 `default:"0.5" yaml:"sample-ratio"
json:"sample-ratio,omitempty" property:"sample-ratio"` // [0.0, 1.0]
+ Insecure bool `default:"false" yaml:"insecure"
json:"insecure,omitempty" property:"insecure"`
}
func (oc *OtelConfig) Init(appConfig *ApplicationConfig) error {
@@ -95,6 +96,7 @@ func (c *OtelTraceConfig) toTraceProviderConfig(a
*ApplicationConfig) *trace.Exp
ServiceNamespace: a.Organization,
ServiceName: a.Name,
ServiceVersion: a.Version,
+ Insecure: c.Insecure,
}
return tpc
}
diff --git a/global/otel_config.go b/global/otel_config.go
index fd4bbf243..5634a952b 100644
--- a/global/otel_config.go
+++ b/global/otel_config.go
@@ -29,6 +29,7 @@ type OtelTraceConfig struct {
Propagator string `default:"w3c" yaml:"propagator"
json:"propagator,omitempty" property:"propagator"` // one of
w3c(standard), b3(for zipkin),
SampleMode string `default:"ratio" yaml:"sample-mode"
json:"sample-mode,omitempty" property:"sample-mode"` // one of always, never,
ratio
SampleRatio float64 `default:"0.5" yaml:"sample-ratio"
json:"sample-ratio,omitempty" property:"sample-ratio"` // [0.0, 1.0]
+ Insecure bool `default:"false" yaml:"insecure"
json:"insecure,omitempty" property:"insecure"`
}
func DefaultOtelConfig() *OtelConfig {
@@ -67,5 +68,6 @@ func (c *OtelTraceConfig) Clone() *OtelTraceConfig {
Propagator: c.Propagator,
SampleMode: c.SampleMode,
SampleRatio: c.SampleRatio,
+ Insecure: c.Insecure,
}
}
diff --git a/otel/trace/exporter.go b/otel/trace/exporter.go
index e14afe7ad..ee3ec2d48 100644
--- a/otel/trace/exporter.go
+++ b/otel/trace/exporter.go
@@ -44,6 +44,7 @@ type ExporterConfig struct {
ServiceNamespace string
ServiceName string
ServiceVersion string
+ Insecure bool
}
type Exporter interface {
diff --git a/otel/trace/options.go b/otel/trace/options.go
index be310879d..0e2ce9aa7 100644
--- a/otel/trace/options.go
+++ b/otel/trace/options.go
@@ -138,3 +138,9 @@ func WithEndpoint(endpoint string) Option {
opts.Otel.TracingConfig.Endpoint = endpoint
}
}
+
+func WithInsecure() Option {
+ return func(opts *Options) {
+ opts.Otel.TracingConfig.Insecure = true
+ }
+}
diff --git a/otel/trace/otlp/exporter.go b/otel/trace/otlp/exporter.go
index ecf2f3812..e7a7d47c4 100644
--- a/otel/trace/otlp/exporter.go
+++ b/otel/trace/otlp/exporter.go
@@ -57,7 +57,18 @@ func newHttpExporter(config *trace.ExporterConfig)
(trace.Exporter, error) {
if httpInstance == nil {
initHttpOnce.Do(func() {
customFunc := func() (sdktrace.SpanExporter, error) {
- client :=
otlptracehttp.NewClient(otlptracehttp.WithEndpoint(config.Endpoint))
+ var client otlptrace.Client
+ if config.Insecure {
+ client = otlptracehttp.NewClient(
+
otlptracehttp.WithEndpoint(config.Endpoint),
+ otlptracehttp.WithInsecure(),
+ )
+ } else {
+ client = otlptracehttp.NewClient(
+
otlptracehttp.WithEndpoint(config.Endpoint),
+ )
+ }
+
return otlptrace.New(context.Background(),
client)
}