| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package graph // import "go.opentelemetry.io/collector/service/internal/graph" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"fmt" |
| 9 |
|
| 10 |
"go.opentelemetry.io/collector/component" |
| 11 |
"go.opentelemetry.io/collector/consumer" |
| 12 |
"go.opentelemetry.io/collector/consumer/xconsumer" |
| 13 |
"go.opentelemetry.io/collector/exporter" |
| 14 |
"go.opentelemetry.io/collector/pipeline" |
| 15 |
"go.opentelemetry.io/collector/pipeline/xpipeline" |
| 16 |
"go.opentelemetry.io/collector/service/internal/attribute" |
| 17 |
"go.opentelemetry.io/collector/service/internal/builders" |
| 18 |
"go.opentelemetry.io/collector/service/internal/componentattribute" |
| 19 |
"go.opentelemetry.io/collector/service/internal/metadata" |
| 20 |
"go.opentelemetry.io/collector/service/internal/obsconsumer" |
| 21 |
"go.opentelemetry.io/collector/service/internal/refconsumer" |
| 22 |
) |
| 23 |
|
| 24 |
var _ consumerNode = (*exporterNode)(nil) |
| 25 |
|
| 26 |
// An exporter instance can be shared by multiple pipelines of the same type. |
| 27 |
// Therefore, nodeID is derived from "pipeline type" and "component ID". |
| 28 |
type exporterNode struct { |
| 29 |
attribute.Attributes |
| 30 |
componentID component.ID |
| 31 |
pipelineType pipeline.Signal |
| 32 |
component.Component |
| 33 |
consumer baseConsumer |
| 34 |
} |
| 35 |
|
| 36 |
func newExporterNode(pipelineType pipeline.Signal, exprID component.ID) *exporterNode { |
| 37 |
return &exporterNode{ |
| 38 |
Attributes: attribute.Exporter(pipelineType, exprID), |
| 39 |
componentID: exprID, |
| 40 |
pipelineType: pipelineType, |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
func (n *exporterNode) getConsumer() baseConsumer { |
| 45 |
return n.consumer |
| 46 |
} |
| 47 |
|
| 48 |
func (n *exporterNode) buildComponent( |
| 49 |
ctx context.Context, |
| 50 |
tel component.TelemetrySettings, |
| 51 |
info component.BuildInfo, |
| 52 |
builder *builders.ExporterBuilder, |
| 53 |
) error { |
| 54 |
set := exporter.Settings{ |
| 55 |
ID: n.componentID, |
| 56 |
TelemetrySettings: componentattribute.TelemetrySettingsWithAttributes(tel, *n.Set()), |
| 57 |
BuildInfo: info, |
| 58 |
} |
| 59 |
|
| 60 |
tb, err := metadata.NewTelemetryBuilder(set.TelemetrySettings) |
| 61 |
if err != nil { |
| 62 |
return err |
| 63 |
} |
| 64 |
|
| 65 |
consumedSettings := obsconsumer.Settings{ |
| 66 |
ItemCounter: tb.ExporterConsumedItems, |
| 67 |
SizeCounter: tb.ExporterConsumedSize, |
| 68 |
Logger: set.Logger, |
| 69 |
} |
| 70 |
|
| 71 |
switch n.pipelineType { |
| 72 |
case pipeline.SignalTraces: |
| 73 |
n.Component, err = builder.CreateTraces(ctx, set) |
| 74 |
if err != nil { |
| 75 |
return fmt.Errorf("failed to create %q exporter for data type %q: %w", set.ID, n.pipelineType, err) |
| 76 |
} |
| 77 |
n.consumer = obsconsumer.NewTraces(n.Component.(consumer.Traces), consumedSettings) |
| 78 |
n.consumer = refconsumer.NewTraces(n.consumer.(consumer.Traces)) |
| 79 |
case pipeline.SignalMetrics: |
| 80 |
n.Component, err = builder.CreateMetrics(ctx, set) |
| 81 |
if err != nil { |
| 82 |
return fmt.Errorf("failed to create %q exporter for data type %q: %w", set.ID, n.pipelineType, err) |
| 83 |
} |
| 84 |
n.consumer = obsconsumer.NewMetrics(n.Component.(consumer.Metrics), consumedSettings) |
| 85 |
n.consumer = refconsumer.NewMetrics(n.consumer.(consumer.Metrics)) |
| 86 |
case pipeline.SignalLogs: |
| 87 |
n.Component, err = builder.CreateLogs(ctx, set) |
| 88 |
if err != nil { |
| 89 |
return fmt.Errorf("failed to create %q exporter for data type %q: %w", set.ID, n.pipelineType, err) |
| 90 |
} |
| 91 |
n.consumer = obsconsumer.NewLogs(n.Component.(consumer.Logs), consumedSettings) |
| 92 |
n.consumer = refconsumer.NewLogs(n.consumer.(consumer.Logs)) |
| 93 |
case xpipeline.SignalProfiles: |
| 94 |
n.Component, err = builder.CreateProfiles(ctx, set) |
| 95 |
if err != nil { |
| 96 |
return fmt.Errorf("failed to create %q exporter for data type %q: %w", set.ID, n.pipelineType, err) |
| 97 |
} |
| 98 |
n.consumer = obsconsumer.NewProfiles(n.Component.(xconsumer.Profiles), consumedSettings) |
| 99 |
n.consumer = refconsumer.NewProfiles(n.consumer.(xconsumer.Profiles)) |
| 100 |
default: |
| 101 |
return fmt.Errorf("error creating exporter %q for data type %q is not supported", set.ID, n.pipelineType) |
| 102 |
} |
| 103 |
return nil |
| 104 |
} |