Skip to content

Commit 224c1b3

Browse files
committed
Add custom build support for lambdacomponents
1 parent 2087b12 commit 224c1b3

27 files changed

+711
-2
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Some layers include the corresponding OTel language SDK for the Lambda. This all
2525

2626
* **What exporters/receivers/processors are included from the OpenTelemetry Collector?**
2727
> You can check out [the stripped-down collector's imports](https://github.com/open-telemetry/opentelemetry-lambda/blob/main/collector/lambdacomponents/default.go#L18) in this repository for a full list of currently included components.
28+
29+
> Self-built binaries of the collector have **experimental** support for a custom set of connectors/exporters/receivers/processors. For more information, see [(Experimental) Customized collector build](#experimental-customized-collector-build)
2830
* **Is the Lambda layer provided or do I need to build it and distribute it myself?**
2931
> This repository provides pre-built Lambda layers, their ARNs are available in the [Releases](https://github.com/open-telemetry/opentelemetry-lambda/releases). You can also build the layers manually and publish them in your AWS account. This repo has files to facilitate doing that. More information is provided in [the Collector folder's README](collector/README.md).
3032
@@ -99,6 +101,45 @@ The following are runtimes which are no longer or not yet supported by this repo
99101
[3]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/faas-spans.md#outgoing-invocations
100102
[4]: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/faas/faas-metrics.md
101103

104+
## (Experimental) Customized collector build
105+
The collector can be built with a customized set of connectors/exporters/receivers/processors. This feature is **experimental** and is only supported for self-built binaries of the collector.
106+
107+
### Build Tags
108+
The build-tag `lambdacomponents.custom` must always be provided to opt-in for a custom build.
109+
Once this build-tag is present, you need provide additional build-tags to include your desired components in the resulting binary:
110+
111+
- `lambdacomponents.all` includes all available components
112+
- `lambdacomponents.connector.all` includes all available connectors
113+
- `lambdacomponents.exporter.all` includes all available exporters
114+
- `lambdacomponents.extension.all` includes all available extensions
115+
- `lambdacomponents.processor.all` includes all available processors
116+
- `lambdacomponents.receiver.all` includes all available receivers
117+
118+
Each available component can also be included explicitly by using its specific build-tag. For a full-list of available components, have a look into the [lambdacomponents](./collector/lambdacomponents) package.
119+
120+
As an example, the full build command including the following components:
121+
- All receivers
122+
- All processors
123+
- No extensions
124+
- Only the otlphttp exporter
125+
- Only the spanmetrics connector
126+
127+
would be the following:
128+
```shell
129+
go build -tags "lambdacomponents.custom,lambdacomponents.receiver.all,lambdacomponents.processor.all,lambdacomponents.exporter.otlphttp,lambdacomponents.connector.spanmetrics"
130+
```
131+
132+
### Adding additional options
133+
To add more options for a customized build, you can add your desired component to the [lambdacomponents](./collector/lambdacomponents) package.
134+
Make sure to always restrict your addition using the appropriate build-tags.
135+
136+
For example, if you want to add the extension `foo`, the file providing this extension should be located in the [extension](./collector/lambdacomponents/extension) directory have to following build restriction:
137+
```
138+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.extension.all || lambdacomponents.extension.foo)
139+
```
140+
141+
You can provide your addition as a pull-request to this repository. Before doing so, please also read through the details of [Contributing](#contributing) to this project.
142+
102143
## Contributing
103144

104145
See the [Contributing Guide](CONTRIBUTING.md) for details.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
15+
package connector
16+
17+
import "go.opentelemetry.io/collector/connector"
18+
19+
var Factories []func(extensionId string) connector.Factory
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.connector.all || lambdacomponents.connector.spanmetrics)
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package connector
18+
19+
import (
20+
"github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector"
21+
"go.opentelemetry.io/collector/connector"
22+
)
23+
24+
func init() {
25+
Factories = append(Factories, func(extensionId string) connector.Factory {
26+
return spanmetricsconnector.NewFactory()
27+
})
28+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//go:build lambdacomponents.custom
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package lambdacomponents
18+
19+
import (
20+
custom_connector "github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents/connector"
21+
custom_exporter "github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents/exporter"
22+
custom_extension "github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents/extension"
23+
custom_processor "github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents/processor"
24+
custom_receiver "github.com/open-telemetry/opentelemetry-lambda/collector/lambdacomponents/receiver"
25+
26+
"go.opentelemetry.io/collector/component"
27+
"go.opentelemetry.io/collector/connector"
28+
"go.opentelemetry.io/collector/exporter"
29+
"go.opentelemetry.io/collector/extension"
30+
"go.opentelemetry.io/collector/otelcol"
31+
"go.opentelemetry.io/collector/processor"
32+
"go.opentelemetry.io/collector/receiver"
33+
34+
"go.uber.org/multierr"
35+
)
36+
37+
func Components(extensionID string) (otelcol.Factories, error) {
38+
var errs []error
39+
40+
receivers, err := makeFactoryMap(custom_receiver.Factories, receiver.MakeFactoryMap, extensionID)
41+
if err != nil {
42+
errs = append(errs, err)
43+
}
44+
45+
processors, err := makeFactoryMap(custom_processor.Factories, processor.MakeFactoryMap, extensionID)
46+
if err != nil {
47+
errs = append(errs, err)
48+
}
49+
50+
exporters, err := makeFactoryMap(custom_exporter.Factories, exporter.MakeFactoryMap, extensionID)
51+
if err != nil {
52+
errs = append(errs, err)
53+
}
54+
55+
extensions, err := makeFactoryMap(custom_extension.Factories, extension.MakeFactoryMap, extensionID)
56+
if err != nil {
57+
errs = append(errs, err)
58+
}
59+
60+
connectors, err := makeFactoryMap(custom_connector.Factories, connector.MakeFactoryMap, extensionID)
61+
if err != nil {
62+
errs = append(errs, err)
63+
}
64+
65+
factories := otelcol.Factories{
66+
Receivers: receivers,
67+
Processors: processors,
68+
Exporters: exporters,
69+
Extensions: extensions,
70+
Connectors: connectors,
71+
}
72+
73+
return factories, multierr.Combine(errs...)
74+
}
75+
76+
func makeFactoryMap[F any](factories []func(extensionId string) F, fn func(...F) (map[component.Type]F, error), extensionId string) (map[component.Type]F, error) {
77+
preprocessedFactories := make([]F, len(factories))
78+
for i, f := range factories {
79+
preprocessedFactories[i] = f(extensionId)
80+
}
81+
82+
return fn(preprocessedFactories...)
83+
}

collector/lambdacomponents/default.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !lambdacomponents.custom
2+
13
// Copyright The OpenTelemetry Authors
24
//
35
// Licensed under the Apache License, Version 2.0 (the "License");
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.exporter.all || lambdacomponents.exporter.logging)
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package exporter
18+
19+
import (
20+
"go.opentelemetry.io/collector/exporter"
21+
"go.opentelemetry.io/collector/exporter/loggingexporter"
22+
)
23+
24+
func init() {
25+
Factories = append(Factories, func(extensionId string) exporter.Factory {
26+
return loggingexporter.NewFactory()
27+
})
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.exporter.all || lambdacomponents.exporter.otlp)
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package exporter
18+
19+
import (
20+
"go.opentelemetry.io/collector/exporter"
21+
"go.opentelemetry.io/collector/exporter/otlpexporter"
22+
)
23+
24+
func init() {
25+
Factories = append(Factories, func(extensionId string) exporter.Factory {
26+
return otlpexporter.NewFactory()
27+
})
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.exporter.all || lambdacomponents.exporter.otlphttp)
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package exporter
18+
19+
import (
20+
"go.opentelemetry.io/collector/exporter"
21+
"go.opentelemetry.io/collector/exporter/otlphttpexporter"
22+
)
23+
24+
func init() {
25+
Factories = append(Factories, func(extensionId string) exporter.Factory {
26+
return otlphttpexporter.NewFactory()
27+
})
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
15+
package exporter
16+
17+
import "go.opentelemetry.io/collector/exporter"
18+
19+
var Factories []func(extensionId string) exporter.Factory
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build lambdacomponents.custom && (lambdacomponents.all || lambdacomponents.exporter.all || lambdacomponents.exporter.prometheusremotewrite)
2+
3+
// Copyright The OpenTelemetry Authors
4+
//
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package exporter
18+
19+
import (
20+
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter"
21+
"go.opentelemetry.io/collector/exporter"
22+
)
23+
24+
func init() {
25+
Factories = append(Factories, func(extensionId string) exporter.Factory {
26+
return prometheusremotewriteexporter.NewFactory()
27+
})
28+
}

0 commit comments

Comments
 (0)