Skip to content

Commit

Permalink
Merge branch 'main' into explicit_bucket_advisory
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole authored Oct 20, 2023
2 parents 20ed283 + 1e1cc90 commit 7f5dce3
Show file tree
Hide file tree
Showing 36 changed files with 541 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

env:
DEFAULT_GO_VERSION: "1.21"
DEFAULT_GO_VERSION: "~1.21.3"
jobs:
benchmark:
name: Benchmarks
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
# backwards compatibility with the previous two minor releases and we
# explicitly test our code for these versions so keeping this at prior
# versions does not add value.
DEFAULT_GO_VERSION: "1.21"
DEFAULT_GO_VERSION: "~1.21.3"
jobs:
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
compatibility-test:
strategy:
matrix:
go-version: ["1.21", "1.20"]
go-version: ["~1.21.3", "~1.20.10"]
os: [ubuntu-latest, macos-latest, windows-latest]
# GitHub Actions does not support arm* architectures on default
# runners. It is possible to accomplish this with a self-hosted runner
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-dependabot-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version: "~1.21.3"
check-latest: true
cache-dependency-path: "**/go.sum"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
ref: ${{ github.head_ref }}
- uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version: "~1.21.3"
check-latest: true
cache-dependency-path: "**/go.sum"
- uses: evantorrie/mott-the-tidier@v1-beta
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/gosec.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ linters:
- godot
- gofumpt
- goimports
- gosec
- gosimple
- govet
- ineffassign
Expand Down Expand Up @@ -53,6 +54,20 @@ issues:
text: "calls to (.+) only in main[(][)] or init[(][)] functions"
linters:
- revive
# It's okay to not run gosec in a test.
- path: _test\.go
linters:
- gosec
# Igonoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand)
# as we commonly use it in tests and examples.
- text: "G404:"
linters:
- gosec
# Igonoring gosec G402: TLS MinVersion too low
# as the https://pkg.go.dev/crypto/tls#Config handles MinVersion default well.
- text: "G402: TLS MinVersion too low."
linters:
- gosec
include:
# revive exported should have comment or be unexported.
- EXC0012
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,33 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

