From 3a4dbaf07225c90e73860f3ded1b1cb019cd3166 Mon Sep 17 00:00:00 2001 From: Tarso Jabbes <60106453+tarsojabbes@users.noreply.github.com> Date: Thu, 4 Apr 2024 08:30:28 -0300 Subject: [PATCH] Removes deprecated ErrNilNextConsumer and solves type error for typeStr in 0.97.0 --- .../en/docs/collector/building/receiver.md | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/content/en/docs/collector/building/receiver.md b/content/en/docs/collector/building/receiver.md index a5dfc6a06231..7a5f9f9d2ff4 100644 --- a/content/en/docs/collector/building/receiver.md +++ b/content/en/docs/collector/building/receiver.md @@ -397,8 +397,8 @@ value for it so it can be used as part of the default settings. Go ahead and add the following code to your `factory.go` file: ```go -const ( - typeStr = "tailtracer" +var ( + typeStr = component.MustNewType("tailtracer") defaultInterval = 1 * time.Minute ) ``` @@ -433,8 +433,8 @@ import ( "go.opentelemetry.io/collector/receiver" ) -const ( - typeStr = "tailtracer" +var ( + typeStr = component.MustNewType("tailtracer") defaultInterval = 1 * time.Minute ) @@ -544,8 +544,8 @@ import ( "go.opentelemetry.io/collector/receiver" ) -const ( - typeStr = "tailtracer" +var ( + typeStr = component.MustNewType("tailtracer") defaultInterval = 1 * time.Minute ) @@ -860,11 +860,6 @@ pipeline and the factory is responsible to make sure the next consumer (either a processor or exporter) in the pipeline is valid otherwise it should generate an error. -The Collector's API provides some standard error types to help the factory -handle pipeline configurations. Your receiver factory should throw a -`component.ErrNilNextConsumer` in case the next consumer has an issue and is -passed as nil. - The `createTracesReceiver()` function will need a guard clause to make that validation. @@ -888,8 +883,8 @@ import ( "go.opentelemetry.io/collector/receiver" ) -const ( - typeStr = "tailtracer" +var ( + typeStr = component.MustNewType("tailtracer") defaultInterval = 1 * time.Minute ) @@ -900,9 +895,6 @@ func createDefaultConfig() component.Config { } func createTracesReceiver(_ context.Context, params receiver.CreateSettings, baseCfg component.Config, consumer consumer.Traces) (receiver.Traces, error) { - if consumer == nil { - return nil, component.ErrNilNextConsumer - } logger := params.Logger tailtracerCfg := baseCfg.(*Config) @@ -927,8 +919,6 @@ func NewFactory() receiver.Factory { {{% alert title="Check your work" color="primary" %}} -- Added a guard clause that verifies if the consumer is properly instantiated - and if not returns the `component.ErrNilNextConsumer`error. - Added a variable called `logger` and initialized it with the Collector's logger that is available as a field named `Logger` within the `receiver.CreateSettings` reference.