Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoexport to automatically configure trace exporters #2753

Merged
merged 64 commits into from May 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
bc10897
add autoexport
MikeGoldsmith Sep 14, 2022
01b61b5
fix linting, add registry tests
MikeGoldsmith Sep 15, 2022
cf9e82d
update env var to OTEL_TRACES_EXPORTERS
MikeGoldsmith Sep 15, 2022
c03aaf6
update to go 1.18
MikeGoldsmith Sep 15, 2022
cd320da
add changelog entry
MikeGoldsmith Sep 15, 2022
c8eee46
add autoexport
MikeGoldsmith Sep 14, 2022
b33a022
fix linting, add registry tests
MikeGoldsmith Sep 15, 2022
8958075
update env var to OTEL_TRACES_EXPORTERS
MikeGoldsmith Sep 15, 2022
f5b23b4
update to go 1.18
MikeGoldsmith Sep 15, 2022
44d7ecb
add changelog entry
MikeGoldsmith Sep 15, 2022
8f220f6
Merge branch 'mike/autoexport' of https://github.com/honeycombio/open…
MikeGoldsmith Sep 15, 2022
baa5cb2
fix changelog
MikeGoldsmith Sep 15, 2022
ff36a60
fix typo :(
MikeGoldsmith Sep 15, 2022
ddc0597
refactor to only return single trace exporter
MikeGoldsmith Sep 15, 2022
78f8ebe
replace single case switch with if
MikeGoldsmith Sep 16, 2022
bec9d58
break up imports
MikeGoldsmith Sep 16, 2022
beb19ee
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
MikeGoldsmith Sep 23, 2022
dc65dd1
Update exporters/autoexport/exporter.go
MikeGoldsmith Sep 30, 2022
86b1759
move and rename errDupReg to var block
MikeGoldsmith Sep 30, 2022
bc32a8b
Apply suggestions from code review
MikeGoldsmith Oct 18, 2022
f30be94
fix const usage after rename
MikeGoldsmith Oct 18, 2022
e7e258e
update registry to reuse default otlp exporter
MikeGoldsmith Oct 19, 2022
4b15a95
update autoexport to use options design and register otlp exporters
MikeGoldsmith Oct 19, 2022
1bf9802
move otlp exporter registration to init
MikeGoldsmith Oct 19, 2022
cb5a453
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
MikeGoldsmith Oct 19, 2022
a9b6606
add autoexport to dependabot and version.yml
MikeGoldsmith Oct 19, 2022
718b1c0
fix linter and update descriptions
MikeGoldsmith Oct 19, 2022
7e44b89
fix typo
MikeGoldsmith Oct 19, 2022
ad5c4d0
update go.mod
MikeGoldsmith Oct 19, 2022
692c582
fix changelog
MikeGoldsmith Oct 19, 2022
0c03c27
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
MikeGoldsmith May 17, 2023
47b10b7
use go 1.19 in go.mod
MikeGoldsmith May 17, 2023
9647ace
update registry to use span exporter factory instead
MikeGoldsmith May 19, 2023
bd28bba
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
MikeGoldsmith May 19, 2023
9272837
fix formatting in registry
MikeGoldsmith May 22, 2023
6104122
update go.mod dependencies
MikeGoldsmith May 22, 2023
37fb2ee
update tests
MikeGoldsmith May 22, 2023
bd5d0dc
Merge branch 'main' of https://github.com/open-telemetry/opentelemetr…
MikeGoldsmith May 22, 2023
b92e45d
add autoexport to codeowners
MikeGoldsmith May 22, 2023
e5453fa
update exporter func to get exporter from env
MikeGoldsmith May 22, 2023
f2808a6
fix typo in test name
MikeGoldsmith May 22, 2023
b5a3fde
Merge branch 'main' into mike/autoexport
MikeGoldsmith May 22, 2023
fab825c
reverrt test names to PascalCase instead of snake_case
MikeGoldsmith May 23, 2023
58dc7c9
Merge branch 'main' into mike/autoexport
MikeGoldsmith May 23, 2023
4bd3bbe
Apply suggestions from code review
MikeGoldsmith May 23, 2023
ef9afd3
Update CHANGELOG.md
MikeGoldsmith May 25, 2023
4a10f64
update config option pattern to match repo
MikeGoldsmith May 25, 2023
b1ffb17
update NewTraceExporter to return errors
MikeGoldsmith May 25, 2023
44578b0
update registry factory funcs to take context
MikeGoldsmith May 25, 2023
edac7cc
return factory return params direclty during load
MikeGoldsmith May 25, 2023
20499ec
add traceSpanExporterFactory type
MikeGoldsmith May 25, 2023
d34f914
pass in context when making exporter from env
MikeGoldsmith May 25, 2023
782c62e
add README
MikeGoldsmith May 25, 2023
d66ccd6
add doc.go
MikeGoldsmith May 25, 2023
a39a084
go mod tidy
MikeGoldsmith May 25, 2023
95a1948
fix formatting
MikeGoldsmith May 25, 2023
9536e1b
Update exporters/autoexport/doc.go
MikeGoldsmith May 25, 2023
f20dc48
move docs from readme to docs.go
MikeGoldsmith May 25, 2023
f5fd316
fix typo
MikeGoldsmith May 25, 2023
27f8710
Apply suggestions from code review
MikeGoldsmith May 25, 2023
8481734
remove traceSpanExporterFactoryFunc
MikeGoldsmith May 25, 2023
0a529dc
Merge branch 'mike/autoexport' of https://github.com/honeycombio/open…
MikeGoldsmith May 25, 2023
7efa4aa
renamed NewTraceExporter to NewSpanExporter
MikeGoldsmith May 25, 2023
d98ccee
Merge branch 'main' into mike/autoexport
MikeGoldsmith May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 14 additions & 48 deletions exporters/autoexport/README.md
@@ -1,56 +1,22 @@
# Automatic Exporter configuration
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved

This module provides easy access to configuring a trace exporter that can be used when configuring an OpenTelemetry Go SDK trace export pipeline.

The autoexport package looks for the `OTEL_TRACES_EXPORTER` environment variable and if set, attempts to load the exporter from it's registry of exporters. The registry is always loaded with an OTLP exporter with the key `"otlp"` and additional exporters can be registered using `autoexport.RegisterSpanExporter("name", ...)`(See example below). Exporter registration uses a factory pattern to not unneccarily build exporters and use resources until they are requested.

If the environment variable is not set, the fallback exporter is returned. The fallback exporter defaults to an [OTLP exporter](https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/otlp/otlptrace) and can be overriden using the `WithFallbackSpanExporter` option.

### Getting an exporter

Set the preferred exporter type using the `OTEL_TRACES_EXPORTER` environment variable.

```shell
export OTEL_TRACES_EXPORTER="otlp"
```

```golang
import "go.opentelemetry.io/contrib/exporters/autoexport"
...
[![Go Reference][goref-image]][goref-url]
[![Apache License][license-image]][license-url]

exp, err := autoexport.NewTraceExporter(context.Background())
```

### Defining a custom fallback exporter

The fallback exporter is returned if the exporter environment variable is not set.

```golang
import "go.opentelemetry.io/contrib/exporters/autoexport"

fallbackExp = ...
exp, err := autoexport.NewTraceExporter(
context.Background(),
WithFallbackSpanExporter(fallbackExp),
)
```

### Registering a custom exporter
This module provides easy access to configuring a trace exporter that can be used when configuring an OpenTelemetry Go SDK trace export pipeline.

Set the `OTEL_TRACES_EXPORTER` environment variable to your custom exporter's name.
## Useful links

```shell
export OTEL_TRACES_EXPORTER="my-custom-exporter"
```
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
- For more about OpenTelemetry Go: <https://github.com/open-telemetry/opentelemetry-go>
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]