- Add `go.opentelemetry.io/otel/bridge/opencensus.InstallTraceBridge`, which installs the OpenCensus trace bridge, and replaces `opencensus.NewTracer`. (#4567)
- Add scope version to trace and metric bridges in `go.opentelemetry.io/otel/bridge/opencensus`. (#4584)
- Add the `go.opentelemetry.io/otel/trace/embedded` package to be embedded in the exported trace API interfaces. (#4620)
- Add the `go.opentelemetry.io/otel/trace/noop` package as a default no-op implementation of the trace API. (#4620)
- Add context propagation in `go.opentelemetry.io/otel/example/dice`. (#4644)
- Add `go.opentelemetry.io/otel/metric.WithExplicitBucketBoundaries`, which allows defining default explicit bucket boundaries when creating histogram instruments. (#4603)

### Deprecated

- Deprecate `go.opentelemetry.io/otel/bridge/opencensus.NewTracer` in favor of `opencensus.InstallTraceBridge`. (#4567)
- Deprecate `go.opentelemetry.io/otel/example/fib` package is in favor of `go.opentelemetry.io/otel/example/dice`. (#4618)
- Deprecate `go.opentelemetry.io/otel/trace.NewNoopTracerProvider`.
Use the added `NewTracerProvider` function in `go.opentelemetry.io/otel/trace/noop` instead. (#4620)

### Changed

- `go.opentelemetry.io/otel/bridge/opencensus.NewMetricProducer` returns a `*MetricProducer` struct instead of the metric.Producer interface. (#4583)
- The `TracerProvider` in `go.opentelemetry.io/otel/trace` now embeds the `go.opentelemetry.io/otel/trace/embedded.TracerProvider` type.
This extends the `TracerProvider` interface and is is a breaking change for any existing implementation.
Implementors need to update their implementations based on what they want the default behavior of the interface to be.
See the "API Implementations" section of the `go.opentelemetry.io/otel/trace` package documentation for more informatoin about how to accomplish this. (#4620)
- The `Tracer` in `go.opentelemetry.io/otel/trace` now embeds the `go.opentelemetry.io/otel/trace/embedded.Tracer` type.
This extends the `Tracer` interface and is is a breaking change for any existing implementation.
Implementors need to update their implementations based on what they want the default behavior of the interface to be.
See the "API Implementations" section of the `go.opentelemetry.io/otel/trace` package documentation for more informatoin about how to accomplish this. (#4620)
- The `Span` in `go.opentelemetry.io/otel/trace` now embeds the `go.opentelemetry.io/otel/trace/embedded.Span` type.
This extends the `Span` interface and is is a breaking change for any existing implementation.
Implementors need to update their implementations based on what they want the default behavior of the interface to be.
See the "API Implementations" section of the `go.opentelemetry.io/otel/trace` package documentation for more informatoin about how to accomplish this. (#4620)

## [1.19.0/0.42.0/0.0.7] 2023-09-28

Expand Down
6 changes: 3 additions & 3 deletions bridge/opencensus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"github.com/stretchr/testify/assert"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)

func TestNewTraceConfig(t *testing.T) {
globalTP := trace.NewNoopTracerProvider()
customTP := trace.NewNoopTracerProvider()
globalTP := noop.NewTracerProvider()
customTP := noop.NewTracerProvider()
otel.SetTracerProvider(globalTP)
for _, tc := range []struct {
desc string
Expand Down
20 changes: 12 additions & 8 deletions bridge/opencensus/internal/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel"
"go.opentelemetry.io/otel/bridge/opencensus/internal/otel2oc"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"
)

type handler struct{ err error }
Expand All @@ -38,15 +40,17 @@ func withHandler() (*handler, func()) {
}

type tracer struct {
embedded.Tracer

ctx context.Context
name string
opts []trace.SpanStartOption
}

func (t *tracer) Start(ctx context.Context, name string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
t.ctx, t.name, t.opts = ctx, name, opts
noop := trace.NewNoopTracerProvider().Tracer("testing")
return noop.Start(ctx, name, opts...)
sub := noop.NewTracerProvider().Tracer("testing")
return sub.Start(ctx, name, opts...)
}

type ctxKey string
Expand Down Expand Up @@ -110,11 +114,11 @@ func TestTracerFromContext(t *testing.T) {
})
ctx := trace.ContextWithSpanContext(context.Background(), sc)

noop := trace.NewNoopTracerProvider().Tracer("TestTracerFromContext")
tracer := noop.NewTracerProvider().Tracer("TestTracerFromContext")
// Test using the fact that the No-Op span will propagate a span context .
ctx, _ = noop.Start(ctx, "test")
ctx, _ = tracer.Start(ctx, "test")

got := internal.NewTracer(noop).FromContext(ctx).SpanContext()
got := internal.NewTracer(tracer).FromContext(ctx).SpanContext()
// Do not test the convedsion, only that the propagtion.
want := otel2oc.SpanContext(sc)
if got != want {
Expand All @@ -129,11 +133,11 @@ func TestTracerNewContext(t *testing.T) {
})
ctx := trace.ContextWithSpanContext(context.Background(), sc)

noop := trace.NewNoopTracerProvider().Tracer("TestTracerNewContext")
tracer := noop.NewTracerProvider().Tracer("TestTracerNewContext")
// Test using the fact that the No-Op span will propagate a span context .
_, s := noop.Start(ctx, "test")
_, s := tracer.Start(ctx, "test")

ocTracer := internal.NewTracer(noop)
ocTracer := internal.NewTracer(tracer)
ctx = ocTracer.NewContext(context.Background(), internal.NewSpan(s))
got := trace.SpanContextFromContext(ctx)

Expand Down
3 changes: 2 additions & 1 deletion bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ import (
iBaggage "go.opentelemetry.io/otel/internal/baggage"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/noop"
)

var (
noopTracer = trace.NewNoopTracerProvider().Tracer("")
noopTracer = noop.NewTracerProvider().Tracer("")
noopSpan = func() trace.Span {
_, s := noopTracer.Start(context.Background(), "")
return s
Expand Down
8 changes: 7 additions & 1 deletion bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.opentelemetry.io/otel/codes"
semconv "go.opentelemetry.io/otel/semconv/v1.21.0"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
"go.opentelemetry.io/otel/trace/noop"
)

//nolint:revive // ignoring missing comments for unexported global variables in an internal package.
Expand All @@ -44,6 +46,8 @@ type MockContextKeyValue struct {
}

type MockTracer struct {
embedded.Tracer

FinishedSpans []*MockSpan
SpareTraceIDs []trace.TraceID
SpareSpanIDs []trace.SpanID
Expand Down Expand Up @@ -184,6 +188,8 @@ type MockEvent struct {
}

type MockSpan struct {
embedded.Span

mockTracer *MockTracer
officialTracer trace.Tracer
spanContext trace.SpanContext
Expand Down Expand Up @@ -295,4 +301,4 @@ func (s *MockSpan) OverrideTracer(tracer trace.Tracer) {
s.officialTracer = tracer
}

func (s *MockSpan) TracerProvider() trace.TracerProvider { return trace.NewNoopTracerProvider() }
func (s *MockSpan) TracerProvider() trace.TracerProvider { return noop.NewTracerProvider() }
3 changes: 3 additions & 0 deletions bridge/opentracing/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ import (
"sync"

"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

// TracerProvider is an OpenTelemetry TracerProvider that wraps an OpenTracing
// Tracer.
type TracerProvider struct {
embedded.TracerProvider

bridge *BridgeTracer
provider trace.TracerProvider

Expand Down
3 changes: 2 additions & 1 deletion bridge/opentracing/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (

"go.opentelemetry.io/otel/bridge/opentracing/internal"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

type namedMockTracer struct {
name string
*internal.MockTracer
}

type namedMockTracerProvider struct{}
type namedMockTracerProvider struct{ embedded.TracerProvider }

var _ trace.TracerProvider = (*namedMockTracerProvider)(nil)

Expand Down
5 changes: 5 additions & 0 deletions bridge/opentracing/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import (

"go.opentelemetry.io/otel/bridge/opentracing/migration"
"go.opentelemetry.io/otel/trace"
"go.opentelemetry.io/otel/trace/embedded"
)

// WrapperTracerProvider is an OpenTelemetry TracerProvider that wraps an
// OpenTracing Tracer, created by the deprecated NewWrappedTracerProvider.
//
// Deprecated: Use the TracerProvider from NewTracerProvider(...) instead.
type WrapperTracerProvider struct {
embedded.TracerProvider

wTracer *WrapperTracer
}

Expand Down Expand Up @@ -56,6 +59,8 @@ func NewWrappedTracerProvider(bridge *BridgeTracer, tracer trace.Tracer) *Wrappe
// aware how to operate in environment where OpenTracing API is also
// used.
type WrapperTracer struct {
embedded.Tracer

bridge *BridgeTracer
tracer trace.Tracer
}
Expand Down
18 changes: 15 additions & 3 deletions example/dice/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
Expand Down Expand Up @@ -50,14 +51,18 @@ func setupOTelSDK(ctx context.Context, serviceName, serviceVersion string) (shut
err = errors.Join(inErr, shutdown(ctx))
}

// Setup resource.
// Set up resource.
res, err := newResource(serviceName, serviceVersion)
if err != nil {
handleErr(err)
return
}

// Setup trace provider.
// Set up propagator.
prop := newPropagator()
otel.SetTextMapPropagator(prop)

// Set up trace provider.
tracerProvider, err := newTraceProvider(res)
if err != nil {
handleErr(err)
Expand All @@ -66,7 +71,7 @@ func setupOTelSDK(ctx context.Context, serviceName, serviceVersion string) (shut
shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown)
otel.SetTracerProvider(tracerProvider)

// Setup meter provider.
// Set up meter provider.
meterProvider, err := newMeterProvider(res)
if err != nil {
handleErr(err)
Expand All @@ -86,6 +91,13 @@ func newResource(serviceName, serviceVersion string) (*resource.Resource, error)
))
}

func newPropagator() propagation.TextMapPropagator {
return propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
)
}

func newTraceProvider(res *resource.Resource) (*trace.TracerProvider, error) {
traceExporter, err := stdouttrace.New(
stdouttrace.WithPrettyPrint())
Expand Down
2 changes: 1 addition & 1 deletion example/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func main() {
func serveMetrics() {
log.Printf("serving metrics at localhost:2223/metrics")
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2223", nil)
err := http.ListenAndServe(":2223", nil) //nolint:gosec // Ignoring G114: Use of net/http serve function that has no support for setting timeouts.
if err != nil {
fmt.Printf("error serving http: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion example/view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func main() {
func serveMetrics() {
log.Printf("serving metrics at localhost:2222/metrics")
http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":2222", nil)
err := http.ListenAndServe(":2222", nil) //nolint:gosec // Ignoring G114: Use of net/http serve function that has no support for setting timeouts.
if err != nil {
fmt.Printf("error serving http: %v", err)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ func NewHTTPCollector(endpoint string, resultCh <-chan ExportResult) (*HTTPColle

mux := http.NewServeMux()
mux.Handle(u.Path, http.HandlerFunc(c.handler))
c.srv = &http.Server{Handler: mux}
c.srv = &http.Server{
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if u.Scheme == "https" {
cert, err := weakCertificate()
if err != nil {
Expand Down
Loading

0 comments on commit 7f5dce3

Please sign in to comment.