Skip to content

Commit 26764ce

Browse files
shunjiazhusjy3
authored andcommitted
print log if there is no exporter when plugin is enabled
1 parent 1bce7c1 commit 26764ce

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

examples/observability/config.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
observability:
2-
opentelemetry:
3-
enable_metrics: true
4-
file:
5-
path: ./go_output.txt
6-
apmplus:
7-
endpoint: "http://apmplus-cn-beijing.volces.com:4317"
8-
api_key: ""
9-
service_name: "veadk.go.demo"
10-

observability/exporter.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ func NewFileExporter(ctx context.Context, cfg *configs.FileConfig) (trace.SpanEx
177177
// NewMultiExporter creates a span exporter that can export to multiple platforms simultaneously.
178178
func NewMultiExporter(ctx context.Context, cfg *configs.OpenTelemetryConfig) (trace.SpanExporter, error) {
179179
var exporters []trace.SpanExporter
180-
// 1. Explicit Exporter Types (Stdout/File)
181180
if cfg.Stdout != nil && cfg.Stdout.Enable {
182181
if exp, err := NewStdoutExporter(); err == nil {
183182
exporters = append(exporters, exp)
@@ -192,20 +191,21 @@ func NewMultiExporter(ctx context.Context, cfg *configs.OpenTelemetryConfig) (tr
192191
}
193192
}
194193

195-
// 2. Platform Exporters (Can be multiple)
196-
if cfg.CozeLoop != nil && cfg.CozeLoop.APIKey != "" {
197-
if exp, err := NewCozeLoopExporter(ctx, cfg.CozeLoop); err == nil {
194+
if cfg.ApmPlus != nil && cfg.ApmPlus.Endpoint != "" && cfg.ApmPlus.APIKey != "" {
195+
if exp, err := NewAPMPlusExporter(ctx, cfg.ApmPlus); err == nil {
198196
exporters = append(exporters, exp)
199-
log.Info("Exporting spans to CozeLoop", "endpoint", cfg.CozeLoop.Endpoint, "service_name", cfg.CozeLoop.ServiceName)
197+
log.Info("Exporting spans to APMPlus", "endpoint", cfg.ApmPlus.Endpoint, "service_name", cfg.ApmPlus.ServiceName)
200198
}
201199
}
202-
if cfg.ApmPlus != nil && cfg.ApmPlus.APIKey != "" {
203-
if exp, err := NewAPMPlusExporter(ctx, cfg.ApmPlus); err == nil {
200+
201+
if cfg.CozeLoop != nil && cfg.CozeLoop.Endpoint != "" && cfg.CozeLoop.APIKey != "" {
202+
if exp, err := NewCozeLoopExporter(ctx, cfg.CozeLoop); err == nil {
204203
exporters = append(exporters, exp)
205-
log.Info("Exporting spans to APMPlus", "endpoint", cfg.ApmPlus.Endpoint, "service_name", cfg.ApmPlus.ServiceName)
204+
log.Info("Exporting spans to CozeLoop", "endpoint", cfg.CozeLoop.Endpoint, "service_name", cfg.CozeLoop.ServiceName)
206205
}
207206
}
208-
if cfg.TLS != nil && cfg.TLS.AccessKey != "" && cfg.TLS.SecretKey != "" {
207+
208+
if cfg.TLS != nil && cfg.TLS.Endpoint != "" && cfg.TLS.AccessKey != "" && cfg.TLS.SecretKey != "" {
209209
if exp, err := NewTLSExporter(ctx, cfg.TLS); err == nil {
210210
exporters = append(exporters, exp)
211211
log.Info("Exporting spans to TLS", "endpoint", cfg.TLS.Endpoint, "service_name", cfg.TLS.ServiceName)
@@ -214,6 +214,10 @@ func NewMultiExporter(ctx context.Context, cfg *configs.OpenTelemetryConfig) (tr
214214

215215
log.Debug("trace data will be exported", "exporter count", len(exporters))
216216

217+
if len(exporters) == 0 {
218+
log.Info("No exporters to export observability data")
219+
}
220+
217221
if len(exporters) == 1 {
218222
return exporters[0], nil
219223
}
@@ -263,7 +267,7 @@ func NewMetricReader(ctx context.Context, cfg *configs.OpenTelemetryConfig) ([]s
263267
}
264268
}
265269

266-
if cfg.ApmPlus != nil && cfg.ApmPlus.APIKey != "" {
270+
if cfg.ApmPlus != nil && cfg.ApmPlus.Endpoint != "" && cfg.ApmPlus.APIKey != "" {
267271
if exp, err := NewAPMPlusMetricExporter(ctx, cfg.ApmPlus); err == nil {
268272
readers = append(readers, sdkmetric.NewPeriodicReader(exp))
269273
log.Info("Exporting metrics to APMPlus", "endpoint", cfg.ApmPlus.Endpoint, "service_name", cfg.ApmPlus.ServiceName)

0 commit comments

Comments
 (0)