diff --git a/CHANGELOG.md b/CHANGELOG.md index aca1551d..8d4babe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## Unreleased +## [1.18.4](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.4) - 2023-06-26) + +- Disable self-tracing, enable self-metrics, and make these optional behaviors. Bugfix in span event timestamps. [#494](https://github.com/lightstep/otel-launcher-go/pull/494) + ## [1.18.3](https://github.com/lightstep/otel-launcher-go/releases/tag/v1.18.3) - 2023-06-21) - Re-release. [#492](https://github.com/lightstep/otel-launcher-go/pull/492) diff --git a/Makefile b/Makefile index e5445d28..60997132 100644 --- a/Makefile +++ b/Makefile @@ -102,6 +102,14 @@ test: $(GOTEST) ./...); \ done +.PHONY: fmt +fmt: + set -e; for dir in $(ALL_GO_MOD_DIRS); do \ + echo "go fmt in $${dir}"; \ + (cd "$${dir}" && \ + go fmt ./...); \ + done + .PHONY: test-386 test-386: if [ $(SKIP_386_TEST) = true ] ; then \ diff --git a/VERSION b/VERSION index b9fb27ab..a67b05e8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.3 +1.18.4 diff --git a/go.mod b/go.mod index b45ec9a7..d736b70f 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module github.com/lightstep/otel-launcher-go go 1.18 require ( - github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.3 - github.com/lightstep/otel-launcher-go/pipelines v1.18.3 + github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4 + github.com/lightstep/otel-launcher-go/pipelines v1.18.4 github.com/sethvargo/go-envconfig v0.8.3 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/otel v1.16.0 @@ -42,8 +42,8 @@ require ( github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/knadh/koanf v1.5.0 // indirect github.com/lightstep/go-expohisto v1.0.0 // indirect - github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.3 // indirect - github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.3 // indirect + github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.4 // indirect + github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect diff --git a/launcher/version.go b/launcher/version.go index 9145005f..73104619 100644 --- a/launcher/version.go +++ b/launcher/version.go @@ -14,4 +14,4 @@ package launcher -const version = "1.18.3" +const version = "1.18.4" diff --git a/lightstep/sdk/metric/example/go.mod b/lightstep/sdk/metric/example/go.mod index 356f0ff9..e2c125f7 100644 --- a/lightstep/sdk/metric/example/go.mod +++ b/lightstep/sdk/metric/example/go.mod @@ -3,7 +3,7 @@ module github.com/lightstep/otel-launcher-go/lightstep/sdk/metric/example go 1.18 require ( - github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.3 + github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4 github.com/lightstep/otel-launcher-go/pipelines v1.8.0 go.opentelemetry.io/proto/otlp v0.20.0 ) @@ -35,7 +35,7 @@ require ( github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/knadh/koanf v1.5.0 // indirect github.com/lightstep/go-expohisto v1.0.0 // indirect - github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.3 // indirect + github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect diff --git a/lightstep/sdk/metric/exporters/otlp/otelcol/client.go b/lightstep/sdk/metric/exporters/otlp/otelcol/client.go index 68a6344f..09e35571 100644 --- a/lightstep/sdk/metric/exporters/otlp/otelcol/client.go +++ b/lightstep/sdk/metric/exporters/otlp/otelcol/client.go @@ -33,15 +33,21 @@ import ( "go.opentelemetry.io/collector/processor" "go.opentelemetry.io/collector/processor/batchprocessor" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/metric/noop" + apitrace "go.opentelemetry.io/otel/trace" "go.uber.org/multierr" "go.uber.org/zap" ) type Option func(*Config) +// TODO: Config, Option, and the option impls are duplicated between +// this package and the metric exporter. Fix this. type Config struct { - Batcher batchprocessor.Config - Exporter otlpexporter.Config + SelfMetrics bool + SelfSpans bool + Batcher batchprocessor.Config + Exporter otlpexporter.Config } type client struct { @@ -54,6 +60,8 @@ type client struct { func NewDefaultConfig() Config { return Config{ + SelfMetrics: true, + SelfSpans: false, Batcher: batchprocessor.Config{ Timeout: 0, SendBatchSize: 0, @@ -130,9 +138,9 @@ func NewExporter(ctx context.Context, cfg Config) (metric.PushExporter, error) { c := &client{} if !cfg.Exporter.Arrow.Disabled { - c.settings.ID = component.NewID("otel/sdk/arrow") + c.settings.ID = component.NewID("otel/sdk/metric/arrow") } else { - c.settings.ID = component.NewID("otel/sdk/otlp") + c.settings.ID = component.NewID("otel/sdk/metric/otlp") } logger, err := zap.NewProduction() if err != nil { @@ -141,14 +149,18 @@ func NewExporter(ctx context.Context, cfg Config) (metric.PushExporter, error) { c.settings.TelemetrySettings.Logger = logger - // This is meta and we rely on global dependency injection, - // but we're hoping this works. - // Note: becomes otel.GetMeterProvider() - c.settings.TelemetrySettings.MeterProvider = otel.GetMeterProvider() - c.settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal + if cfg.SelfSpans { + c.settings.TelemetrySettings.TracerProvider = otel.GetTracerProvider() + } else { + c.settings.TelemetrySettings.TracerProvider = apitrace.NewNoopTracerProvider() + } - // Note: this may be too much tracing. - c.settings.TelemetrySettings.TracerProvider = otel.GetTracerProvider() + if cfg.SelfMetrics { + c.settings.TelemetrySettings.MeterProvider = otel.GetMeterProvider() + c.settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal + } else { + c.settings.TelemetrySettings.MeterProvider = noop.NewMeterProvider() + } exp, err := otlpexporter.NewFactory().CreateMetricsExporter(ctx, c.settings, &cfg.Exporter) if err != nil { diff --git a/lightstep/sdk/metric/go.mod b/lightstep/sdk/metric/go.mod index 38dcda01..f29ba916 100644 --- a/lightstep/sdk/metric/go.mod +++ b/lightstep/sdk/metric/go.mod @@ -10,7 +10,7 @@ require ( github.com/golang/mock v1.6.0 github.com/google/go-cmp v0.5.9 github.com/lightstep/go-expohisto v1.0.0 - github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.3 + github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector v0.79.0 go.opentelemetry.io/collector/component v0.79.0 @@ -22,6 +22,7 @@ require ( go.opentelemetry.io/otel v1.16.0 go.opentelemetry.io/otel/metric v1.16.0 go.opentelemetry.io/otel/sdk v1.16.0 + go.opentelemetry.io/otel/trace v1.16.0 go.opentelemetry.io/proto/otlp v0.20.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.24.0 @@ -71,7 +72,6 @@ require ( go.opentelemetry.io/collector/featuregate v1.0.0-rcv0012 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect - go.opentelemetry.io/otel/trace v1.16.0 // indirect go.uber.org/atomic v1.10.0 // indirect golang.org/x/mod v0.9.0 // indirect golang.org/x/net v0.10.0 // indirect diff --git a/lightstep/sdk/metric/internal/doevery/doevery.go b/lightstep/sdk/metric/internal/doevery/doevery.go index 25bdaddd..a77353a4 100644 --- a/lightstep/sdk/metric/internal/doevery/doevery.go +++ b/lightstep/sdk/metric/internal/doevery/doevery.go @@ -55,7 +55,8 @@ type invocationKey struct { // same duration. // // Example usage: -// end := time.Now().Add(5 * time.Second) +// +// end := time.Now().Add(5 * time.Second) // for end.After(time.Now()) { // doevery.TimePeriod(1*time.Second, func() { // fmt.Println("This will only appear once per second.") diff --git a/lightstep/sdk/metric/internal/syncstate/refcount_mapped.go b/lightstep/sdk/metric/internal/syncstate/refcount_mapped.go index cbf60a22..ad9dfddf 100644 --- a/lightstep/sdk/metric/internal/syncstate/refcount_mapped.go +++ b/lightstep/sdk/metric/internal/syncstate/refcount_mapped.go @@ -50,8 +50,9 @@ func (rm *refcountMapped) unref() { // tryUnmap flips the mapped bit to "unmapped" state and returns true if both of the // following conditions are true upon entry to this function: -// * There are no active references; -// * The mapped bit is in "mapped" state. +// - There are no active references; +// - The mapped bit is in "mapped" state. +// // Otherwise no changes are done to mapped bit and false is returned. func (rm *refcountMapped) tryUnmap() bool { if atomic.LoadInt64(&rm.value) != 0 { diff --git a/lightstep/sdk/trace/exporters/otlp/otelcol/client.go b/lightstep/sdk/trace/exporters/otlp/otelcol/client.go index f628adbe..1bf1ba7d 100644 --- a/lightstep/sdk/trace/exporters/otlp/otelcol/client.go +++ b/lightstep/sdk/trace/exporters/otlp/otelcol/client.go @@ -24,22 +24,29 @@ import ( "go.opentelemetry.io/collector/config/configcompression" "go.opentelemetry.io/collector/config/configgrpc" "go.opentelemetry.io/collector/config/configopaque" + "go.opentelemetry.io/collector/config/configtelemetry" "go.opentelemetry.io/collector/config/configtls" "go.opentelemetry.io/collector/exporter" "go.opentelemetry.io/collector/exporter/exporterhelper" "go.opentelemetry.io/collector/processor" "go.opentelemetry.io/collector/processor/batchprocessor" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/metric/noop" "go.opentelemetry.io/otel/sdk/trace" + apitrace "go.opentelemetry.io/otel/trace" "go.uber.org/multierr" "go.uber.org/zap" ) type Option func(*Config) +// TODO: Config, Option, and the option impls are duplicated between +// this package and the metric exporter. Fix this. type Config struct { - Batcher batchprocessor.Config - Exporter otlpexporter.Config + SelfMetrics bool + SelfSpans bool + Batcher batchprocessor.Config + Exporter otlpexporter.Config } type client struct { @@ -67,6 +74,8 @@ func (c *client) Shutdown(ctx context.Context) error { func NewDefaultConfig() Config { return Config{ + SelfMetrics: true, + SelfSpans: false, Batcher: batchprocessor.Config{ Timeout: 0, SendBatchSize: 0, @@ -143,9 +152,9 @@ func NewExporter(ctx context.Context, cfg Config) (trace.SpanExporter, error) { c := &client{} if !cfg.Exporter.Arrow.Disabled { - c.settings.ID = component.NewID("otel/sdk/arrow") + c.settings.ID = component.NewID("otel/sdk/trace/arrow") } else { - c.settings.ID = component.NewID("otel/sdk/otlp") + c.settings.ID = component.NewID("otel/sdk/trace/otlp") } logger, err := zap.NewProduction() if err != nil { @@ -154,8 +163,17 @@ func NewExporter(ctx context.Context, cfg Config) (trace.SpanExporter, error) { c.settings.TelemetrySettings.Logger = logger - // Note: this may be too much tracing. - c.settings.TelemetrySettings.TracerProvider = otel.GetTracerProvider() + if cfg.SelfSpans { + c.settings.TelemetrySettings.TracerProvider = otel.GetTracerProvider() + } else { + c.settings.TelemetrySettings.TracerProvider = apitrace.NewNoopTracerProvider() + } + if cfg.SelfMetrics { + c.settings.TelemetrySettings.MeterProvider = otel.GetMeterProvider() + c.settings.TelemetrySettings.MetricsLevel = configtelemetry.LevelNormal + } else { + c.settings.TelemetrySettings.MeterProvider = noop.NewMeterProvider() + } exp, err := otlpexporter.NewFactory().CreateTracesExporter(ctx, c.settings, &cfg.Exporter) if err != nil { diff --git a/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go b/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go index 4de36aae..d9648822 100644 --- a/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go +++ b/lightstep/sdk/trace/exporters/otlp/otelcol/client_test.go @@ -35,12 +35,12 @@ import ( "go.opentelemetry.io/collector/receiver/receivertest" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/resource" - "go.opentelemetry.io/otel/trace" sdktrace "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/trace" coltracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1" - tracev1 "go.opentelemetry.io/proto/otlp/trace/v1" commonpb "go.opentelemetry.io/proto/otlp/common/v1" resourcev1 "go.opentelemetry.io/proto/otlp/resource/v1" + tracev1 "go.opentelemetry.io/proto/otlp/trace/v1" // "google.golang.org/protobuf/encoding/prototext" "google.golang.org/protobuf/proto" ) @@ -173,7 +173,7 @@ func (t *clientTestSuite) TestSpan() { tracer := t.sdk.Tracer("test-tracer") _, span := tracer.Start(ctx, "ExecuteRequest") span.SetAttributes(attribute.String("test-attribute-1", "test-value-1")) - span.AddEvent("test event", trace.WithAttributes(attribute.String("test-event-attribute-1", "test-event-value-1"))) + span.AddEvent("test event", trace.WithAttributes(attribute.String("test-event-attribute-1", "test-event-value-1"))) span.End() _ = t.sdk.Shutdown(ctx) @@ -203,7 +203,7 @@ func (t *clientTestSuite) TestSpan() { Value: &commonpb.AnyValue{ Value: &commonpb.AnyValue_StringValue{ StringValue: "value", - }, + }, }, }, &commonpb.KeyValue{ @@ -211,7 +211,7 @@ func (t *clientTestSuite) TestSpan() { Value: &commonpb.AnyValue{ Value: &commonpb.AnyValue_StringValue{ StringValue: "tester", - }, + }, }, }, }, @@ -223,11 +223,11 @@ func (t *clientTestSuite) TestSpan() { }, Spans: []*tracev1.Span{ &tracev1.Span{ - SpanId: []byte(unqSpanID), + SpanId: []byte(unqSpanID), TraceId: []byte(unqTraceID), - Kind: tracev1.Span_SPAN_KIND_INTERNAL, - Name: "ExecuteRequest", - Status: &tracev1.Status{}, + Kind: tracev1.Span_SPAN_KIND_INTERNAL, + Name: "ExecuteRequest", + Status: &tracev1.Status{}, Attributes: []*commonpb.KeyValue{ &commonpb.KeyValue{ Key: "test-attribute-1", @@ -240,8 +240,8 @@ func (t *clientTestSuite) TestSpan() { }, Events: []*tracev1.Span_Event{ { - TimeUnixNano: uint64(roSpan.Events()[0].Time.Nanosecond()), - Name: "test event", + TimeUnixNano: uint64(roSpan.Events()[0].Time.UnixNano()), + Name: "test event", Attributes: []*commonpb.KeyValue{ { Key: "test-event-attribute-1", @@ -252,7 +252,7 @@ func (t *clientTestSuite) TestSpan() { }, }, }, - DroppedAttributesCount: uint32(roSpan.DroppedAttributes()), + DroppedAttributesCount: uint32(roSpan.DroppedAttributes()), }, }, }, @@ -321,7 +321,7 @@ func (t *clientTestSuite) TestD2PD() { t.Equal(event.Time.Nanosecond(), actualEvent.Timestamp().AsTime().Nanosecond()) t.Equal(event.Name, actualEvent.Name()) t.Equal(uint32(event.DroppedAttributeCount), actualEvent.DroppedAttributesCount()) - + for _, attr := range event.Attributes { actualEventVal, ok := actualEvent.Attributes().Get(string(attr.Key)) t.True(ok) @@ -342,4 +342,4 @@ func (t *clientTestSuite) TestD2PD() { t.Equal(attr.Value.AsString(), actualLinkVal.AsString()) } } -} \ No newline at end of file +} diff --git a/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go b/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go index 77c02bd6..2895b543 100644 --- a/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go +++ b/lightstep/sdk/trace/exporters/otlp/otelcol/otlp.go @@ -27,7 +27,7 @@ func copyEvents(dest ptrace.SpanEventSlice, events []trace.Event) { e1 := dest.AppendEmpty() e1.SetDroppedAttributesCount(uint32(event.DroppedAttributeCount)) e1.SetName(event.Name) - e1.SetTimestamp(pcommon.Timestamp((event.Time.Nanosecond()))) + e1.SetTimestamp(pcommon.NewTimestampFromTime(event.Time)) internal.CopyAttributes(e1.Attributes(), attribute.NewSet(event.Attributes...)) } diff --git a/lightstep/sdk/trace/go.mod b/lightstep/sdk/trace/go.mod index 44fa2810..334c1a50 100644 --- a/lightstep/sdk/trace/go.mod +++ b/lightstep/sdk/trace/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/f5/otel-arrow-adapter v0.0.0-20230612212022-445aac7c6ae8 github.com/google/go-cmp v0.5.9 - github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.3 + github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector v0.79.0 go.opentelemetry.io/collector/component v0.79.0 @@ -15,6 +15,7 @@ require ( go.opentelemetry.io/collector/processor/batchprocessor v0.79.0 go.opentelemetry.io/collector/receiver v0.79.0 go.opentelemetry.io/otel v1.16.0 + go.opentelemetry.io/otel/metric v1.16.0 go.opentelemetry.io/otel/sdk v1.16.0 go.opentelemetry.io/otel/trace v1.16.0 go.opentelemetry.io/proto/otlp v0.20.0 @@ -67,7 +68,6 @@ require ( go.opentelemetry.io/collector/featuregate v1.0.0-rcv0012 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 // indirect - go.opentelemetry.io/otel/metric v1.16.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/goleak v1.2.1 // indirect golang.org/x/mod v0.9.0 // indirect diff --git a/pipelines/go.mod b/pipelines/go.mod index 162e1b5a..7928d34e 100644 --- a/pipelines/go.mod +++ b/pipelines/go.mod @@ -50,8 +50,8 @@ require ( ) require ( - github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.3 - github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.3 + github.com/lightstep/otel-launcher-go/lightstep/instrumentation v1.18.4 + github.com/lightstep/otel-launcher-go/lightstep/sdk/metric v1.18.4 go.opentelemetry.io/collector v0.79.0 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0 ) @@ -79,7 +79,7 @@ require ( github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/knadh/koanf v1.5.0 // indirect github.com/lightstep/go-expohisto v1.0.0 // indirect - github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.3 // indirect + github.com/lightstep/otel-launcher-go/lightstep/sdk/internal v1.18.4 // indirect github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8 // indirect github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect