forked from open-telemetry/opentelemetry-go-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exporters/autoexport): enable support of multiple exporters for …
…OTEL_*_EXPORTER (open-telemetry#4471) This commit introduces the support of comma-separated value for OTEL_{METRICS,TRACES,LOGS}_EXPORTER. New functions can now be used to intialize a list of exporters: NewMetricReaders, NewLogExporters, NewSpanExporters. Old ones (NewMetricReader, NewLogExporter, NewSpanExporter) are now deprecated but still continue to do they initial work to avoid breaking change. Signed-off-by: thomasgouveia <[email protected]>
- Loading branch information
1 parent
074bc28
commit 7167054
Showing
16 changed files
with
535 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package autoexport | ||
|
||
const ( | ||
none = "none" | ||
otlp = "otlp" | ||
console = "console" | ||
|
||
httpProtobuf = "http/protobuf" | ||
grpc = "grpc" | ||
|
||
otelExporterOTLPProtoEnvKey = "OTEL_EXPORTER_OTLP_PROTOCOL" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package autoexport | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
// factory is a type alias for a factory method to build a signal-specific exporter. | ||
type factory[T any] func(ctx context.Context) (T, error) | ||
|
||
// executor allows different factories to be registered and executed. | ||
type executor[T any] struct { | ||
// factories holds a list of exporter factory functions. | ||
factories []factory[T] | ||
} | ||
|
||
func newExecutor[T any]() *executor[T] { | ||
return &executor[T]{ | ||
factories: make([]factory[T], 0), | ||
} | ||
} | ||
|
||
// Append appends the given factory to the executor. | ||
func (f *executor[T]) Append(fact factory[T]) { | ||
f.factories = append(f.factories, fact) | ||
} | ||
|
||
// Execute executes all the factories and returns the results. | ||
// An error will be returned if at least one factory fails. | ||
func (f *executor[T]) Execute(ctx context.Context) ([]T, error) { | ||
var results []T | ||
|
||
for _, registered := range f.factories { | ||
result, err := registered(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
results = append(results, result) | ||
} | ||
|
||
return results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.