Skip to content

Commit 0fb1dd1

Browse files
authored
Merge branch 'main' into cap-quotabalance
2 parents 80b4018 + 0be2d5b commit 0fb1dd1

File tree

78 files changed

+14787
-73
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+14787
-73
lines changed

.github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ updates:
190190
schedule:
191191
interval: weekly
192192
day: sunday
193+
- package-ecosystem: gomod
194+
directory: /exporters/autoexport
195+
labels:
196+
- dependencies
197+
- go
198+
- Skip Changelog
199+
schedule:
200+
interval: weekly
201+
day: sunday
193202
- package-ecosystem: gomod
194203
directory: /instrgen
195204
labels:

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1111
### Added
1212

1313
- Add the new `go.opentelemetry.io/contrib/instrgen` package to provide auto-generated source code instrumentation. (#3068, #3108)
14+
- The `go.opentelemetry.io/contrib/exporters/autoexport` package to provide configuration of trace exporters with useful defaults and envar support. (#2753)
1415

1516
## [1.17.0/0.42.0/0.11.0] - 2023-05-23
1617

@@ -72,7 +73,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7273

7374
### Fixed
7475

75-
- AWS SDK rename attributes `aws.operation`, `aws.service` to `rpc.method`,`rpc.service` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3617)
76+
- AWS SDK rename attributes `aws.operation`, `aws.service` to `rpc.method`,`rpc.service` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3617)
7677
- AWS SDK span name to be of the format `Service.Operation` in `go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws`. (#3582, #3521)
7778
- Prevent sampler configuration reset from erroneously sampling first span in `go.opentelemetry.io/contrib/samplers/jaegerremote`. (#3603, #3604)
7879

CODEOWNERS

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# instrumentation/net/http/otelhttp/ @open-telemetry/collector-go-approvers @madvikinggod @mralias
1717
# Path separator and minimum of 1 space between component path and owners is
1818
# important for validation steps
19-
#
19+
#
2020

2121
* @open-telemetry/go-approvers
2222

@@ -25,19 +25,21 @@ CODEOWNERS @MrAlias @Aneurysm9 @MadVikingGod
2525
detectors/aws/ @open-telemetry/go-approvers @Aneurysm9
2626
detectors/gcp/ @open-telemetry/go-approvers @dashpole
2727

28+
exporters/autoexport @open-telemetry/go-approvers @MikeGoldsmith
29+
2830
instrumentation/github.com/astaxie/beego/otelbeego/ @open-telemetry/go-approvers
2931
instrumentation/github.com/aws/aws-lambda-go/otellambda/ @open-telemetry/go-approvers @Aneurysm9
3032
instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/ @open-telemetry/go-approvers @Aneurysm9
3133
instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/ @open-telemetry/go-approvers
3234
instrumentation/github.com/emicklei/go-restful/otelrestful/ @open-telemetry/go-approvers
33-
instrumentation/github.com/gin-gonic/gin/otelgin/ @open-telemetry/go-approvers @hanyuancheung
35+
instrumentation/github.com/gin-gonic/gin/otelgin/ @open-telemetry/go-approvers @hanyuancheung
3436
instrumentation/github.com/go-kit/kit/otelkit/ @open-telemetry/go-approvers
3537
instrumentation/github.com/gocql/gocql/otelgocql/ @open-telemetry/go-approvers
3638
instrumentation/github.com/gorilla/mux/otelmux/ @open-telemetry/go-approvers
3739
instrumentation/github.com/labstack/echo/otelecho/ @open-telemetry/go-approvers
38-
instrumentation/github.com/Shopify/sarama/otelsarama/ @open-telemetry/go-approvers @pellared @hanyuancheung
40+
instrumentation/github.com/Shopify/sarama/otelsarama/ @open-telemetry/go-approvers @pellared @hanyuancheung
3941
instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/ @open-telemetry/go-approvers
40-
instrumentation/google.golang.org/grpc/otelgrpc/ @open-telemetry/go-approvers @dashpole @hanyuancheung
42+
instrumentation/google.golang.org/grpc/otelgrpc/ @open-telemetry/go-approvers @dashpole @hanyuancheung
4143
instrumentation/gopkg.in/macaron.v1/otelmacaron/ @open-telemetry/go-approvers
4244

4345
instrumentation/host/ @open-telemetry/go-approvers @MadVikingGod

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ generate: go-generate vanity-import-fix
8181
.PHONY: go-generate
8282
go-generate: $(OTEL_GO_MOD_DIRS:%=go-generate/%)
8383
go-generate/%: DIR=$*
84-
go-generate/%: | $(STRINGER) $(PORTO)
84+
go-generate/%: | $(STRINGER) $(GOTMPL)
8585
@echo "$(GO) generate $(DIR)/..." \
8686
&& cd $(DIR) \
8787
&& PATH="$(TOOLS):$${PATH}" $(GO) generate ./...
@@ -148,7 +148,7 @@ lint: go-mod-tidy golangci-lint misspell
148148
.PHONY: license-check
149149
license-check:
150150
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './exporters/otlp/internal/opentelemetry-proto/*') ; do \
151-
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \
151+
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=4 { found=1; next } END { if (!found) print FILENAME }' $$f; \
152152
done); \
153153
if [ -n "$${licRes}" ]; then \
154154
echo "license header checking failed:"; echo "$${licRes}"; \

detectors/aws/ec2/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module go.opentelemetry.io/contrib/detectors/aws/ec2
33
go 1.19
44

55
require (
6-
github.com/aws/aws-sdk-go v1.44.266
6+
github.com/aws/aws-sdk-go v1.44.269
77
github.com/stretchr/testify v1.8.3
88
go.opentelemetry.io/otel v1.16.0
99
go.opentelemetry.io/otel/sdk v1.16.0

detectors/aws/ec2/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/aws/aws-sdk-go v1.44.266 h1:MWd775dcYf7NrwgcHLtlsIbWoWkX8p4vomfNHr88zH0=
2-
github.com/aws/aws-sdk-go v1.44.266/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
1+
github.com/aws/aws-sdk-go v1.44.269 h1:NUNq++KMjhWUVVUIx7HYLgBpX16bWfTY1EdQRraLALo=
2+
github.com/aws/aws-sdk-go v1.44.269/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

exporters/autoexport/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Automatic Exporter configuration
2+
3+
[![Go Reference][goref-image]][goref-url]
4+
[![Apache License][license-image]][license-url]
5+
6+
This module provides easy access to configuring a trace exporter that can be used when configuring an OpenTelemetry Go SDK trace export pipeline.
7+
8+
## Useful links
9+
10+
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
11+
- For more about OpenTelemetry Go: <https://github.com/open-telemetry/opentelemetry-go>
12+
- For help or feedback on this project, join us in [GitHub Discussions][discussions-url]
13+
14+
## License
15+
16+
Apache 2.0 - See [LICENSE][license-url] for more information.
17+
18+
[license-url]: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/LICENSE
19+
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
20+
[goref-image]: https://pkg.go.dev/badge/go.opentelemetry.io/contrib/exporters/autoexport.svg
21+
[goref-url]: https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport
22+
[discussions-url]: https://github.com/open-telemetry/opentelemetry-go/discussions

exporters/autoexport/doc.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
// This module provides easy access to configuring a trace exporter
16+
// that can be used when configuring an OpenTelemetry Go SDK trace export
17+
// pipeline.
18+
//
19+
// [NewSpanExporter] looks for the `OTEL_TRACES_EXPORTER` environment
20+
// variable and if set, attempts to load the exporter from it's registry of
21+
// exporters. The registry is always loaded with an OTLP exporter with the key
22+
// `otlp` and additional exporters can be registered using
23+
// [RegisterSpanExporter].
24+
// Exporter registration uses a factory method pattern to not unneccarily build
25+
// exporters and use resources until they are requested.
26+
//
27+
// If the environment variable is not set, the fallback exporter is returned.
28+
// The fallback exporter defaults to an
29+
// [OTLP exporter](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace)
30+
// and can be overridden using the [RegisterSpanExporter](https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport#WithFallbackSpanExporter)
31+
// option.
32+
33+
package autoexport // import "go.opentelemetry.io/contrib/exporters/autoexport"

exporters/autoexport/exporter.go

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 autoexport // import "go.opentelemetry.io/contrib/exporters/autoexport"
16+
17+
import (
18+
"context"
19+
"os"
20+
21+
"go.opentelemetry.io/otel/sdk/trace"
22+
)
23+
24+
const (
25+
otelTracesExportersEnvKey = "OTEL_TRACES_EXPORTER"
26+
)
27+
28+
type config struct {
29+
fallbackExporter trace.SpanExporter
30+
}
31+
32+
func newConfig(ctx context.Context, opts ...Option) (config, error) {
33+
cfg := config{}
34+
for _, opt := range opts {
35+
cfg = opt.apply(cfg)
36+
}
37+
38+
// if no fallback exporter is configured, use otlp exporter
39+
if cfg.fallbackExporter == nil {
40+
exp, err := spanExporter(context.Background(), "otlp")
41+
if err != nil {
42+
return cfg, err
43+
}
44+
cfg.fallbackExporter = exp
45+
}
46+
return cfg, nil
47+
}
48+
49+
// Option applies an autoexport configuration option.
50+
type Option interface {
51+
apply(config) config
52+
}
53+
54+
type optionFunc func(config) config
55+
56+
func (fn optionFunc) apply(cfg config) config {
57+
return fn(cfg)
58+
}
59+
60+
// WithFallbackSpanExporter sets the fallback exporter to use when no exporter
61+
// is configured through the OTEL_TRACES_EXPORTER environment variable.
62+
func WithFallbackSpanExporter(exporter trace.SpanExporter) Option {
63+
return optionFunc(func(cfg config) config {
64+
cfg.fallbackExporter = exporter
65+
return cfg
66+
})
67+
}
68+
69+
// NewSpanExporter returns a configured SpanExporter defined using the environment
70+
// variable OTEL_TRACES_EXPORTER, the configured fallback exporter via options or
71+
// a default OTLP exporter (in this order).
72+
func NewSpanExporter(ctx context.Context, opts ...Option) (trace.SpanExporter, error) {
73+
// prefer exporter configured via environment variables over exporter
74+
// passed in via exporter parameter
75+
envExporter, err := makeExporterFromEnv(ctx)
76+
if err != nil {
77+
return nil, err
78+
}
79+
if envExporter != nil {
80+
return envExporter, nil
81+
}
82+
config, err := newConfig(ctx, opts...)
83+
if err != nil {
84+
return nil, err
85+
}
86+
return config.fallbackExporter, nil
87+
}
88+
89+
// makeExporterFromEnv returns a configured SpanExporter defined by the OTEL_TRACES_EXPORTER
90+
// environment variable.
91+
// nil is returned if no exporter is defined for the environment variable.
92+
func makeExporterFromEnv(ctx context.Context) (trace.SpanExporter, error) {
93+
expType, defined := os.LookupEnv(otelTracesExportersEnvKey)
94+
if !defined {
95+
return nil, nil
96+
}
97+
return spanExporter(ctx, expType)
98+
}

exporters/autoexport/exporter_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 autoexport
16+
17+
import (
18+
"context"
19+
"testing"
20+
21+
"github.com/stretchr/testify/assert"
22+
23+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
24+
"go.opentelemetry.io/otel/sdk/trace"
25+
)
26+
27+
func TestOTLPExporterReturnedWhenNoEnvOrFallbackExporterConfigured(t *testing.T) {
28+
exporter, err := NewSpanExporter(context.Background())
29+
assert.Nil(t, err)
30+
assert.NotNil(t, exporter)
31+
assert.IsType(t, &otlptrace.Exporter{}, exporter)
32+
}
33+
34+
func TestFallbackExporterReturnedWhenNoEnvExporterConfigured(t *testing.T) {
35+
testExporter := &testExporter{}
36+
exporter, err := NewSpanExporter(
37+
context.Background(),
38+
WithFallbackSpanExporter(testExporter),
39+
)
40+
assert.Nil(t, err)
41+
assert.Equal(t, testExporter, exporter)
42+
}
43+
44+
func TestEnvExporterIsPreferredOverFallbackExporter(t *testing.T) {
45+
t.Setenv("OTEL_TRACES_EXPORTER", "otlp")
46+
47+
testExporter := &testExporter{}
48+
exporter, err := NewSpanExporter(
49+
context.Background(),
50+
WithFallbackSpanExporter(testExporter),
51+
)
52+
assert.Nil(t, err)
53+
assert.IsType(t, &otlptrace.Exporter{}, exporter)
54+
}
55+
56+
type testExporter struct{}
57+
58+
func (e *testExporter) ExportSpans(ctx context.Context, ss []trace.ReadOnlySpan) error {
59+
return nil
60+
}
61+
62+
func (e *testExporter) Shutdown(ctx context.Context) error {
63+
return nil
64+
}

exporters/autoexport/go.mod

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module go.opentelemetry.io/contrib/exporters/autoexport
2+
3+
go 1.19
4+
5+
require (
6+
github.com/stretchr/testify v1.8.3
7+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0
8+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0
9+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.16.0
10+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0
11+
go.opentelemetry.io/otel/sdk v1.16.0
12+
)
13+
14+
require (
15+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
16+
github.com/davecgh/go-spew v1.1.1 // indirect
17+
github.com/go-logr/logr v1.2.4 // indirect
18+
github.com/go-logr/stdr v1.2.2 // indirect
19+
github.com/golang/protobuf v1.5.3 // indirect
20+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
21+
github.com/pmezard/go-difflib v1.0.0 // indirect
22+
go.opentelemetry.io/otel v1.16.0 // indirect
23+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
24+
go.opentelemetry.io/otel/metric v1.16.0 // indirect
25+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
26+
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
27+
golang.org/x/net v0.10.0 // indirect
28+
golang.org/x/sys v0.8.0 // indirect
29+
golang.org/x/text v0.9.0 // indirect
30+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
31+
google.golang.org/grpc v1.55.0 // indirect
32+
google.golang.org/protobuf v1.30.0 // indirect
33+
gopkg.in/yaml.v3 v3.0.1 // indirect
34+
)

0 commit comments

Comments
 (0)