1// Copyright The OpenTelemetry Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package componenttest 16 17import ( 18 "context" 19 20 "go.opentelemetry.io/otel/trace" 21 "go.uber.org/zap" 22 23 "go.opentelemetry.io/collector/component" 24 "go.opentelemetry.io/collector/component/componenthelper" 25 "go.opentelemetry.io/collector/config" 26) 27 28// NewNopExtensionCreateSettings returns a new nop settings for Create*Extension functions. 29func NewNopExtensionCreateSettings() component.ExtensionCreateSettings { 30 return component.ExtensionCreateSettings{ 31 Logger: zap.NewNop(), 32 TracerProvider: trace.NewNoopTracerProvider(), 33 BuildInfo: component.DefaultBuildInfo(), 34 } 35} 36 37type nopExtensionConfig struct { 38 config.ExtensionSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct 39} 40 41// nopExtensionFactory is factory for nopExtension. 42type nopExtensionFactory struct{} 43 44var nopExtensionFactoryInstance = &nopExtensionFactory{} 45 46// NewNopExtensionFactory returns a component.ExtensionFactory that constructs nop extensions. 47func NewNopExtensionFactory() component.ExtensionFactory { 48 return nopExtensionFactoryInstance 49} 50 51// Type gets the type of the Extension config created by this factory. 52func (f *nopExtensionFactory) Type() config.Type { 53 return "nop" 54} 55 56// CreateDefaultConfig creates the default configuration for the Extension. 57func (f *nopExtensionFactory) CreateDefaultConfig() config.Extension { 58 return &nopExtensionConfig{ 59 ExtensionSettings: config.NewExtensionSettings(config.NewID("nop")), 60 } 61} 62 63// CreateExtension implements component.ExtensionFactory interface. 64func (f *nopExtensionFactory) CreateExtension( 65 _ context.Context, 66 _ component.ExtensionCreateSettings, 67 _ config.Extension, 68) (component.Extension, error) { 69 return nopExtensionInstance, nil 70} 71 72var nopExtensionInstance = &nopExtension{ 73 Component: componenthelper.New(), 74} 75 76// nopExtension stores consumed traces and metrics for testing purposes. 77type nopExtension struct { 78 component.Component 79} 80