Debian Codegraph @

exporter/exportertest/nop_exporter.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package exportertest // import "go.opentelemetry.io/collector/exporter/exportertest"
5
6 import (
7 "context"
8
9 "github.com/google/uuid"
10
11 "go.opentelemetry.io/collector/component"
12 "go.opentelemetry.io/collector/component/componenttest"
13 "go.opentelemetry.io/collector/consumer/consumertest"
14 "go.opentelemetry.io/collector/exporter"
15 "go.opentelemetry.io/collector/exporter/xexporter"
16 )
17
18 var NopType = component.MustNewType("nop")
19
20 // NewNopSettings returns a new nop settings for Create* functions with the given type.
21 func NewNopSettings(typ component.Type) exporter.Settings {
22 return exporter.Settings{
23 ID: component.NewIDWithName(typ, uuid.NewString()),
24 TelemetrySettings: componenttest.NewNopTelemetrySettings(),
25 BuildInfo: component.NewDefaultBuildInfo(),
26 }
27 }
28
29 // NewNopFactory returns an exporter.Factory that constructs nop exporters.
30 func NewNopFactory() exporter.Factory {
31 return xexporter.NewFactory(
32 NopType,
33 func() component.Config { return &nopConfig{} },
34 xexporter.WithTraces(createTraces, component.StabilityLevelStable),
35 xexporter.WithMetrics(createMetrics, component.StabilityLevelStable),
36 xexporter.WithLogs(createLogs, component.StabilityLevelStable),
37 xexporter.WithProfiles(createProfiles, component.StabilityLevelAlpha),
38 )
39 }
40
41 func createTraces(context.Context, exporter.Settings, component.Config) (exporter.Traces, error) {
42 return nopInstance, nil
43 }
44
45 func createMetrics(context.Context, exporter.Settings, component.Config) (exporter.Metrics, error) {
46 return nopInstance, nil
47 }
48
49 func createLogs(context.Context, exporter.Settings, component.Config) (exporter.Logs, error) {
50 return nopInstance, nil
51 }
52
53 func createProfiles(context.Context, exporter.Settings, component.Config) (xexporter.Profiles, error) {
54 return nopInstance, nil
55 }
56
57 type nopConfig struct{}
58
59 var nopInstance = &nop{
60 Consumer: consumertest.NewNop(),
61 }
62
63 // nop stores consumed traces, metrics, logs and profiles for testing purposes.
64 type nop struct {
65 component.StartFunc
66 component.ShutdownFunc
67 consumertest.Consumer
68 }