Debian Codegraph @

exporter/xexporter/exporter.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package xexporter // import "go.opentelemetry.io/collector/exporter/xexporter"
5
6 import (
7 "context"
8
9 "go.opentelemetry.io/collector/component"
10 "go.opentelemetry.io/collector/consumer/xconsumer"
11 "go.opentelemetry.io/collector/exporter"
12 "go.opentelemetry.io/collector/exporter/internal/experr"
13 "go.opentelemetry.io/collector/pipeline"
14 )
15
16 // Profiles is an exporter that can consume profiles.
17 type Profiles interface {
18 component.Component
19 xconsumer.Profiles
20 }
21
22 type Factory interface {
23 exporter.Factory
24
25 // CreateProfiles creates a Profiles exporter based on this config.
26 // If the exporter type does not support tracing,
27 // this function returns the error [pipeline.ErrSignalNotSupported].
28 CreateProfiles(ctx context.Context, set exporter.Settings, cfg component.Config) (Profiles, error)
29
30 // ProfilesStability gets the stability level of the Profiles exporter.
31 ProfilesStability() component.StabilityLevel
32 }
33
34 // FactoryOption apply changes to ReceiverOptions.
35 type FactoryOption interface {
36 // applyOption applies the option.
37 applyOption(o *factoryOpts)
38 }
39
40 // factoryOptionFunc is an ReceiverFactoryOption created through a function.
41 type factoryOptionFunc func(*factoryOpts)
42
43 func (f factoryOptionFunc) applyOption(o *factoryOpts) {
44 f(o)
45 }
46
47 type factoryOpts struct {
48 opts []exporter.FactoryOption
49 *factory
50 }
51
52 // CreateProfilesFunc is the equivalent of Factory.CreateProfiles.
53 type CreateProfilesFunc func(context.Context, exporter.Settings, component.Config) (Profiles, error)
54
55 // WithTraces overrides the default "error not supported" implementation for CreateTraces and the default "undefined" stability level.
56 func WithTraces(createTraces exporter.CreateTracesFunc, sl component.StabilityLevel) FactoryOption {
57 return factoryOptionFunc(func(o *factoryOpts) {
58 o.opts = append(o.opts, exporter.WithTraces(createTraces, sl))
59 })
60 }
61
62 // WithMetrics overrides the default "error not supported" implementation for CreateMetrics and the default "undefined" stability level.
63 func WithMetrics(createMetrics exporter.CreateMetricsFunc, sl component.StabilityLevel) FactoryOption {
64 return factoryOptionFunc(func(o *factoryOpts) {
65 o.opts = append(o.opts, exporter.WithMetrics(createMetrics, sl))
66 })
67 }
68
69 // WithLogs overrides the default "error not supported" implementation for CreateLogs and the default "undefined" stability level.
70 func WithLogs(createLogs exporter.CreateLogsFunc, sl component.StabilityLevel) FactoryOption {
71 return factoryOptionFunc(func(o *factoryOpts) {
72 o.opts = append(o.opts, exporter.WithLogs(createLogs, sl))
73 })
74 }
75
76 // WithProfiles overrides the default "error not supported" implementation for CreateProfilesExporter and the default "undefined" stability level.
77 func WithProfiles(createProfiles CreateProfilesFunc, sl component.StabilityLevel) FactoryOption {
78 return factoryOptionFunc(func(o *factoryOpts) {
79 o.profilesStabilityLevel = sl
80 o.createProfilesFunc = createProfiles
81 })
82 }
83
84 type factory struct {
85 exporter.Factory
86 createProfilesFunc CreateProfilesFunc
87 profilesStabilityLevel component.StabilityLevel
88 }
89
90 func (f *factory) ProfilesStability() component.StabilityLevel {
91 return f.profilesStabilityLevel
92 }
93
94 func (f *factory) CreateProfiles(ctx context.Context, set exporter.Settings, cfg component.Config) (Profiles, error) {
95 if f.createProfilesFunc == nil {
96 return nil, pipeline.ErrSignalNotSupported
97 }
98
99 if set.ID.Type() != f.Type() {
100 return nil, experr.ErrIDMismatch(set.ID, f.Type())
101 }
102 return f.createProfilesFunc(ctx, set, cfg)
103 }
104
105 // NewFactory returns a Factory.
106 func NewFactory(cfgType component.Type, createDefaultConfig component.CreateDefaultConfigFunc, options ...FactoryOption) Factory {
107 opts := factoryOpts{factory: &factory{}}
108 for _, opt := range options {
109 opt.applyOption(&opts)
110 }
111 opts.Factory = exporter.NewFactory(cfgType, createDefaultConfig, opts.opts...)
112 return opts.factory
113 }