forked from open-telemetry/opentelemetry-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexporter.go
More file actions
71 lines (62 loc) · 2.08 KB
/
Copy pathexporter.go
File metadata and controls
71 lines (62 loc) · 2.08 KB
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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package graph // import "go.opentelemetry.io/collector/service/internal/graph"
import (
"context"
"fmt"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/internal/telemetry"
"go.opentelemetry.io/collector/pipeline"
"go.opentelemetry.io/collector/pipeline/xpipeline"
"go.opentelemetry.io/collector/service/internal/attribute"
"go.opentelemetry.io/collector/service/internal/builders"
)
var _ consumerNode = (*exporterNode)(nil)
// An exporter instance can be shared by multiple pipelines of the same type.
// Therefore, nodeID is derived from "pipeline type" and "component ID".
type exporterNode struct {
attribute.Attributes
componentID component.ID
pipelineType pipeline.Signal
component.Component
}
func newExporterNode(pipelineType pipeline.Signal, exprID component.ID) *exporterNode {
return &exporterNode{
Attributes: attribute.Exporter(pipelineType, exprID),
componentID: exprID,
pipelineType: pipelineType,
}
}
func (n *exporterNode) getConsumer() baseConsumer {
return n.Component.(baseConsumer)
}
func (n *exporterNode) buildComponent(
ctx context.Context,
tel component.TelemetrySettings,
info component.BuildInfo,
builder *builders.ExporterBuilder,
) error {
set := exporter.Settings{
ID: n.componentID,
TelemetrySettings: telemetry.WithAttributeSet(tel, *n.Set()),
BuildInfo: info,
}
var err error
switch n.pipelineType {
case pipeline.SignalTraces:
n.Component, err = builder.CreateTraces(ctx, set)
case pipeline.SignalMetrics:
n.Component, err = builder.CreateMetrics(ctx, set)
case pipeline.SignalLogs:
n.Component, err = builder.CreateLogs(ctx, set)
case xpipeline.SignalProfiles:
n.Component, err = builder.CreateProfiles(ctx, set)
default:
return fmt.Errorf("error creating exporter %q for data type %q is not supported", set.ID, n.pipelineType)
}
if err != nil {
return fmt.Errorf("failed to create %q exporter for data type %q: %w", set.ID, n.pipelineType, err)
}
return nil
}