Register your custom exporter's factory before retrieveing it.
## License

```golang
import "go.opentelemetry.io/contrib/exporters/autoexport"
Apache 2.0 - See [LICENSE][license-url] for more information.

autoexport.RegisterSpanExporter("my-custom-exporter", func(ctx context.Context) (trace.SpanExporter, error) {
exp := ...
return exp, nil
})
exp, err := autoexport.NewTraceExporter(context.Background())
```
[license-url]: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[goref-image]: https://pkg.go.dev/badge/go.opentelemetry.io/contrib/exporters/autoexport.svg
[goref-url]: https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport
[discussions-url]: https://github.com/open-telemetry/opentelemetry-go/discussions
20 changes: 18 additions & 2 deletions exporters/autoexport/doc.go
Expand Up @@ -12,6 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package autoexport helps build trace exporters for configuring the
// OpenTelemetry SDK trace export pipeline.
// This module provides easy access to configuring a trace exporter
// that can be used when configuring an OpenTelemetry Go SDK trace export
// pipeline.
//
// The autoexport package looks for the `OTEL_TRACES_EXPORTER` environment
// variable and if set, attempts to load the exporter from it's registry of
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
// exporters. The registry is always loaded with an OTLP exporter with the key
// `"otlp"` and additional exporters can be registered using
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
// [RegisterSpanExporter](https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport#RegisterSpanExporter).
MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
// Exporter registration uses a factory method pattern to not unneccarily build
// exporters and use resources until they are requested.
//
// If the environment variable is not set, the fallback exporter is returned.
// The fallback exporter defaults to an
// [OTLP exporter](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace)
// and can be overriden using the [RegisterSpanExporter](https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport#WithFallbackSpanExporter)
pellared marked this conversation as resolved.
Show resolved Hide resolved
// option.

MikeGoldsmith marked this conversation as resolved.
Show resolved Hide resolved
package autoexport // import "go.opentelemetry.io/contrib/exporters/autoexport"