Skip to content

Commit

Permalink
Merge branch 'main' into prometheus_exemplars
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Apr 1, 2024
2 parents 912cbcd + 2f73208 commit 9b14786
Show file tree
Hide file tree
Showing 28 changed files with 298 additions and 33 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ jobs:
external-data-json-path: ./benchmarks/data.json
github-token: ${{ secrets.GITHUB_TOKEN }}
gh-pages-branch: benchmarks
auto-push: true
fail-on-alert: false
fail-on-alert: true
alert-threshold: "400%"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Added

- Add `AddLink` method to the `Span` interface in `go.opentelemetry.io/otel/trace`. (#5032)
- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp`. (#4906)
- Add `WithProxy` option in `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlptracehttp`. (#4906)
- The `Enabled` method is added to the `Logger` interface in `go.opentelemetry.io/otel/log`.
Expand All @@ -22,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
At which point, users will be required to migrage their code, and this package will be deprecated then removed. (#5085)
- Add support for `Summary` metrics in the `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` and `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` exporters. (#5100)
- Add `otel.scope.name` and `otel.scope.version` tags to spans exported by `go.opentelemetry.io/otel/exporters/zipkin`. (#5108)
- Add support for `AddLink` to `go.opentelemetry.io/otel/bridge/opencensus`. (#5116)
- Add Exemplar support to `go.opentelemetry.io/otel/exporters/prometheus`. (#5111)

### Changed
Expand Down
12 changes: 6 additions & 6 deletions baggage/baggage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ func NewKeyProperty(key string) (Property, error) {
// NewKeyValueProperty returns a new Property for key with value.
//
// The passed key must be compliant with W3C Baggage specification.
// The passed value must be precent-encoded as defined in W3C Baggage specification.
// The passed value must be percent-encoded as defined in W3C Baggage specification.
//
// Notice: Consider using [NewKeyValuePropertyRaw] instead
// that does not require precent-encoding of the value.
// that does not require percent-encoding of the value.
func NewKeyValueProperty(key, value string) (Property, error) {
if !validateValue(value) {
return newInvalidProperty(), fmt.Errorf("%w: %q", errInvalidValue, value)
Expand Down Expand Up @@ -224,10 +224,10 @@ type Member struct {
// NewMemberRaw returns a new Member from the passed arguments.
//
// The passed key must be compliant with W3C Baggage specification.
// The passed value must be precent-encoded as defined in W3C Baggage specification.
// The passed value must be percent-encoded as defined in W3C Baggage specification.
//
// Notice: Consider using [NewMemberRaw] instead
// that does not require precent-encoding of the value.
// that does not require percent-encoding of the value.
func NewMember(key, value string, props ...Property) (Member, error) {
if !validateValue(value) {
return newInvalidMember(), fmt.Errorf("%w: %q", errInvalidValue, value)
Expand Down Expand Up @@ -298,7 +298,7 @@ func parseMember(member string) (Member, error) {
return newInvalidMember(), fmt.Errorf("%w: %q", errInvalidValue, v)
}

// Decode a precent-encoded value.
// Decode a percent-encoded value.
value, err := url.PathUnescape(val)
if err != nil {
return newInvalidMember(), fmt.Errorf("%w: %v", errInvalidValue, err)
Expand Down Expand Up @@ -605,7 +605,7 @@ func parsePropertyInternal(s string) (p Property, ok bool) {
return
}

// Decode a precent-encoded value.
// Decode a percent-encoded value.
value, err := url.PathUnescape(s[valueStart:valueEnd])
if err != nil {
return
Expand Down
2 changes: 0 additions & 2 deletions bridge/opencensus/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
//
// There are known limitations to the trace bridge:
//
// - The AddLink method for OpenCensus Spans is ignored, and an error is sent
// to the OpenTelemetry ErrorHandler.
// - The NewContext method of the OpenCensus Tracer cannot embed an OpenCensus
// Span in a context unless that Span was created by that Tracer.
// - Conversion of custom OpenCensus Samplers to OpenTelemetry is not
Expand Down
11 changes: 11 additions & 0 deletions bridge/opencensus/internal/oc2otel/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ func Attributes(attr []octrace.Attribute) []attribute.KeyValue {
return otelAttr
}

func AttributesFromMap(attr map[string]interface{}) []attribute.KeyValue {
otelAttr := make([]attribute.KeyValue, 0, len(attr))
for k, v := range attr {
otelAttr = append(otelAttr, attribute.KeyValue{
Key: attribute.Key(k),
Value: AttributeValue(v),
})
}
return otelAttr
}

func AttributeValue(ocval interface{}) attribute.Value {
switch v := ocval.(type) {
case bool:
Expand Down
23 changes: 23 additions & 0 deletions bridge/opencensus/internal/oc2otel/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ func TestAttributes(t *testing.T) {
}
}

func TestAttributesFromMap(t *testing.T) {
in := map[string]interface{}{
"bool": true,
"int64": int64(49),
"float64": float64(1.618),
"key": "val",
}

want := []attribute.KeyValue{
attribute.Bool("bool", true),
attribute.Int64("int64", 49),
attribute.Float64("float64", 1.618),
attribute.String("key", "val"),
}
got := AttributesFromMap(in)

gotAttributeSet := attribute.NewSet(got...)
wantAttributeSet := attribute.NewSet(want...)
if !gotAttributeSet.Equals(&wantAttributeSet) {
t.Errorf("Attributes conversion want %v, got %v", wantAttributeSet.Encoded(attribute.DefaultEncoder()), gotAttributeSet.Encoded(attribute.DefaultEncoder()))
}
}

func TestAttributeValueUnknown(t *testing.T) {
got := AttributeValue([]byte{})
if got != attribute.StringValue("unknown") {
Expand Down
14 changes: 13 additions & 1 deletion bridge/opencensus/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,20 @@ func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compresse
}

// AddLink adds a link to this span.
// This drops the OpenCensus LinkType because there is no such concept in OpenTelemetry.
func (s *Span) AddLink(l octrace.Link) {
Handle(fmt.Errorf("ignoring OpenCensus link %+v for span %q because OpenTelemetry doesn't support setting links after creation", l, s.String()))
s.otelSpan.AddLink(trace.Link{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID(l.TraceID),
SpanID: trace.SpanID(l.SpanID),
// We don't know if this was sampled or not.
// Mark it as sampled, since sampled means
// "the caller may have recorded trace data":
// https://www.w3.org/TR/trace-context/#sampled-flag
TraceFlags: trace.FlagsSampled,
}),
Attributes: oc2otel.AttributesFromMap(l.Attributes),
})
}

// String prints a string representation of this span.
Expand Down
47 changes: 42 additions & 5 deletions bridge/opencensus/internal/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type span struct {
attrs []attribute.KeyValue
eName string
eOpts []trace.EventOption
links []trace.Link
}

func (s *span) IsRecording() bool { return s.recording }
Expand All @@ -37,6 +38,7 @@ func (s *span) SetName(n string) { s.name = n }
func (s *span) SetStatus(c codes.Code, d string) { s.sCode, s.sMsg = c, d }
func (s *span) SetAttributes(a ...attribute.KeyValue) { s.attrs = a }
func (s *span) AddEvent(n string, o ...trace.EventOption) { s.eName, s.eOpts = n, o }
func (s *span) AddLink(l trace.Link) { s.links = append(s.links, l) }

func TestSpanIsRecordingEvents(t *testing.T) {
s := &span{recording: true}
Expand Down Expand Up @@ -230,16 +232,51 @@ func TestSpanAddMessageReceiveEvent(t *testing.T) {
}

func TestSpanAddLinkFails(t *testing.T) {
h, restore := withHandler()
defer restore()

// OpenCensus does not try to set links if not recording.
s := &span{recording: true}
ocS := internal.NewSpan(s)
ocS.AddLink(octrace.Link{})
ocS.AddLink(octrace.Link{
TraceID: octrace.TraceID([16]byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
SpanID: octrace.SpanID([8]byte{2, 0, 0, 0, 0, 0, 0, 0}),
Attributes: map[string]interface{}{
"foo": "bar",
"number": int64(3),
},
})

wantLinks := []trace.Link{
{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceFlags: trace.FlagsSampled,
}),
},
{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID([]byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
SpanID: trace.SpanID([]byte{2, 0, 0, 0, 0, 0, 0, 0}),
TraceFlags: trace.FlagsSampled,
}),
Attributes: []attribute.KeyValue{
attribute.String("foo", "bar"),
attribute.Int64("number", 3),
},
},
}

if len(s.links) != len(wantLinks) {
t.Fatalf("got wrong number of links; want %v, got %v", len(wantLinks), len(s.links))
}

if h.err == nil {
t.Error("span.AddLink failed to raise an error")
for i, l := range s.links {
if !l.SpanContext.Equal(wantLinks[i].SpanContext) {
t.Errorf("link[%v] has the wrong span context; want %+v, got %+v", i, wantLinks[i].SpanContext, l.SpanContext)
}
gotAttributeSet := attribute.NewSet(l.Attributes...)
wantAttributeSet := attribute.NewSet(wantLinks[i].Attributes...)
if !gotAttributeSet.Equals(&wantAttributeSet) {
t.Errorf("link[%v] has the wrong attributes; want %v, got %v", i, wantAttributeSet.Encoded(attribute.DefaultEncoder()), gotAttributeSet.Encoded(attribute.DefaultEncoder()))
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions bridge/opentracing/internal/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ type MockEvent struct {
Attributes []attribute.KeyValue
}

type MockLink struct {
SpanContext trace.SpanContext
Attributes []attribute.KeyValue
}

type MockSpan struct {
embedded.Span

Expand All @@ -190,6 +195,7 @@ type MockSpan struct {
EndTime time.Time
ParentSpanID trace.SpanID
Events []MockEvent
Links []MockLink
}

var (
Expand Down Expand Up @@ -286,6 +292,13 @@ func (s *MockSpan) AddEvent(name string, o ...trace.EventOption) {
})
}

func (s *MockSpan) AddLink(link trace.Link) {
s.Links = append(s.Links, MockLink{
SpanContext: link.SpanContext,
Attributes: link.Attributes,
})
}

func (s *MockSpan) OverrideTracer(tracer trace.Tracer) {
s.officialTracer = tracer
}
Expand Down
2 changes: 1 addition & 1 deletion example/otel-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/otel-collector/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
retract v0.32.2 // Contains unresolvable dependencies.

require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlpmetric/otlpmetricgrpc/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
retract v0.32.2 // Contains unresolvable dependencies.

require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/google/go-cmp v0.6.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlpmetric/otlpmetrichttp/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracegrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc
go 1.21

require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlptrace/otlptracegrpc/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp
go 1.21

require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cenkalti/backoff/v4 v4.3.0
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.24.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0
Expand Down
4 changes: 2 additions & 2 deletions exporters/otlp/otlptrace/otlptracehttp/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
3 changes: 3 additions & 0 deletions internal/global/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (nonRecordingSpan) RecordError(error, ...trace.EventOption) {}
// AddEvent does nothing.
func (nonRecordingSpan) AddEvent(string, ...trace.EventOption) {}

// AddLink does nothing.
func (nonRecordingSpan) AddLink(trace.Link) {}

// SetName does nothing.
func (nonRecordingSpan) SetName(string) {}

Expand Down
27 changes: 27 additions & 0 deletions sdk/log/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package log // import "go.opentelemetry.io/otel/sdk/log"

import (
"context"
"time"

"go.opentelemetry.io/otel"
)
Expand Down Expand Up @@ -53,6 +54,32 @@ func (noopExporter) Shutdown(context.Context) error { return nil }

func (noopExporter) ForceFlush(context.Context) error { return nil }

// timeoutExporter wraps an Exporter and ensures any call to Export will have a
// timeout for the context.
type timeoutExporter struct {
Exporter

// timeout is the maximum time an export is attempted.
timeout time.Duration
}

// newTimeoutExporter wraps exporter with an Exporter that limits the context
// lifetime passed to Export to be timeout. If timeout is less than or equal to
// zero, exporter will be returned directly.
func newTimeoutExporter(exp Exporter, timeout time.Duration) Exporter {
if timeout <= 0 {
return exp
}
return &timeoutExporter{Exporter: exp, timeout: timeout}
}

// Export sets the timeout of ctx before calling the Exporter e wraps.
func (e *timeoutExporter) Export(ctx context.Context, records []Record) error {
ctx, cancel := context.WithTimeout(ctx, e.timeout)
defer cancel()
return e.Exporter.Export(ctx, records)
}

// exportSync exports all data from input using exporter in a spawned
// goroutine. The returned chan will be closed when the spawned goroutine
// completes.
Expand Down

0 comments on commit 9b14786

Please sign in to comment.