forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connector.go
642 lines (536 loc) · 23.9 KB
/
connector.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package connector // import "go.opentelemetry.io/collector/connector"
import (
"context"
"fmt"
"go.uber.org/zap"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
)
// A Traces connector acts as an exporter from a traces pipeline and a receiver
// to one or more traces, metrics, or logs pipelines.
// Traces feeds a consumer.Traces, consumer.Metrics, or consumer.Logs with data.
//
// Examples:
// - Traces could be collected in one pipeline and routed to another traces pipeline
// based on criteria such as attributes or other content of the trace. The second
// pipeline can then process and export the trace to the appropriate backend.
// - Traces could be summarized by a metrics connector that emits statistics describing
// the number of traces observed.
// - Traces could be analyzed by a logs connector that emits events when particular
// criteria are met.
type Traces interface {
component.Component
consumer.Traces
}
// TracesRouter feeds the first consumer.Traces in each of the specified pipelines.
// The router will create a fanout consumer for the set of pipelines and return a uuid
type TracesRouter interface {
Consumer(...component.ID) (consumer.Traces, error)
PipelineIDs() []component.ID
}
// A Metrics connector acts as an exporter from a metrics pipeline and a receiver
// to one or more traces, metrics, or logs pipelines.
// Metrics feeds a consumer.Traces, consumer.Metrics, or consumer.Logs with data.
//
// Examples:
// - Latency between related data points could be modeled and emitted as traces.
// - Metrics could be collected in one pipeline and routed to another metrics pipeline
// based on criteria such as attributes or other content of the metric. The second
// pipeline can then process and export the metric to the appropriate backend.
// - Metrics could be analyzed by a logs connector that emits events when particular
// criteria are met.
type Metrics interface {
component.Component
consumer.Metrics
}
// MetricsRouter feeds the first consumer.Metrics in each of the specified pipelines.
type MetricsRouter interface {
Consumer(...component.ID) (consumer.Metrics, error)
PipelineIDs() []component.ID
}
// A Logs connector acts as an exporter from a logs pipeline and a receiver
// to one or more traces, metrics, or logs pipelines.
// Logs feeds a consumer.Logs, consumer.Metrics, or consumer.Logs with data.
//
// Examples:
// - Structured logs containing span information could be consumed and emitted as traces.
// - Metrics could be extracted from structured logs that contain numeric data.
// - Logs could be collected in one pipeline and routed to another logs pipeline
// based on criteria such as attributes or other content of the log. The second
// pipeline can then process and export the log to the appropriate backend.
type Logs interface {
component.Component
consumer.Logs
}
// LogsRouter feeds the first consumer.Logs in each of the specified pipelines.
type LogsRouter interface {
Consumer(...component.ID) (consumer.Logs, error)
PipelineIDs() []component.ID
}
// CreateSettings configures Connector creators.
type CreateSettings struct {
// ID returns the ID of the component that will be created.
ID component.ID
component.TelemetrySettings
// BuildInfo can be used by components for informational purposes
BuildInfo component.BuildInfo
}
// Factory is factory interface for connectors.
//
// This interface cannot be directly implemented. Implementations must
// use the NewFactory to implement it.
type Factory interface {
component.Factory
// CreateDefaultConfig creates the default configuration for the Connector.
// This method can be called multiple times depending on the pipeline
// configuration and should not cause side-effects that prevent the creation
// of multiple instances of the Connector.
// The object returned by this method needs to pass the checks implemented by
// 'configtest.CheckConfigStruct'. It is recommended to have these checks in the
// tests of any implementation of the Factory interface.
CreateDefaultConfig() component.Config
CreateTracesToTraces(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (Traces, error)
CreateTracesToMetrics(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (Traces, error)
CreateTracesToLogs(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Logs) (Traces, error)
CreateMetricsToTraces(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (Metrics, error)
CreateMetricsToMetrics(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (Metrics, error)
CreateMetricsToLogs(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Logs) (Metrics, error)
CreateLogsToTraces(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (Logs, error)
CreateLogsToMetrics(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (Logs, error)
CreateLogsToLogs(ctx context.Context, set CreateSettings, cfg component.Config, nextConsumer consumer.Logs) (Logs, error)
TracesToTracesStability() component.StabilityLevel
TracesToMetricsStability() component.StabilityLevel
TracesToLogsStability() component.StabilityLevel
MetricsToTracesStability() component.StabilityLevel
MetricsToMetricsStability() component.StabilityLevel
MetricsToLogsStability() component.StabilityLevel
LogsToTracesStability() component.StabilityLevel
LogsToMetricsStability() component.StabilityLevel
LogsToLogsStability() component.StabilityLevel
unexportedFactoryFunc()
}
// FactoryOption applies changes to Factory.
type FactoryOption interface {
// apply applies the option.
apply(o *factory)
}
var _ FactoryOption = (*factoryOptionFunc)(nil)
// factoryOptionFunc is an FactoryOption created through a function.
type factoryOptionFunc func(*factory)
func (f factoryOptionFunc) apply(o *factory) {
f(o)
}
// CreateTracesToTracesFunc is the equivalent of Factory.CreateTracesToTraces().
type CreateTracesToTracesFunc func(context.Context, CreateSettings, component.Config, consumer.Traces) (Traces, error)
// CreateTracesToTraces implements Factory.CreateTracesToTraces().
func (f CreateTracesToTracesFunc) CreateTracesToTraces(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces) (Traces, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeTraces, component.DataTypeTraces)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateTracesToMetricsFunc is the equivalent of Factory.CreateTracesToMetrics().
type CreateTracesToMetricsFunc func(context.Context, CreateSettings, component.Config, consumer.Metrics) (Traces, error)
// CreateTracesToMetrics implements Factory.CreateTracesToMetrics().
func (f CreateTracesToMetricsFunc) CreateTracesToMetrics(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (Traces, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeTraces, component.DataTypeMetrics)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateTracesToLogsFunc is the equivalent of Factory.CreateTracesToLogs().
type CreateTracesToLogsFunc func(context.Context, CreateSettings, component.Config, consumer.Logs) (Traces, error)
// CreateTracesToLogs implements Factory.CreateTracesToLogs().
func (f CreateTracesToLogsFunc) CreateTracesToLogs(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Logs,
) (Traces, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeTraces, component.DataTypeLogs)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateMetricsToTracesFunc is the equivalent of Factory.CreateMetricsToTraces().
type CreateMetricsToTracesFunc func(context.Context, CreateSettings, component.Config, consumer.Traces) (Metrics, error)
// CreateMetricsToTraces implements Factory.CreateMetricsToTraces().
func (f CreateMetricsToTracesFunc) CreateMetricsToTraces(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces,
) (Metrics, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeMetrics, component.DataTypeTraces)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateMetricsToMetricsFunc is the equivalent of Factory.CreateMetricsToTraces().
type CreateMetricsToMetricsFunc func(context.Context, CreateSettings, component.Config, consumer.Metrics) (Metrics, error)
// CreateMetricsToMetrics implements Factory.CreateMetricsToTraces().
func (f CreateMetricsToMetricsFunc) CreateMetricsToMetrics(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (Metrics, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeMetrics, component.DataTypeMetrics)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateMetricsToLogsFunc is the equivalent of Factory.CreateMetricsToLogs().
type CreateMetricsToLogsFunc func(context.Context, CreateSettings, component.Config, consumer.Logs) (Metrics, error)
// CreateMetricsToLogs implements Factory.CreateMetricsToLogs().
func (f CreateMetricsToLogsFunc) CreateMetricsToLogs(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Logs,
) (Metrics, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeMetrics, component.DataTypeLogs)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateLogsToTracesFunc is the equivalent of Factory.CreateLogsToTraces().
type CreateLogsToTracesFunc func(context.Context, CreateSettings, component.Config, consumer.Traces) (Logs, error)
// CreateLogsToTraces implements Factory.CreateLogsToTraces().
func (f CreateLogsToTracesFunc) CreateLogsToTraces(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Traces,
) (Logs, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeLogs, component.DataTypeTraces)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateLogsToMetricsFunc is the equivalent of Factory.CreateLogsToMetrics().
type CreateLogsToMetricsFunc func(context.Context, CreateSettings, component.Config, consumer.Metrics) (Logs, error)
// CreateLogsToMetrics implements Factory.CreateLogsToMetrics().
func (f CreateLogsToMetricsFunc) CreateLogsToMetrics(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (Logs, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeLogs, component.DataTypeMetrics)
}
return f(ctx, set, cfg, nextConsumer)
}
// CreateLogsToLogsFunc is the equivalent of Factory.CreateLogsToLogs().
type CreateLogsToLogsFunc func(context.Context, CreateSettings, component.Config, consumer.Logs) (Logs, error)
// CreateLogsToLogs implements Factory.CreateLogsToLogs().
func (f CreateLogsToLogsFunc) CreateLogsToLogs(
ctx context.Context,
set CreateSettings,
cfg component.Config,
nextConsumer consumer.Logs,
) (Logs, error) {
if f == nil {
return nil, errDataTypes(set.ID, component.DataTypeLogs, component.DataTypeLogs)
}
return f(ctx, set, cfg, nextConsumer)
}
// factory implements Factory.
type factory struct {
cfgType component.Type
component.CreateDefaultConfigFunc
CreateTracesToTracesFunc
CreateTracesToMetricsFunc
CreateTracesToLogsFunc
CreateMetricsToTracesFunc
CreateMetricsToMetricsFunc
CreateMetricsToLogsFunc
CreateLogsToTracesFunc
CreateLogsToMetricsFunc
CreateLogsToLogsFunc
tracesToTracesStabilityLevel component.StabilityLevel
tracesToMetricsStabilityLevel component.StabilityLevel
tracesToLogsStabilityLevel component.StabilityLevel
metricsToTracesStabilityLevel component.StabilityLevel
metricsToMetricsStabilityLevel component.StabilityLevel
metricsToLogsStabilityLevel component.StabilityLevel
logsToTracesStabilityLevel component.StabilityLevel
logsToMetricsStabilityLevel component.StabilityLevel
logsToLogsStabilityLevel component.StabilityLevel
}
// Type returns the type of component.
func (f *factory) Type() component.Type {
return f.cfgType
}
func (f *factory) unexportedFactoryFunc() {}
// WithTracesToTraces overrides the default "error not supported" implementation for WithTracesToTraces and the default "undefined" stability level.
func WithTracesToTraces(createTracesToTraces CreateTracesToTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.tracesToTracesStabilityLevel = sl
o.CreateTracesToTracesFunc = createTracesToTraces
})
}
// WithTracesToMetrics overrides the default "error not supported" implementation for WithTracesToMetrics and the default "undefined" stability level.
func WithTracesToMetrics(createTracesToMetrics CreateTracesToMetricsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.tracesToMetricsStabilityLevel = sl
o.CreateTracesToMetricsFunc = createTracesToMetrics
})
}
// WithTracesToLogs overrides the default "error not supported" implementation for WithTracesToLogs and the default "undefined" stability level.
func WithTracesToLogs(createTracesToLogs CreateTracesToLogsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.tracesToLogsStabilityLevel = sl
o.CreateTracesToLogsFunc = createTracesToLogs
})
}
// WithMetricsToTraces overrides the default "error not supported" implementation for WithMetricsToTraces and the default "undefined" stability level.
func WithMetricsToTraces(createMetricsToTraces CreateMetricsToTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.metricsToTracesStabilityLevel = sl
o.CreateMetricsToTracesFunc = createMetricsToTraces
})
}
// WithMetricsToMetrics overrides the default "error not supported" implementation for WithMetricsToMetrics and the default "undefined" stability level.
func WithMetricsToMetrics(createMetricsToMetrics CreateMetricsToMetricsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.metricsToMetricsStabilityLevel = sl
o.CreateMetricsToMetricsFunc = createMetricsToMetrics
})
}
// WithMetricsToLogs overrides the default "error not supported" implementation for WithMetricsToLogs and the default "undefined" stability level.
func WithMetricsToLogs(createMetricsToLogs CreateMetricsToLogsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.metricsToLogsStabilityLevel = sl
o.CreateMetricsToLogsFunc = createMetricsToLogs
})
}
// WithLogsToTraces overrides the default "error not supported" implementation for WithLogsToTraces and the default "undefined" stability level.
func WithLogsToTraces(createLogsToTraces CreateLogsToTracesFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.logsToTracesStabilityLevel = sl
o.CreateLogsToTracesFunc = createLogsToTraces
})
}
// WithLogsToMetrics overrides the default "error not supported" implementation for WithLogsToMetrics and the default "undefined" stability level.
func WithLogsToMetrics(createLogsToMetrics CreateLogsToMetricsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.logsToMetricsStabilityLevel = sl
o.CreateLogsToMetricsFunc = createLogsToMetrics
})
}
// WithLogsToLogs overrides the default "error not supported" implementation for WithLogsToLogs and the default "undefined" stability level.
func WithLogsToLogs(createLogsToLogs CreateLogsToLogsFunc, sl component.StabilityLevel) FactoryOption {
return factoryOptionFunc(func(o *factory) {
o.logsToLogsStabilityLevel = sl
o.CreateLogsToLogsFunc = createLogsToLogs
})
}
func (f factory) TracesToTracesStability() component.StabilityLevel {
return f.tracesToTracesStabilityLevel
}
func (f factory) TracesToMetricsStability() component.StabilityLevel {
return f.tracesToMetricsStabilityLevel
}
func (f factory) TracesToLogsStability() component.StabilityLevel {
return f.tracesToLogsStabilityLevel
}
func (f factory) MetricsToTracesStability() component.StabilityLevel {
return f.metricsToTracesStabilityLevel
}
func (f factory) MetricsToMetricsStability() component.StabilityLevel {
return f.metricsToMetricsStabilityLevel
}
func (f factory) MetricsToLogsStability() component.StabilityLevel {
return f.metricsToLogsStabilityLevel
}
func (f factory) LogsToTracesStability() component.StabilityLevel {
return f.logsToTracesStabilityLevel
}
func (f factory) LogsToMetricsStability() component.StabilityLevel {
return f.logsToMetricsStabilityLevel
}
func (f factory) LogsToLogsStability() component.StabilityLevel {
return f.logsToLogsStabilityLevel
}
// NewFactory returns a Factory.
func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
f := &factory{
cfgType: cfgType,
CreateDefaultConfigFunc: createDefaultConfig,
}
for _, opt := range options {
opt.apply(f)
}
return f
}
// MakeFactoryMap takes a list of connector factories and returns a map with factory type as keys.
// It returns a non-nil error when there are factories with duplicate type.
func MakeFactoryMap(factories ...Factory) (map[component.Type]Factory, error) {
fMap := map[component.Type]Factory{}
for _, f := range factories {
if _, ok := fMap[f.Type()]; ok {
return fMap, fmt.Errorf("duplicate connector factory %q", f.Type())
}
fMap[f.Type()] = f
}
return fMap, nil
}
// Builder processor is a helper struct that given a set of Configs and Factories helps with creating processors.
type Builder struct {
cfgs map[component.ID]component.Config
factories map[component.Type]Factory
}
// NewBuilder creates a new connector.Builder to help with creating components form a set of configs and factories.
func NewBuilder(cfgs map[component.ID]component.Config, factories map[component.Type]Factory) *Builder {
return &Builder{cfgs: cfgs, factories: factories}
}
// CreateTracesToTraces creates a Traces connector based on the settings and config.
func (b *Builder) CreateTracesToTraces(ctx context.Context, set CreateSettings, next consumer.Traces) (Traces, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.TracesToTracesStability())
return f.CreateTracesToTraces(ctx, set, cfg, next)
}
// CreateTracesToMetrics creates a Traces connector based on the settings and config.
func (b *Builder) CreateTracesToMetrics(ctx context.Context, set CreateSettings, next consumer.Metrics) (Traces, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.TracesToMetricsStability())
return f.CreateTracesToMetrics(ctx, set, cfg, next)
}
// CreateTracesToLogs creates a Traces connector based on the settings and config.
func (b *Builder) CreateTracesToLogs(ctx context.Context, set CreateSettings, next consumer.Logs) (Traces, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.TracesToLogsStability())
return f.CreateTracesToLogs(ctx, set, cfg, next)
}
// CreateMetricsToTraces creates a Metrics connector based on the settings and config.
func (b *Builder) CreateMetricsToTraces(ctx context.Context, set CreateSettings, next consumer.Traces) (Metrics, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.MetricsToTracesStability())
return f.CreateMetricsToTraces(ctx, set, cfg, next)
}
// CreateMetricsToMetrics creates a Metrics connector based on the settings and config.
func (b *Builder) CreateMetricsToMetrics(ctx context.Context, set CreateSettings, next consumer.Metrics) (Metrics, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.MetricsToMetricsStability())
return f.CreateMetricsToMetrics(ctx, set, cfg, next)
}
// CreateMetricsToLogs creates a Metrics connector based on the settings and config.
func (b *Builder) CreateMetricsToLogs(ctx context.Context, set CreateSettings, next consumer.Logs) (Metrics, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.MetricsToLogsStability())
return f.CreateMetricsToLogs(ctx, set, cfg, next)
}
// CreateLogsToTraces creates a Logs connector based on the settings and config.
func (b *Builder) CreateLogsToTraces(ctx context.Context, set CreateSettings, next consumer.Traces) (Logs, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.LogsToTracesStability())
return f.CreateLogsToTraces(ctx, set, cfg, next)
}
// CreateLogsToMetrics creates a Logs connector based on the settings and config.
func (b *Builder) CreateLogsToMetrics(ctx context.Context, set CreateSettings, next consumer.Metrics) (Logs, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.LogsToMetricsStability())
return f.CreateLogsToMetrics(ctx, set, cfg, next)
}
// CreateLogsToLogs creates a Logs connector based on the settings and config.
func (b *Builder) CreateLogsToLogs(ctx context.Context, set CreateSettings, next consumer.Logs) (Logs, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("connector %q is not configured", set.ID)
}
f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("connector factory not available for: %q", set.ID)
}
logStabilityLevel(set.Logger, f.LogsToLogsStability())
return f.CreateLogsToLogs(ctx, set, cfg, next)
}
func (b *Builder) IsConfigured(componentID component.ID) bool {
_, ok := b.cfgs[componentID]
return ok
}
func (b *Builder) Factory(componentType component.Type) component.Factory {
return b.factories[componentType]
}
// logStabilityLevel logs the stability level of a component. The log level is set to info for
// undefined, unmaintained, deprecated and development. The log level is set to debug
// for alpha, beta and stable.
func logStabilityLevel(logger *zap.Logger, sl component.StabilityLevel) {
if sl >= component.StabilityLevelAlpha {
logger.Debug(sl.LogMessage())
} else {
logger.Info(sl.LogMessage())
}
}
func errDataTypes(id component.ID, from, to component.DataType) error {
return fmt.Errorf("connector %q cannot connect from %s to %s: %w", id, from, to, component.ErrDataTypeIsNotSupported)
}