forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfactory.go
119 lines (107 loc) · 4.14 KB
/
factory.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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
//go:generate mdatagen metadata.yaml
package googlecloudexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter"
import (
"context"
"time"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/featuregate"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlecloudexporter/internal/metadata"
)
const (
defaultTimeout = 12 * time.Second // Consistent with Cloud Monitoring's timeout
)
var _ = featuregate.GlobalRegistry().MustRegister(
"exporter.googlecloud.OTLPDirect",
featuregate.StageStable,
featuregate.WithRegisterDescription("When enabled, the googlecloud exporter translates pdata directly to google cloud monitoring's types, rather than first translating to opencensus."),
featuregate.WithRegisterReferenceURL("https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/7132"),
featuregate.WithRegisterToVersion("v0.69.0"),
)
// NewFactory creates a factory for the googlecloud exporter
func NewFactory() exporter.Factory {
return exporter.NewFactory(
metadata.Type,
createDefaultConfig,
exporter.WithTraces(createTracesExporter, metadata.TracesStability),
exporter.WithMetrics(createMetricsExporter, metadata.MetricsStability),
exporter.WithLogs(createLogsExporter, metadata.LogsStability),
)
}
// createDefaultConfig creates the default configuration for exporter.
func createDefaultConfig() component.Config {
return &Config{
TimeoutSettings: exporterhelper.TimeoutSettings{Timeout: defaultTimeout},
QueueSettings: exporterhelper.NewDefaultQueueSettings(),
Config: collector.DefaultConfig(),
}
}
func createLogsExporter(
ctx context.Context,
params exporter.Settings,
cfg component.Config) (exporter.Logs, error) {
eCfg := cfg.(*Config)
logsExporter, err := collector.NewGoogleCloudLogsExporter(ctx, eCfg.Config, params.TelemetrySettings.Logger, params.BuildInfo.Version)
if err != nil {
return nil, err
}
return exporterhelper.NewLogsExporter(
ctx,
params,
cfg,
logsExporter.PushLogs,
exporterhelper.WithStart(logsExporter.Start),
exporterhelper.WithShutdown(logsExporter.Shutdown),
// Disable exporterhelper Timeout, since we are using a custom mechanism
// within exporter itself
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithQueue(eCfg.QueueSettings))
}
// createTracesExporter creates a trace exporter based on this config.
func createTracesExporter(
ctx context.Context,
params exporter.Settings,
cfg component.Config) (exporter.Traces, error) {
eCfg := cfg.(*Config)
tExp, err := collector.NewGoogleCloudTracesExporter(ctx, eCfg.Config, params.BuildInfo.Version, eCfg.Timeout)
if err != nil {
return nil, err
}
return exporterhelper.NewTracesExporter(
ctx,
params,
cfg,
tExp.PushTraces,
exporterhelper.WithStart(tExp.Start),
exporterhelper.WithShutdown(tExp.Shutdown),
// Disable exporterhelper Timeout, since we are using a custom mechanism
// within exporter itself
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithQueue(eCfg.QueueSettings))
}
// createMetricsExporter creates a metrics exporter based on this config.
func createMetricsExporter(
ctx context.Context,
params exporter.Settings,
cfg component.Config) (exporter.Metrics, error) {
eCfg := cfg.(*Config)
mExp, err := collector.NewGoogleCloudMetricsExporter(ctx, eCfg.Config, params.TelemetrySettings.Logger, params.BuildInfo.Version, eCfg.Timeout)
if err != nil {
return nil, err
}
return exporterhelper.NewMetricsExporter(
ctx,
params,
cfg,
mExp.PushMetrics,
exporterhelper.WithStart(mExp.Start),
exporterhelper.WithShutdown(mExp.Shutdown),
// Disable exporterhelper Timeout, since we are using a custom mechanism
// within exporter itself
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithQueue(eCfg.QueueSettings))
}