diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 555decd4daf..f4c687ce090 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -64,6 +64,15 @@ updates: schedule: interval: weekly day: sunday + - package-ecosystem: gomod + directory: /example/dice + labels: + - dependencies + - go + - Skip Changelog + schedule: + interval: weekly + day: sunday - package-ecosystem: gomod directory: /example/fib labels: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 55cb5ddcd19..67ad856d2cf 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,6 +13,9 @@ on: # │ │ │ │ │ # * * * * * - cron: '30 1 * * *' + push: + branches: [ main ] + pull_request: jobs: CodeQL-Build: diff --git a/.gitignore b/.gitignore index aa699376225..f3355c852be 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ go.work.sum gen/ +/example/dice/dice /example/fib/fib /example/fib/traces.txt /example/jaeger/jaeger diff --git a/CHANGELOG.md b/CHANGELOG.md index a5734521026..3e5c35b5dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,45 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +## [1.19.0/0.42.0/0.0.7] 2023-09-28 + +This release contains the first stable release of the OpenTelemetry Go [metric SDK]. +Our project stability guarantees now apply to the `go.opentelemetry.io/otel/sdk/metric` package. +See our [versioning policy](VERSIONING.md) for more information about these stability guarantees. + +### Added + +- Add the "Roll the dice" getting started application example in `go.opentelemetry.io/otel/example/dice`. (#4539) +- The `WithWriter` and `WithPrettyPrint` options to `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` to set a custom `io.Writer`, and allow displaying the output in human-readable JSON. (#4507) + +### Changed + +- Allow '/' characters in metric instrument names. (#4501) +- The exporter in `go.opentelemetry.io/otel/exporters/stdout/stdoutmetric` does not prettify its output by default anymore. (#4507) +- Upgrade `gopkg.io/yaml` from `v2` to `v3` in `go.opentelemetry.io/otel/schema`. (#4535) + +### Fixed + +- In `go.opentelemetry.op/otel/exporters/prometheus`, don't try to create the Prometheus metric on every `Collect` if we know the scope is invalid. (#4499) + +### Removed + +- Remove `"go.opentelemetry.io/otel/bridge/opencensus".NewMetricExporter`, which is replaced by `NewMetricProducer`. (#4566) + +## [1.19.0-rc.1/0.42.0-rc.1] 2023-09-14 + +This is a release candidate for the v1.19.0/v0.42.0 release. +That release is expected to include the `v1` release of the OpenTelemetry Go metric SDK and will provide stability guarantees of that SDK. +See our [versioning policy](VERSIONING.md) for more information about these stability guarantees. + +### Changed + +- Allow '/' characters in metric instrument names. (#4501) + +### Fixed + +- In `go.opentelemetry.op/otel/exporters/prometheus`, don't try to create the prometheus metric on every `Collect` if we know the scope is invalid. (#4499) + ## [1.18.0/0.41.0/0.0.6] 2023-09-12 This release drops the compatibility guarantee of [Go 1.19]. @@ -2617,7 +2656,9 @@ It contains api and sdk for trace and meter. - CircleCI build CI manifest files. - CODEOWNERS file to track owners of this project. -[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.18.0...HEAD +[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.19.0...HEAD +[1.19.0/0.42.0/0.0.7]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.19.0 +[1.19.0-rc.1/0.42.0-rc.1]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.19.0-rc.1 [1.18.0/0.41.0/0.0.6]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.18.0 [1.17.0/0.40.0/0.0.5]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.17.0 [1.16.0/0.39.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.16.0 @@ -2693,3 +2734,4 @@ It contains api and sdk for trace and meter. [Go 1.19]: https://go.dev/doc/go1.19 [metric API]:https://pkg.go.dev/go.opentelemetry.io/otel/metric +[metric SDK]:https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric diff --git a/bridge/opencensus/README.md b/bridge/opencensus/README.md deleted file mode 100644 index 3df9dc7eb07..00000000000 --- a/bridge/opencensus/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# OpenCensus Bridge - -The OpenCensus Bridge helps facilitate the migration of an application from OpenCensus to OpenTelemetry. - -## Caveat about OpenCensus - -Installing a metric or tracing bridge will cause OpenCensus telemetry to be exported by OpenTelemetry exporters. Since OpenCensus telemetry uses globals, installing a bridge will result in telemetry collection from _all_ libraries that use OpenCensus, including some you may not expect. For example ([#1928](https://github.com/open-telemetry/opentelemetry-go/issues/1928)), if a client library generates traces with OpenCensus, installing the bridge will cause those traces to be exported by OpenTelemetry. - -## Tracing - -### The Problem: Mixing OpenCensus and OpenTelemetry libraries - -In a perfect world, one would simply migrate their entire go application --including custom instrumentation, libraries, and exporters-- from OpenCensus to OpenTelemetry all at once. In the real world, dependency constraints, third-party ownership of libraries, or other reasons may require mixing OpenCensus and OpenTelemetry libraries in a single application. - -However, if you create the following spans in a go application: - -```go -ctx, ocSpan := opencensus.StartSpan(context.Background(), "OuterSpan") -defer ocSpan.End() -ctx, otSpan := opentelemetryTracer.Start(ctx, "MiddleSpan") -defer otSpan.End() -ctx, ocSpan := opencensus.StartSpan(ctx, "InnerSpan") -defer ocSpan.End() -``` - -OpenCensus reports (to OpenCensus exporters): - -``` -[--------OuterSpan------------] - [----InnerSpan------] -``` - -OpenTelemetry reports (to OpenTelemetry exporters): - -``` - [-----MiddleSpan--------] -``` - -Instead, I would prefer (to a single set of exporters): - -``` -[--------OuterSpan------------] - [-----MiddleSpan--------] - [----InnerSpan------] -``` - -### The bridge solution - -The bridge implements the OpenCensus trace API using OpenTelemetry. This would cause, for example, a span recorded with OpenCensus' `StartSpan()` method to be equivalent to recording a span using OpenTelemetry's `tracer.Start()` method. Funneling all tracing API calls to OpenTelemetry APIs results in the desired unified span hierarchy. - -### User Journey - -Starting from an application using entirely OpenCensus APIs: - -1. Instantiate OpenTelemetry SDK and Exporters -2. Override OpenCensus' DefaultTracer with the bridge -3. Migrate libraries individually from OpenCensus to OpenTelemetry -4. Remove OpenCensus exporters and configuration - -To override OpenCensus' DefaultTracer with the bridge: - -```go -import ( - octrace "go.opencensus.io/trace" - "go.opentelemetry.io/otel/bridge/opencensus" - "go.opentelemetry.io/otel" -) - -tracer := otel.GetTracerProvider().Tracer("bridge") -octrace.DefaultTracer = opencensus.NewTracer(tracer) -``` - -Be sure to set the `Tracer` name to your instrumentation package name instead of `"bridge"`. - -#### Incompatibilities - -OpenCensus and OpenTelemetry APIs are not entirely compatible. If the bridge finds any incompatibilities, it will log them. Incompatibilities include: - -* Custom OpenCensus Samplers specified during StartSpan are ignored. -* Links cannot be added to OpenCensus spans. -* OpenTelemetry Debug or Deferred trace flags are dropped after an OpenCensus span is created. diff --git a/bridge/opencensus/doc.go b/bridge/opencensus/doc.go index 80d80da6f78..ed2a4cfd935 100644 --- a/bridge/opencensus/doc.go +++ b/bridge/opencensus/doc.go @@ -13,23 +13,51 @@ // limitations under the License. // Package opencensus provides a migration bridge from OpenCensus to -// OpenTelemetry. The NewTracer function should be used to create an -// OpenCensus Tracer from an OpenTelemetry Tracer. This Tracer can be use in -// place of any existing OpenCensus Tracer and will generate OpenTelemetry -// spans for traces. These spans will be exported by the OpenTelemetry -// TracerProvider the original OpenTelemetry Tracer came from. +// OpenTelemetry for metrics and traces. The bridge incorporates metrics and +// traces from OpenCensus into the OpenTelemetry SDK, combining them with +// metrics and traces from OpenTelemetry instrumentation. // -// There are known limitations to this bridge: +// # Migration Guide // -// - The AddLink method for OpenCensus Spans is not compatible with the -// OpenTelemetry Span. No link can be added to an OpenTelemetry Span once it -// is started. Any calls to this method for the OpenCensus Span will result -// in an error being sent to the OpenTelemetry default ErrorHandler. +// For most applications, it would be difficult to migrate an application +// from OpenCensus to OpenTelemetry all-at-once. Libraries used by the +// application may still be using OpenCensus, and the application itself may +// have many lines of instrumentation. // -// - The NewContext method of the OpenCensus Tracer cannot embed an OpenCensus -// Span in a context unless that Span was created by that Tracer. +// Bridges help in this situation by allowing your application to have "mixed" +// instrumentation, while incorporating all instrumentation into a single +// export path. To migrate with bridges, a user would: // -// - Conversion of custom OpenCensus Samplers to OpenTelemetry is not -// implemented. An error will be sent to the OpenTelemetry default -// ErrorHandler if this is attempted. +// 1. Configure the OpenTelemetry SDK for metrics and traces, with the OpenTelemetry exporters matching to your current OpenCensus exporters. +// 2. Install this OpenCensus bridge, which sends OpenCensus telemetry to your new OpenTelemetry exporters. +// 3. Over time, migrate your instrumentation from OpenCensus to OpenTelemetry. +// 4. Once all instrumentation is migrated, remove the OpenCensus bridge. +// +// With this approach, you can migrate your telemetry, including in dependent +// libraries over time without disruption. +// +// # Warnings +// +// Installing a metric or tracing bridge will cause OpenCensus telemetry to be +// exported by OpenTelemetry exporters. Since OpenCensus telemetry uses globals, +// installing a bridge will result in telemetry collection from _all_ libraries +// that use OpenCensus, including some you may not expect, such as the +// telemetry exporter itself. +// +// # Limitations +// +// 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 +// implemented, and An error will be sent to the OpenTelemetry ErrorHandler. +// +// There are known limitations to the metric bridge: +// - Summary-typed metrics are dropped +// - GaugeDistribution-typed metrics are dropped +// - Histogram's SumOfSquaredDeviation field is dropped +// - Exemplars on Histograms are dropped package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus" diff --git a/bridge/opencensus/example_test.go b/bridge/opencensus/example_test.go new file mode 100644 index 00000000000..57fef19e168 --- /dev/null +++ b/bridge/opencensus/example_test.go @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package opencensus_test + +import ( + octrace "go.opencensus.io/trace" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/bridge/opencensus" + "go.opentelemetry.io/otel/sdk/metric" +) + +func ExampleNewTracer() { + // Create an OpenTelemetry Tracer to use to record spans. + tracer := otel.GetTracerProvider().Tracer("go.opentelemetry.io/otel/bridge/opencensus") + // Overwrite the OpenCensus DefaultTracer so that it uses OpenTelemetry + // rather than OpenCensus. + octrace.DefaultTracer = opencensus.NewTracer(tracer) +} + +func ExampleNewMetricProducer() { + // Create the OpenCensus Metric bridge. + bridge := opencensus.NewMetricProducer() + // Add the bridge as a producer to your reader. + // If using a push exporter, such as OTLP exporter, + // use metric.NewPeriodicReader with metric.WithProducer option. + // If using a pull exporter which acts as a reader, such as prometheus exporter, + // use a dedicated option like prometheus.WithProducer. + reader := metric.NewManualReader(metric.WithProducer(bridge)) + // Add the reader to your MeterProvider. + _ = metric.NewMeterProvider(metric.WithReader(reader)) +} diff --git a/bridge/opencensus/go.mod b/bridge/opencensus/go.mod index 752bf2794da..48f2d2a956d 100644 --- a/bridge/opencensus/go.mod +++ b/bridge/opencensus/go.mod @@ -5,10 +5,10 @@ go 1.20 require ( github.com/stretchr/testify v1.8.4 go.opencensus.io v0.24.0 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( @@ -18,7 +18,7 @@ require ( github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/kr/pretty v0.1.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/bridge/opencensus/metric.go b/bridge/opencensus/metric.go index c2e0be49052..1c2496d8c9b 100644 --- a/bridge/opencensus/metric.go +++ b/bridge/opencensus/metric.go @@ -18,15 +18,12 @@ import ( "context" ocmetricdata "go.opencensus.io/metric/metricdata" - "go.opencensus.io/metric/metricexport" "go.opencensus.io/metric/metricproducer" - "go.opentelemetry.io/otel" internal "go.opentelemetry.io/otel/bridge/opencensus/internal/ocmetric" "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" - "go.opentelemetry.io/otel/sdk/resource" ) const scopeName = "go.opentelemetry.io/otel/bridge/opencensus" @@ -60,40 +57,3 @@ func (p *producer) Produce(context.Context) ([]metricdata.ScopeMetrics, error) { Metrics: otelmetrics, }}, err } - -// exporter implements the OpenCensus metric Exporter interface using an -// OpenTelemetry base exporter. -type exporter struct { - base metric.Exporter - res *resource.Resource -} - -// NewMetricExporter returns an OpenCensus exporter that exports to an -// OpenTelemetry (push) exporter. -// -// Deprecated: Use [NewMetricProducer] instead. -func NewMetricExporter(base metric.Exporter, res *resource.Resource) metricexport.Exporter { - return &exporter{base: base, res: res} -} - -// ExportMetrics implements the OpenCensus metric Exporter interface by sending -// to an OpenTelemetry exporter. -func (e *exporter) ExportMetrics(ctx context.Context, ocmetrics []*ocmetricdata.Metric) error { - otelmetrics, err := internal.ConvertMetrics(ocmetrics) - if err != nil { - otel.Handle(err) - } - if len(otelmetrics) == 0 { - return nil - } - return e.base.Export(ctx, &metricdata.ResourceMetrics{ - Resource: e.res, - ScopeMetrics: []metricdata.ScopeMetrics{ - { - Scope: instrumentation.Scope{ - Name: scopeName, - }, - Metrics: otelmetrics, - }, - }}) -} diff --git a/bridge/opencensus/metric_test.go b/bridge/opencensus/metric_test.go index 58c11aadc0a..29ec835c8ba 100644 --- a/bridge/opencensus/metric_test.go +++ b/bridge/opencensus/metric_test.go @@ -16,7 +16,6 @@ package opencensus // import "go.opentelemetry.io/otel/bridge/opencensus" import ( "context" - "fmt" "testing" "time" @@ -27,10 +26,8 @@ import ( "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/sdk/instrumentation" - "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/metric/metricdata" "go.opentelemetry.io/otel/sdk/metric/metricdata/metricdatatest" - "go.opentelemetry.io/otel/sdk/resource" ) func TestMetricProducer(t *testing.T) { @@ -160,127 +157,3 @@ type fakeOCProducer struct { func (f *fakeOCProducer) Read() []*ocmetricdata.Metric { return f.metrics } - -func TestPushMetricsExporter(t *testing.T) { - now := time.Now() - for _, tc := range []struct { - desc string - input []*ocmetricdata.Metric - inputResource *resource.Resource - exportErr error - expected *metricdata.ResourceMetrics - expectErr bool - }{ - { - desc: "empty batch isn't sent", - }, - { - desc: "export error", - exportErr: fmt.Errorf("failed to export"), - input: []*ocmetricdata.Metric{ - { - Resource: &ocresource.Resource{ - Labels: map[string]string{ - "R1": "V1", - "R2": "V2", - }, - }, - TimeSeries: []*ocmetricdata.TimeSeries{ - { - StartTime: now, - Points: []ocmetricdata.Point{ - {Value: int64(123), Time: now}, - }, - }, - }, - }, - }, - expectErr: true, - }, - { - desc: "success", - input: []*ocmetricdata.Metric{ - { - Resource: &ocresource.Resource{ - Labels: map[string]string{ - "R1": "V1", - "R2": "V2", - }, - }, - TimeSeries: []*ocmetricdata.TimeSeries{ - { - StartTime: now, - Points: []ocmetricdata.Point{ - {Value: int64(123), Time: now}, - }, - }, - }, - }, - }, - inputResource: resource.NewSchemaless( - attribute.String("R1", "V1"), - attribute.String("R2", "V2"), - ), - expected: &metricdata.ResourceMetrics{ - Resource: resource.NewSchemaless( - attribute.String("R1", "V1"), - attribute.String("R2", "V2"), - ), - ScopeMetrics: []metricdata.ScopeMetrics{ - { - Scope: instrumentation.Scope{ - Name: scopeName, - }, - Metrics: []metricdata.Metrics{ - { - Name: "", - Description: "", - Unit: "", - Data: metricdata.Gauge[int64]{ - DataPoints: []metricdata.DataPoint[int64]{ - { - Attributes: attribute.NewSet(), - StartTime: now, - Time: now, - Value: 123, - }, - }, - }, - }, - }, - }, - }, - }, - }, - } { - t.Run(tc.desc, func(t *testing.T) { - fake := &fakeExporter{err: tc.exportErr} - exporter := NewMetricExporter(fake, tc.inputResource) - err := exporter.ExportMetrics(context.Background(), tc.input) - if tc.expectErr { - require.Error(t, err) - } else { - require.NoError(t, err) - } - if tc.expected != nil { - require.NotNil(t, fake.data) - metricdatatest.AssertEqual(t, *tc.expected, *fake.data) - } else { - require.Nil(t, fake.data) - } - }) - } -} - -type fakeExporter struct { - metric.Exporter - data *metricdata.ResourceMetrics - err error -} - -func (f *fakeExporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error { - if f.err == nil { - f.data = data - } - return f.err -} diff --git a/bridge/opencensus/test/go.mod b/bridge/opencensus/test/go.mod index c4c1950b328..139c3069b03 100644 --- a/bridge/opencensus/test/go.mod +++ b/bridge/opencensus/test/go.mod @@ -4,18 +4,18 @@ go 1.20 require ( go.opencensus.io v0.24.0 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/bridge/opencensus v0.41.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/bridge/opencensus v0.42.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/sdk/metric v0.41.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/bridge/opencensus/bridge.go b/bridge/opencensus/trace.go similarity index 100% rename from bridge/opencensus/bridge.go rename to bridge/opencensus/trace.go diff --git a/bridge/opentracing/go.mod b/bridge/opentracing/go.mod index 7bba77e050b..a225a4016cd 100644 --- a/bridge/opentracing/go.mod +++ b/bridge/opentracing/go.mod @@ -9,8 +9,8 @@ replace go.opentelemetry.io/otel/trace => ../../trace require ( github.com/opentracing/opentracing-go v1.2.0 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( @@ -18,7 +18,7 @@ require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/bridge/opentracing/test/go.mod b/bridge/opentracing/test/go.mod index e67bac8cb8d..796bd37f4f4 100644 --- a/bridge/opentracing/test/go.mod +++ b/bridge/opentracing/test/go.mod @@ -12,9 +12,9 @@ require ( github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e github.com/opentracing/opentracing-go v1.2.0 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/bridge/opentracing v1.18.0 - google.golang.org/grpc v1.58.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/bridge/opentracing v1.19.0 + google.golang.org/grpc v1.58.2 ) require ( @@ -23,8 +23,8 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/bridge/opentracing/test/go.sum b/bridge/opentracing/test/go.sum index b3b28952647..9849f15acb7 100644 --- a/bridge/opentracing/test/go.sum +++ b/bridge/opentracing/test/go.sum @@ -54,8 +54,8 @@ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoA google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/example/dice/doc.go b/example/dice/doc.go new file mode 100644 index 00000000000..5fe156fb977 --- /dev/null +++ b/example/dice/doc.go @@ -0,0 +1,16 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Dice is the "Roll the dice" getting started example application. +package main diff --git a/example/dice/go.mod b/example/dice/go.mod new file mode 100644 index 00000000000..d1e13586d73 --- /dev/null +++ b/example/dice/go.mod @@ -0,0 +1,35 @@ +module go.opentelemetry.io/otel/example/dice + +go 1.20 + +require ( + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 +) + +require ( + github.com/felixge/httpsnoop v1.0.3 // indirect + github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/stdr v1.2.2 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect + golang.org/x/sys v0.12.0 // indirect +) + +replace go.opentelemetry.io/otel/exporters/stdout/stdouttrace => ../../exporters/stdout/stdouttrace + +replace go.opentelemetry.io/otel/exporters/stdout/stdoutmetric => ../../exporters/stdout/stdoutmetric + +replace go.opentelemetry.io/otel => ../.. + +replace go.opentelemetry.io/otel/trace => ../../trace + +replace go.opentelemetry.io/otel/metric => ../../metric + +replace go.opentelemetry.io/otel/sdk/metric => ../../sdk/metric + +replace go.opentelemetry.io/otel/sdk => ../../sdk diff --git a/example/dice/go.sum b/example/dice/go.sum new file mode 100644 index 00000000000..b9534f5b329 --- /dev/null +++ b/example/dice/go.sum @@ -0,0 +1,16 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= +github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 h1:KfYpVmrjI7JuToy5k8XV3nkapjWx48k4E4JOtVstzQI= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0/go.mod h1:SeQhzAEccGVZVEy7aH87Nh0km+utSpo1pTv6eMMop48= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/example/dice/main.go b/example/dice/main.go new file mode 100644 index 00000000000..f7e0242906f --- /dev/null +++ b/example/dice/main.go @@ -0,0 +1,99 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "errors" + "log" + "net" + "net/http" + "os" + "os/signal" + "time" + + "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" +) + +func main() { + if err := run(); err != nil { + log.Fatalln(err) + } +} + +func run() (err error) { + // Handle SIGINT (CTRL+C) gracefully. + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) + defer stop() + + // Set up OpenTelemetry. + serviceName := "dice" + serviceVersion := "0.1.0" + otelShutdown, err := setupOTelSDK(ctx, serviceName, serviceVersion) + if err != nil { + return + } + // Handle shutdown properly so nothing leaks. + defer func() { + err = errors.Join(err, otelShutdown(context.Background())) + }() + + // Start HTTP server. + srv := &http.Server{ + Addr: ":8080", + BaseContext: func(_ net.Listener) context.Context { return ctx }, + ReadTimeout: time.Second, + WriteTimeout: 10 * time.Second, + Handler: newHTTPHandler(), + } + srvErr := make(chan error, 1) + go func() { + srvErr <- srv.ListenAndServe() + }() + + // Wait for interruption. + select { + case err = <-srvErr: + // Error when starting HTTP server. + return + case <-ctx.Done(): + // Wait for first CTRL+C. + // Stop receiving signal notifications as soon as possible. + stop() + } + + // When Shutdown is called, ListenAndServe immediately returns ErrServerClosed. + err = srv.Shutdown(context.Background()) + return +} + +func newHTTPHandler() http.Handler { + mux := http.NewServeMux() + + // handleFunc is a replacement for mux.HandleFunc + // which enriches the handler's HTTP instrumentation with the pattern as the http.route. + handleFunc := func(pattern string, handlerFunc func(http.ResponseWriter, *http.Request)) { + // Configure the "http.route" for the HTTP instrumentation. + handler := otelhttp.WithRouteTag(pattern, http.HandlerFunc(handlerFunc)) + mux.Handle(pattern, handler) + } + + // Register handlers. + handleFunc("/rolldice", rolldice) + + // Add HTTP instrumentation for the whole server. + handler := otelhttp.NewHandler(mux, "/") + return handler +} diff --git a/example/dice/otel.go b/example/dice/otel.go new file mode 100644 index 00000000000..8612352d959 --- /dev/null +++ b/example/dice/otel.go @@ -0,0 +1,118 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "errors" + "time" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" + "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" + "go.opentelemetry.io/otel/sdk/metric" + "go.opentelemetry.io/otel/sdk/resource" + "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.21.0" +) + +// setupOTelSDK bootstraps the OpenTelemetry pipeline. +// If it does not return an error, make sure to call shutdown for proper cleanup. +func setupOTelSDK(ctx context.Context, serviceName, serviceVersion string) (shutdown func(context.Context) error, err error) { + var shutdownFuncs []func(context.Context) error + + // shutdown calls cleanup functions registered via shutdownFuncs. + // The errors from the calls are joined. + // Each registered cleanup will be invoked once. + shutdown = func(ctx context.Context) error { + var err error + for _, fn := range shutdownFuncs { + err = errors.Join(err, fn(ctx)) + } + shutdownFuncs = nil + return err + } + + // handleErr calls shutdown for cleanup and makes sure that all errors are returned. + handleErr := func(inErr error) { + err = errors.Join(inErr, shutdown(ctx)) + } + + // Setup resource. + res, err := newResource(serviceName, serviceVersion) + if err != nil { + handleErr(err) + return + } + + // Setup trace provider. + tracerProvider, err := newTraceProvider(res) + if err != nil { + handleErr(err) + return + } + shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown) + otel.SetTracerProvider(tracerProvider) + + // Setup meter provider. + meterProvider, err := newMeterProvider(res) + if err != nil { + handleErr(err) + return + } + shutdownFuncs = append(shutdownFuncs, meterProvider.Shutdown) + otel.SetMeterProvider(meterProvider) + + return +} + +func newResource(serviceName, serviceVersion string) (*resource.Resource, error) { + return resource.Merge(resource.Default(), + resource.NewWithAttributes(semconv.SchemaURL, + semconv.ServiceName(serviceName), + semconv.ServiceVersion(serviceVersion), + )) +} + +func newTraceProvider(res *resource.Resource) (*trace.TracerProvider, error) { + traceExporter, err := stdouttrace.New( + stdouttrace.WithPrettyPrint()) + if err != nil { + return nil, err + } + + traceProvider := trace.NewTracerProvider( + trace.WithBatcher(traceExporter, + // Default is 5s. Set to 1s for demonstrative purposes. + trace.WithBatchTimeout(time.Second)), + trace.WithResource(res), + ) + return traceProvider, nil +} + +func newMeterProvider(res *resource.Resource) (*metric.MeterProvider, error) { + metricExporter, err := stdoutmetric.New() + if err != nil { + return nil, err + } + + meterProvider := metric.NewMeterProvider( + metric.WithResource(res), + metric.WithReader(metric.NewPeriodicReader(metricExporter, + // Default is 1m. Set to 3s for demonstrative purposes. + metric.WithInterval(3*time.Second))), + ) + return meterProvider, nil +} diff --git a/example/dice/rolldice.go b/example/dice/rolldice.go new file mode 100644 index 00000000000..10bd237c325 --- /dev/null +++ b/example/dice/rolldice.go @@ -0,0 +1,59 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "io" + "log" + "math/rand" + "net/http" + "strconv" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" +) + +var ( + tracer = otel.Tracer("rolldice") + meter = otel.Meter("rolldice") + rollCnt metric.Int64Counter +) + +func init() { + var err error + rollCnt, err = meter.Int64Counter("dice.rolls", + metric.WithDescription("The number of rolls by roll value"), + metric.WithUnit("{roll}")) + if err != nil { + panic(err) + } +} + +func rolldice(w http.ResponseWriter, r *http.Request) { + ctx, span := tracer.Start(r.Context(), "roll") + defer span.End() + + roll := 1 + rand.Intn(6) + + rollValueAttr := attribute.Int("roll.value", roll) + span.SetAttributes(rollValueAttr) + rollCnt.Add(ctx, 1, metric.WithAttributes(rollValueAttr)) + + resp := strconv.Itoa(roll) + "\n" + if _, err := io.WriteString(w, resp); err != nil { + log.Printf("Write failed: %v\n", err) + } +} diff --git a/example/fib/go.mod b/example/fib/go.mod index 05b7055d389..359be6c20de 100644 --- a/example/fib/go.mod +++ b/example/fib/go.mod @@ -3,16 +3,16 @@ module go.opentelemetry.io/otel/example/fib go 1.20 require ( - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/example/namedtracer/go.mod b/example/namedtracer/go.mod index 1340e16da72..50498093e16 100644 --- a/example/namedtracer/go.mod +++ b/example/namedtracer/go.mod @@ -9,15 +9,15 @@ replace ( require ( github.com/go-logr/stdr v1.2.2 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/example/opencensus/go.mod b/example/opencensus/go.mod index f5a0fc1dbc3..cc75b9ae829 100644 --- a/example/opencensus/go.mod +++ b/example/opencensus/go.mod @@ -10,20 +10,20 @@ replace ( require ( go.opencensus.io v0.24.0 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/bridge/opencensus v0.41.0 - go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.41.0 - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/bridge/opencensus v0.42.0 + go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v0.42.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/example/otel-collector/go.mod b/example/otel-collector/go.mod index bba14370c92..6470a15f2e3 100644 --- a/example/otel-collector/go.mod +++ b/example/otel-collector/go.mod @@ -8,11 +8,11 @@ replace ( ) require ( - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 - google.golang.org/grpc v1.58.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 + google.golang.org/grpc v1.58.2 ) require ( @@ -21,8 +21,8 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/proto/otlp v1.0.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect diff --git a/example/otel-collector/go.sum b/example/otel-collector/go.sum index 227a74e5462..aed78e17b32 100644 --- a/example/otel-collector/go.sum +++ b/example/otel-collector/go.sum @@ -31,8 +31,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1: google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/example/passthrough/go.mod b/example/passthrough/go.mod index ac285278df4..7d8c68534b1 100644 --- a/example/passthrough/go.mod +++ b/example/passthrough/go.mod @@ -3,16 +3,16 @@ module go.opentelemetry.io/otel/example/passthrough go 1.20 require ( - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/example/prometheus/go.mod b/example/prometheus/go.mod index 087729cc6c5..2c3510a0c24 100644 --- a/example/prometheus/go.mod +++ b/example/prometheus/go.mod @@ -4,10 +4,10 @@ go 1.20 require ( github.com/prometheus/client_golang v1.16.0 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/prometheus v0.41.0 - go.opentelemetry.io/otel/metric v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/prometheus v0.42.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 ) require ( @@ -20,8 +20,8 @@ require ( github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect - go.opentelemetry.io/otel/sdk v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/sdk v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/example/view/go.mod b/example/view/go.mod index 993173f2b7d..9b0f6224f19 100644 --- a/example/view/go.mod +++ b/example/view/go.mod @@ -4,11 +4,11 @@ go 1.20 require ( github.com/prometheus/client_golang v1.16.0 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/prometheus v0.41.0 - go.opentelemetry.io/otel/metric v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/prometheus v0.42.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 ) require ( @@ -21,7 +21,7 @@ require ( github.com/prometheus/client_model v0.4.0 // indirect github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/example/zipkin/go.mod b/example/zipkin/go.mod index f6910800cd3..95588af0609 100644 --- a/example/zipkin/go.mod +++ b/example/zipkin/go.mod @@ -9,17 +9,17 @@ replace ( ) require ( - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/zipkin v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/zipkin v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/openzipkin/zipkin-go v0.4.2 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect ) diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod b/exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod index 7f57062cee5..af9052af4f5 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/go.mod @@ -8,13 +8,13 @@ require ( github.com/cenkalti/backoff/v4 v4.2.1 github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.41.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 go.opentelemetry.io/proto/otlp v1.0.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 - google.golang.org/grpc v1.58.0 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 ) @@ -26,8 +26,8 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/go.sum b/exporters/otlp/otlpmetric/otlpmetricgrpc/go.sum index e4b12d31f5c..b3ae2009b4f 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/go.sum +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/go.sum @@ -39,8 +39,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1: google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/go.mod b/exporters/otlp/otlpmetric/otlpmetrichttp/go.mod index 0978e5d614d..f8da8eeb33c 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/go.mod +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/go.mod @@ -8,12 +8,12 @@ require ( github.com/cenkalti/backoff/v4 v4.2.1 github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.41.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.42.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 go.opentelemetry.io/proto/otlp v1.0.0 - google.golang.org/grpc v1.58.0 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 ) @@ -25,8 +25,8 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/go.sum b/exporters/otlp/otlpmetric/otlpmetrichttp/go.sum index e4b12d31f5c..b3ae2009b4f 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/go.sum +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/go.sum @@ -39,8 +39,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1: google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/exporters/otlp/otlpmetric/version.go b/exporters/otlp/otlpmetric/version.go index 371e3b50b0e..b4ecccdfb40 100644 --- a/exporters/otlp/otlpmetric/version.go +++ b/exporters/otlp/otlpmetric/version.go @@ -16,5 +16,5 @@ package otlpmetric // import "go.opentelemetry.io/otel/exporters/otlp/otlpmetric // Version is the current release version of the OpenTelemetry OTLP metrics exporter in use. func Version() string { - return "0.41.0" + return "0.42.0" } diff --git a/exporters/otlp/otlptrace/go.mod b/exporters/otlp/otlptrace/go.mod index a6d40e9c98f..06c08197355 100644 --- a/exporters/otlp/otlptrace/go.mod +++ b/exporters/otlp/otlptrace/go.mod @@ -5,9 +5,9 @@ go 1.20 require ( github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 go.opentelemetry.io/proto/otlp v1.0.0 google.golang.org/protobuf v1.31.0 ) @@ -19,7 +19,7 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/exporters/otlp/otlptrace/otlptracegrpc/client_test.go b/exporters/otlp/otlptrace/otlptracegrpc/client_test.go index b25606d232d..aa531eb926e 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/client_test.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/client_test.go @@ -188,7 +188,7 @@ func TestNewCollectorOnBadConnection(t *testing.T) { endpoint := fmt.Sprintf("localhost:%s", collectorPortStr) ctx := context.Background() exp := newGRPCExporter(t, ctx, endpoint) - _ = exp.Shutdown(ctx) + require.NoError(t, exp.Shutdown(ctx)) } func TestNewWithEndpoint(t *testing.T) { @@ -197,7 +197,7 @@ func TestNewWithEndpoint(t *testing.T) { ctx := context.Background() exp := newGRPCExporter(t, ctx, mc.endpoint) - _ = exp.Shutdown(ctx) + require.NoError(t, exp.Shutdown(ctx)) } func TestNewWithHeaders(t *testing.T) { diff --git a/exporters/otlp/otlptrace/otlptracegrpc/go.mod b/exporters/otlp/otlptrace/otlptracegrpc/go.mod index a424a624dea..08f543f4c41 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/go.mod +++ b/exporters/otlp/otlptrace/otlptracegrpc/go.mod @@ -5,14 +5,14 @@ go 1.20 require ( github.com/cenkalti/backoff/v4 v4.2.1 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 go.opentelemetry.io/proto/otlp v1.0.0 go.uber.org/goleak v1.2.1 google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 - google.golang.org/grpc v1.58.0 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 ) @@ -24,7 +24,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/exporters/otlp/otlptrace/otlptracegrpc/go.sum b/exporters/otlp/otlptrace/otlptracegrpc/go.sum index 36088fe05c8..1838dbbf406 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/go.sum +++ b/exporters/otlp/otlptrace/otlptracegrpc/go.sum @@ -40,8 +40,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1: google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/exporters/otlp/otlptrace/otlptracehttp/example_test.go b/exporters/otlp/otlptrace/otlptracehttp/example_test.go index 56f78af67ef..05f27212059 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/example_test.go +++ b/exporters/otlp/otlptrace/otlptracehttp/example_test.go @@ -30,7 +30,7 @@ import ( const ( instrumentationName = "github.com/instrumentron" - instrumentationVersion = "v0.1.0" + instrumentationVersion = "0.1.0" ) var ( diff --git a/exporters/otlp/otlptrace/otlptracehttp/go.mod b/exporters/otlp/otlptrace/otlptracehttp/go.mod index 1e93b05047c..ebea9d1f2ad 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/go.mod +++ b/exporters/otlp/otlptrace/otlptracehttp/go.mod @@ -5,12 +5,12 @@ go 1.20 require ( github.com/cenkalti/backoff/v4 v4.2.1 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 go.opentelemetry.io/proto/otlp v1.0.0 - google.golang.org/grpc v1.58.0 + google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 ) @@ -22,7 +22,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect golang.org/x/text v0.11.0 // indirect diff --git a/exporters/otlp/otlptrace/otlptracehttp/go.sum b/exporters/otlp/otlptrace/otlptracehttp/go.sum index 2fd37969a31..822ed05cfc9 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/go.sum +++ b/exporters/otlp/otlptrace/otlptracehttp/go.sum @@ -38,8 +38,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 h1: google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U= google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM= -google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o= -google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= +google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I= +google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= diff --git a/exporters/otlp/otlptrace/version.go b/exporters/otlp/otlptrace/version.go index 661c146c223..10ac73ee3b8 100644 --- a/exporters/otlp/otlptrace/version.go +++ b/exporters/otlp/otlptrace/version.go @@ -16,5 +16,5 @@ package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace" // Version is the current release version of the OpenTelemetry OTLP trace exporter in use. func Version() string { - return "1.18.0" + return "1.19.0" } diff --git a/exporters/prometheus/config_test.go b/exporters/prometheus/config_test.go index d209fdf3fbd..b759cfe98f5 100644 --- a/exporters/prometheus/config_test.go +++ b/exporters/prometheus/config_test.go @@ -151,7 +151,7 @@ func TestNewConfig(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { cfg := newConfig(tt.options...) - // only check the length of readerOpts, since they are not compareable + // only check the length of readerOpts, since they are not comparable assert.Equal(t, len(tt.wantConfig.readerOpts), len(cfg.readerOpts)) cfg.readerOpts = nil tt.wantConfig.readerOpts = nil diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index c88e82a1385..8973b2028e6 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -45,7 +45,11 @@ const ( scopeInfoDescription = "Instrumentation Scope metadata" ) -var scopeInfoKeys = [2]string{"otel_scope_name", "otel_scope_version"} +var ( + scopeInfoKeys = [2]string{"otel_scope_name", "otel_scope_version"} + + errScopeInvalid = errors.New("invalid scope") +) // Exporter is a Prometheus Exporter that embeds the OTel metric.Reader // interface for easy instantiation with a MeterProvider. @@ -87,6 +91,7 @@ type collector struct { disableTargetInfo bool targetInfo prometheus.Metric scopeInfos map[instrumentation.Scope]prometheus.Metric + scopeInfosInvalid map[instrumentation.Scope]struct{} metricFamilies map[string]*dto.MetricFamily } @@ -110,6 +115,7 @@ func New(opts ...Option) (*Exporter, error) { withoutCounterSuffixes: cfg.withoutCounterSuffixes, disableScopeInfo: cfg.disableScopeInfo, scopeInfos: make(map[instrumentation.Scope]prometheus.Metric), + scopeInfosInvalid: make(map[instrumentation.Scope]struct{}), metricFamilies: make(map[string]*dto.MetricFamily), namespace: cfg.namespace, } @@ -177,6 +183,10 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { if !c.disableScopeInfo { scopeInfo, err := c.scopeInfo(scopeMetrics.Scope) + if err == errScopeInvalid { + // Do not report the same error multiple times. + continue + } if err != nil { otel.Handle(err) continue @@ -469,8 +479,13 @@ func (c *collector) scopeInfo(scope instrumentation.Scope) (prometheus.Metric, e return scopeInfo, nil } + if _, ok := c.scopeInfosInvalid[scope]; ok { + return nil, errScopeInvalid + } + scopeInfo, err := createScopeInfoMetric(scope) if err != nil { + c.scopeInfosInvalid[scope] = struct{}{} return nil, fmt.Errorf("cannot create scope info metric: %w", err) } diff --git a/exporters/prometheus/exporter_test.go b/exporters/prometheus/exporter_test.go index 86cc8dc0b20..89fc87df3b9 100644 --- a/exporters/prometheus/exporter_test.go +++ b/exporters/prometheus/exporter_test.go @@ -16,6 +16,7 @@ package prometheus import ( "context" + "io" "os" "sync" "testing" @@ -25,6 +26,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" otelmetric "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/sdk/metric" @@ -790,6 +792,14 @@ func TestCollectorConcurrentSafe(t *testing.T) { } func TestIncompatibleMeterName(t *testing.T) { + defer func(orig otel.ErrorHandler) { + otel.SetErrorHandler(orig) + }(otel.GetErrorHandler()) + + errs := []error{} + eh := otel.ErrorHandlerFunc(func(e error) { errs = append(errs, e) }) + otel.SetErrorHandler(eh) + // This test checks that Prometheus exporter ignores // when it encounters incompatible meter name. @@ -815,4 +825,13 @@ func TestIncompatibleMeterName(t *testing.T) { err = testutil.GatherAndCompare(registry, file) require.NoError(t, err) + + assert.Equal(t, 1, len(errs)) + + // A second collect shouldn't trigger new errors + _, err = file.Seek(0, io.SeekStart) + assert.NoError(t, err) + err = testutil.GatherAndCompare(registry, file) + require.NoError(t, err) + assert.Equal(t, 1, len(errs)) } diff --git a/exporters/prometheus/go.mod b/exporters/prometheus/go.mod index f6021df58fb..45ab7d28df2 100644 --- a/exporters/prometheus/go.mod +++ b/exporters/prometheus/go.mod @@ -6,10 +6,10 @@ require ( github.com/prometheus/client_golang v1.16.0 github.com/prometheus/client_model v0.4.0 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/metric v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 google.golang.org/protobuf v1.31.0 ) @@ -26,7 +26,7 @@ require ( github.com/prometheus/common v0.42.0 // indirect github.com/prometheus/procfs v0.10.1 // indirect github.com/rogpeppe/go-internal v1.10.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/exporters/stdout/stdoutmetric/config.go b/exporters/stdout/stdoutmetric/config.go index 6189c019f37..cac5afeeb67 100644 --- a/exporters/stdout/stdoutmetric/config.go +++ b/exporters/stdout/stdoutmetric/config.go @@ -15,6 +15,7 @@ package stdoutmetric // import "go.opentelemetry.io/otel/exporters/stdout/stdout import ( "encoding/json" + "io" "os" "go.opentelemetry.io/otel/sdk/metric" @@ -22,6 +23,7 @@ import ( // config contains options for the exporter. type config struct { + prettyPrint bool encoder *encoderHolder temporalitySelector metric.TemporalitySelector aggregationSelector metric.AggregationSelector @@ -37,10 +39,15 @@ func newConfig(options ...Option) config { if cfg.encoder == nil { enc := json.NewEncoder(os.Stdout) - enc.SetIndent("", "\t") cfg.encoder = &encoderHolder{encoder: enc} } + if cfg.prettyPrint { + if e, ok := cfg.encoder.encoder.(*json.Encoder); ok { + e.SetIndent("", "\t") + } + } + if cfg.temporalitySelector == nil { cfg.temporalitySelector = metric.DefaultTemporalitySelector } @@ -74,6 +81,22 @@ func WithEncoder(encoder Encoder) Option { }) } +// WithWriter sets the export stream destination. +// Using this option overrides any previously set encoder. +func WithWriter(w io.Writer) Option { + return WithEncoder(json.NewEncoder(w)) +} + +// WithPrettyPrint prettifies the emitted output. +// This option only works if the encoder is a *json.Encoder, as is the case +// when using `WithWriter`. +func WithPrettyPrint() Option { + return optionFunc(func(c config) config { + c.prettyPrint = true + return c + }) +} + // WithTemporalitySelector sets the TemporalitySelector the exporter will use // to determine the Temporality of an instrument based on its kind. If this // option is not used, the exporter will use the DefaultTemporalitySelector diff --git a/exporters/stdout/stdoutmetric/example_test.go b/exporters/stdout/stdoutmetric/example_test.go index a3e7377914f..c0e250f4e4c 100644 --- a/exporters/stdout/stdoutmetric/example_test.go +++ b/exporters/stdout/stdoutmetric/example_test.go @@ -41,7 +41,7 @@ var ( Resource: res, ScopeMetrics: []metricdata.ScopeMetrics{ { - Scope: instrumentation.Scope{Name: "example", Version: "v0.0.1"}, + Scope: instrumentation.Scope{Name: "example", Version: "0.0.1"}, Metrics: []metricdata.Metrics{ { Name: "requests", @@ -173,7 +173,7 @@ func Example() { // { // "Scope": { // "Name": "example", - // "Version": "v0.0.1", + // "Version": "0.0.1", // "SchemaURL": "" // }, // "Metrics": [ diff --git a/exporters/stdout/stdoutmetric/exporter_test.go b/exporters/stdout/stdoutmetric/exporter_test.go index 71679d623a1..2dbfe6357a2 100644 --- a/exporters/stdout/stdoutmetric/exporter_test.go +++ b/exporters/stdout/stdoutmetric/exporter_test.go @@ -15,6 +15,7 @@ package stdoutmetric_test // import "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" import ( + "bytes" "context" "encoding/json" "io" @@ -103,6 +104,43 @@ func deltaSelector(metric.InstrumentKind) metricdata.Temporality { return metricdata.DeltaTemporality } +func TestExportWithOptions(t *testing.T) { + var ( + data = new(metricdata.ResourceMetrics) + ctx = context.Background() + ) + + for _, tt := range []struct { + name string + opts []stdoutmetric.Option + + expectedData string + }{ + { + name: "with no options", + expectedData: "{\"Resource\":null,\"ScopeMetrics\":null}\n", + }, + { + name: "with pretty print", + opts: []stdoutmetric.Option{ + stdoutmetric.WithPrettyPrint(), + }, + expectedData: "{\n\t\"Resource\": null,\n\t\"ScopeMetrics\": null\n}\n", + }, + } { + t.Run(tt.name, func(t *testing.T) { + var b bytes.Buffer + opts := append(tt.opts, stdoutmetric.WithWriter(&b)) + + exp, err := stdoutmetric.New(opts...) + require.NoError(t, err) + require.NoError(t, exp.Export(ctx, data)) + + assert.Equal(t, tt.expectedData, b.String()) + }) + } +} + func TestTemporalitySelector(t *testing.T) { exp, err := stdoutmetric.New( testEncoderOption(), diff --git a/exporters/stdout/stdoutmetric/go.mod b/exporters/stdout/stdoutmetric/go.mod index 128911273f7..028903bf998 100644 --- a/exporters/stdout/stdoutmetric/go.mod +++ b/exporters/stdout/stdoutmetric/go.mod @@ -4,9 +4,9 @@ go 1.20 require ( github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/sdk/metric v0.41.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/sdk/metric v1.19.0 ) require ( @@ -14,8 +14,8 @@ require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/exporters/stdout/stdouttrace/config.go b/exporters/stdout/stdouttrace/config.go index 2cb534a75e9..2d765435495 100644 --- a/exporters/stdout/stdouttrace/config.go +++ b/exporters/stdout/stdouttrace/config.go @@ -71,7 +71,7 @@ func (o writerOption) apply(cfg config) config { return cfg } -// WithPrettyPrint sets the export stream format to use JSON. +// WithPrettyPrint prettifies the emitted output. func WithPrettyPrint() Option { return prettyPrintOption(true) } diff --git a/exporters/stdout/stdouttrace/example_test.go b/exporters/stdout/stdouttrace/example_test.go index 5e3a5064568..a3634296e7a 100644 --- a/exporters/stdout/stdouttrace/example_test.go +++ b/exporters/stdout/stdouttrace/example_test.go @@ -29,7 +29,7 @@ import ( const ( instrumentationName = "github.com/instrumentron" - instrumentationVersion = "v0.1.0" + instrumentationVersion = "0.1.0" ) var ( diff --git a/exporters/stdout/stdouttrace/go.mod b/exporters/stdout/stdouttrace/go.mod index a604b804fae..70177f0d88f 100644 --- a/exporters/stdout/stdouttrace/go.mod +++ b/exporters/stdout/stdouttrace/go.mod @@ -9,9 +9,9 @@ replace ( require ( github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( @@ -19,7 +19,7 @@ require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/exporters/zipkin/go.mod b/exporters/zipkin/go.mod index 03fc1cef1e8..f1376901874 100644 --- a/exporters/zipkin/go.mod +++ b/exporters/zipkin/go.mod @@ -8,15 +8,15 @@ require ( github.com/google/go-cmp v0.5.9 github.com/openzipkin/zipkin-go v0.4.2 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.mod b/go.mod index 1d71e9627e4..9ecfdb50f74 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/go-logr/stdr v1.2.2 github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel/metric v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 ) require ( diff --git a/internal/tools/go.mod b/internal/tools/go.mod index ae996729f3d..b8713b02069 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -9,11 +9,11 @@ require ( github.com/itchyny/gojq v0.12.13 github.com/jcchavezs/porto v0.4.0 github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad - go.opentelemetry.io/build-tools/crosslink v0.11.0 - go.opentelemetry.io/build-tools/dbotconf v0.11.0 - go.opentelemetry.io/build-tools/gotmpl v0.11.0 - go.opentelemetry.io/build-tools/multimod v0.11.0 - go.opentelemetry.io/build-tools/semconvgen v0.11.0 + go.opentelemetry.io/build-tools/crosslink v0.12.0 + go.opentelemetry.io/build-tools/dbotconf v0.12.0 + go.opentelemetry.io/build-tools/gotmpl v0.12.0 + go.opentelemetry.io/build-tools/multimod v0.12.0 + go.opentelemetry.io/build-tools/semconvgen v0.12.0 golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea golang.org/x/tools v0.13.0 ) @@ -32,7 +32,7 @@ require ( github.com/Masterminds/semver v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/OpenPeeDeeP/depguard/v2 v2.1.0 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/alexkohler/nakedret/v2 v2.0.2 // indirect github.com/alexkohler/prealloc v1.0.0 // indirect @@ -53,6 +53,7 @@ require ( github.com/chavacava/garif v0.0.0-20230227094218-b8c73b2037b8 // indirect github.com/cloudflare/circl v1.3.3 // indirect github.com/curioswitch/go-reassign v0.2.0 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/daixiang0/gci v0.11.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/denis-tingaikin/go-header v0.4.3 // indirect @@ -66,8 +67,8 @@ require ( github.com/fzipp/gocyclo v0.6.0 // indirect github.com/go-critic/go-critic v0.9.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.4.1 // indirect - github.com/go-git/go-git/v5 v5.8.1 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-git/go-git/v5 v5.9.0 // indirect github.com/go-toolsmith/astcast v1.1.0 // indirect github.com/go-toolsmith/astcopy v1.1.0 // indirect github.com/go-toolsmith/astequal v1.1.0 // indirect @@ -191,11 +192,10 @@ require ( github.com/yeya24/promlinter v0.2.0 // indirect github.com/ykadowak/zerologlint v0.1.3 // indirect gitlab.com/bosi/decorder v0.4.0 // indirect - go.opentelemetry.io/build-tools v0.11.0 // indirect + go.opentelemetry.io/build-tools v0.12.0 // indirect go.tmz.dev/musttag v0.7.2 // indirect - go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.11.0 // indirect - go.uber.org/zap v1.24.0 // indirect + go.uber.org/zap v1.26.0 // indirect golang.org/x/crypto v0.13.0 // indirect golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect golang.org/x/mod v0.12.0 // indirect diff --git a/internal/tools/go.sum b/internal/tools/go.sum index 6ce63a44950..6b4c7209fe2 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -65,8 +65,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/OpenPeeDeeP/depguard/v2 v2.1.0 h1:aQl70G173h/GZYhWf36aE5H0KaujXfVMnn/f1kSDVYY= github.com/OpenPeeDeeP/depguard/v2 v2.1.0/go.mod h1:PUBgk35fX4i7JDmwzlJwJ+GMe6NfO1723wmJMgPThNQ= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -86,7 +86,6 @@ github.com/ashanbrown/forbidigo v1.6.0 h1:D3aewfM37Yb3pxHujIPSpTf6oQk9sc9WZi8ger github.com/ashanbrown/forbidigo v1.6.0/go.mod h1:Y8j9jy9ZYAEHXdu723cUlraTqbzjKF1MUyfOKL+AjcU= github.com/ashanbrown/makezero v1.1.1 h1:iCQ87C0V0vSyO+M9E/FZYbu65auqH0lnsOkf5FcB28s= github.com/ashanbrown/makezero v1.1.1/go.mod h1:i1bJLCRSCHOcOa9Y6MyF2FTfMZMFdHvxKHxgO5Z1axI= -github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -128,9 +127,10 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/curioswitch/go-reassign v0.2.0 h1:G9UZyOcpk/d7Gd6mqYgd8XYWFMw/znxwGDUstnC9DIo= github.com/curioswitch/go-reassign v0.2.0/go.mod h1:x6OpXuWvgfQaMGks2BZybTngWjT84hqJfKoO8Tt/Roc= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/daixiang0/gci v0.11.0 h1:XeQbFKkCRxvVyn06EOuNY6LPGBLVuB/W130c8FrnX6A= github.com/daixiang0/gci v0.11.0/go.mod h1:xtHP9N7AHdNvtRNfcx9gwTDfw7FRJx4bZUsiEfiNNAI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -138,7 +138,7 @@ 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/denis-tingaikin/go-header v0.4.3 h1:tEaZKAlqql6SKCY++utLmkPLd6K8IBM20Ha7UVm+mtU= github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c= -github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -167,11 +167,11 @@ github.com/go-critic/go-critic v0.9.0 h1:Pmys9qvU3pSML/3GEQ2Xd9RZ/ip+aXHKILuxczK github.com/go-critic/go-critic v0.9.0/go.mod h1:5P8tdXL7m/6qnyG6oRAlYLORvoXH0WDypYgAEmagT40= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= -github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8= -github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= -github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= +github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY= +github.com/go-git/go-git/v5 v5.9.0/go.mod h1:RKIqga24sWdMGZF+1Ekv9kylsDz6LzdTSI2s/OsZWE0= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -366,12 +366,10 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kulti/thelper v0.6.3 h1:ElhKf+AlItIu+xGnI990no4cE2+XaSu1ULymV2Yulxs= github.com/kulti/thelper v0.6.3/go.mod h1:DsqKShOvP40epevkFrvIwkCMNYxMeTNjdWL4dqWHZ6I= github.com/kunwardeep/paralleltest v1.0.8 h1:Ul2KsqtzFxTlSU7IP0JusWlLiNqQaloB9vguyjbE558= @@ -427,7 +425,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nakabonne/nestif v0.3.1 h1:wm28nZjhQY5HyYPx+weN3Q65k6ilSBxDb8v5S81B81U= github.com/nakabonne/nestif v0.3.1/go.mod h1:9EtoZochLn5iUprVDmDjqGKPofoUEBL8U4Ngq6aY7OE= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nishanths/exhaustive v0.11.0 h1:T3I8nUGhl/Cwu5Z2hfc92l0e04D2GEW6e0l8pzda2l0= github.com/nishanths/exhaustive v0.11.0/go.mod h1:RqwDsZ1xY0dNdqHho2z6X+bgzizwbLYOWnZbbl2wLB4= github.com/nishanths/predeclared v0.2.2 h1:V2EPdZPliZymNAn79T8RkNApBjMmVKh5XRpLm/w98Vk= @@ -495,7 +492,7 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryancurrah/gomodguard v1.3.0 h1:q15RT/pd6UggBXVBuLps8BXRvl5GPBcwVA7BJHMLuTw= github.com/ryancurrah/gomodguard v1.3.0/go.mod h1:ggBxb3luypPEzqVtq33ee7YSN35V28XeGnid8dnni50= @@ -620,27 +617,25 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opentelemetry.io/build-tools v0.11.0 h1:yXTgCJM/vxWZEB8FbgVhKOAFnRlacG2Z3eoTQZ0/gYE= -go.opentelemetry.io/build-tools v0.11.0/go.mod h1:GFpz8YD/DG5shfY1J2f3uuK88zr61U5rVRGOhKMDE9M= -go.opentelemetry.io/build-tools/crosslink v0.11.0 h1:K0eJY/AT6SiIaoJSrQyiVquGErcJEHsx4oHkhxvpj9k= -go.opentelemetry.io/build-tools/crosslink v0.11.0/go.mod h1:h5oxbHx+O50aO0/M7mFejZmd7cMONdsmmC+IOmgWoWw= -go.opentelemetry.io/build-tools/dbotconf v0.11.0 h1:hG0Zyln9Vv+kwNC+ip/EUcLnd9osTZ8dOYOxe/lHZy4= -go.opentelemetry.io/build-tools/dbotconf v0.11.0/go.mod h1:BxYX1iAki4EWzIVXeEPFM75ZWr9e9koqT7pTU5xzad4= -go.opentelemetry.io/build-tools/gotmpl v0.11.0 h1:T2KJ7Eli7wLrp+8TXpUQ+Q+wAdZZDiyHYSvrpeER7Pc= -go.opentelemetry.io/build-tools/gotmpl v0.11.0/go.mod h1:FzweYUfAJC1i5ATrtFI4KJggnO9QQGPdSVKWA8RHjdE= -go.opentelemetry.io/build-tools/multimod v0.11.0 h1:QMo2Y4BlsTsWUR0LXV4gmiv5yEiX2iPLn2qAdAcCE6k= -go.opentelemetry.io/build-tools/multimod v0.11.0/go.mod h1:EID7sjEGyk1FWzRdsV6rlWp43IIn8iHXGE5pM4TytyQ= -go.opentelemetry.io/build-tools/semconvgen v0.11.0 h1:gQsNzy49l9JjNozybaRUl+vy0EMxYasV8w6aK+IWquc= -go.opentelemetry.io/build-tools/semconvgen v0.11.0/go.mod h1:Zy04Bw3w3lT7mORe23V2BwjfJYpoza6Xz1XSMIrLTCg= +go.opentelemetry.io/build-tools v0.12.0 h1:ZqK1GuqBp9Mf1RthYO3/jjf9tPWzeHMcVDo0itFi/lI= +go.opentelemetry.io/build-tools v0.12.0/go.mod h1:I76Qvv9cN055XJfTHw9t257EUd5Yp0EofeTMESlZuRU= +go.opentelemetry.io/build-tools/crosslink v0.12.0 h1:GNJQURuabE5rAkIbnrqndIKyXrr7wFy54e/8ujkgjHg= +go.opentelemetry.io/build-tools/crosslink v0.12.0/go.mod h1:QE8Kxf4Ygg2ltSHE+Vdys/67jtQM26j7spJLyjNA2DU= +go.opentelemetry.io/build-tools/dbotconf v0.12.0 h1:I+oaEtAMK+nd660l//r14d3AI1A8BB3A4hKArvUX/n4= +go.opentelemetry.io/build-tools/dbotconf v0.12.0/go.mod h1:K0Xszcb11bbFtVpjieY8gzGWLw9SNarDKvFW1Ti7w4U= +go.opentelemetry.io/build-tools/gotmpl v0.12.0 h1:ysCtNFkoJddyaAdemtdbI6Qn7nb7GYn2WbHmajTW+pM= +go.opentelemetry.io/build-tools/gotmpl v0.12.0/go.mod h1:FzweYUfAJC1i5ATrtFI4KJggnO9QQGPdSVKWA8RHjdE= +go.opentelemetry.io/build-tools/multimod v0.12.0 h1:DKi+A+4EaKrOZDTNDDZz3ijiAduEQDo8j1rzWUaGUHo= +go.opentelemetry.io/build-tools/multimod v0.12.0/go.mod h1:w03q3WgZs7reoBNnmfdClkKdTIA/IHM8ric5E2jEDD0= +go.opentelemetry.io/build-tools/semconvgen v0.12.0 h1:AsjYFwo8sSLAjwjklj+yVwm2xogJUxRf5pxflATg9N0= +go.opentelemetry.io/build-tools/semconvgen v0.12.0/go.mod h1:SRmou8pp+7gBmf1AvdxOTwVts74Syyrgm1/Qx7R8mis= go.tmz.dev/musttag v0.7.2 h1:1J6S9ipDbalBSODNT5jCep8dhZyMr4ttnjQagmGYR5s= go.tmz.dev/musttag v0.7.2/go.mod h1:m6q5NiiSKMnQYokefa2xGoyoXnrswCbJ0AWYzf4Zs28= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= +go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= -go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= -go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -1035,7 +1030,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/metric/example_test.go b/metric/example_test.go index 35d7f4218e2..5c28d2f2926 100644 --- a/metric/example_test.go +++ b/metric/example_test.go @@ -16,18 +16,23 @@ package metric_test import ( "context" + "database/sql" "fmt" + "net/http" "runtime" "time" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" + semconv "go.opentelemetry.io/otel/semconv/v1.21.0" ) +var meter = otel.Meter("my-service-meter") + func ExampleMeter_synchronous() { // Create a histogram using the global MeterProvider. - workDuration, err := otel.Meter("go.opentelemetry.io/otel/metric#SyncExample").Int64Histogram( + workDuration, err := meter.Int64Histogram( "workDuration", metric.WithUnit("ms")) if err != nil { @@ -43,8 +48,6 @@ func ExampleMeter_synchronous() { } func ExampleMeter_asynchronous_single() { - meter := otel.Meter("go.opentelemetry.io/otel/metric#AsyncExample") - _, err := meter.Int64ObservableGauge( "DiskUsage", metric.WithUnit("By"), @@ -73,8 +76,6 @@ func ExampleMeter_asynchronous_single() { } func ExampleMeter_asynchronous_multiple() { - meter := otel.Meter("go.opentelemetry.io/otel/metric#MultiAsyncExample") - // This is just a sample of memory stats to record from the Memstats heapAlloc, err := meter.Int64ObservableUpDownCounter("heapAllocs") if err != nil { @@ -106,3 +107,175 @@ func ExampleMeter_asynchronous_multiple() { panic(err) } } + +// Counters can be used to measure a non-negative, increasing value. +// +// Here's how you might report the number of calls for an HTTP handler. +func ExampleMeter_counter() { + apiCounter, err := meter.Int64Counter( + "api.counter", + metric.WithDescription("Number of API calls."), + metric.WithUnit("{call}"), + ) + if err != nil { + panic(err) + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + apiCounter.Add(r.Context(), 1) + + // do some work in an API call + }) +} + +// UpDown counters can increment and decrement, allowing you to observe +// a cumulative value that goes up or down. +// +// Here's how you might report the number of items of some collection. +func ExampleMeter_upDownCounter() { + var err error + itemsCounter, err := meter.Int64UpDownCounter( + "items.counter", + metric.WithDescription("Number of items."), + metric.WithUnit("{item}"), + ) + if err != nil { + panic(err) + } + + _ = func() { + // code that adds an item to the collection + itemsCounter.Add(context.Background(), 1) + } + + _ = func() { + // code that removes an item from the collection + itemsCounter.Add(context.Background(), -1) + } +} + +// Histograms are used to measure a distribution of values over time. +// +// Here's how you might report a distribution of response times for an HTTP handler. +func ExampleMeter_histogram() { + histogram, err := meter.Float64Histogram( + "task.duration", + metric.WithDescription("The duration of task execution."), + metric.WithUnit("s"), + ) + if err != nil { + panic(err) + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + start := time.Now() + + // do some work in an API call + + duration := time.Since(start) + histogram.Record(r.Context(), duration.Seconds()) + }) +} + +// Observable counters can be used to measure an additive, non-negative, +// monotonically increasing value. +// +// Here's how you might report time since the application started. +func ExampleMeter_observableCounter() { + start := time.Now() + if _, err := meter.Float64ObservableCounter( + "uptime", + metric.WithDescription("The duration since the application started."), + metric.WithUnit("s"), + metric.WithFloat64Callback(func(_ context.Context, o metric.Float64Observer) error { + o.Observe(float64(time.Since(start).Seconds())) + return nil + }), + ); err != nil { + panic(err) + } +} + +// Observable UpDown counters can increment and decrement, allowing you to measure +// an additive, non-negative, non-monotonically increasing cumulative value. +// +// Here's how you might report some database metrics. +func ExampleMeter_observableUpDownCounter() { + // The function registers asynchronous metrics for the provided db. + // Make sure to unregister metric.Registration before closing the provided db. + _ = func(db *sql.DB, meter metric.Meter, poolName string) (metric.Registration, error) { + max, err := meter.Int64ObservableUpDownCounter( + "db.client.connections.max", + metric.WithDescription("The maximum number of open connections allowed."), + metric.WithUnit("{connection}"), + ) + if err != nil { + return nil, err + } + + waitTime, err := meter.Int64ObservableUpDownCounter( + "db.client.connections.wait_time", + metric.WithDescription("The time it took to obtain an open connection from the pool."), + metric.WithUnit("ms"), + ) + if err != nil { + return nil, err + } + + reg, err := meter.RegisterCallback( + func(_ context.Context, o metric.Observer) error { + stats := db.Stats() + o.ObserveInt64(max, int64(stats.MaxOpenConnections)) + o.ObserveInt64(waitTime, int64(stats.WaitDuration)) + return nil + }, + max, + waitTime, + ) + if err != nil { + return nil, err + } + return reg, nil + } +} + +// Observable Gauges should be used to measure non-additive values. +// +// Here's how you might report memory usage of the heap objects used +// in application. +func ExampleMeter_observableGauge() { + if _, err := meter.Int64ObservableGauge( + "memory.heap", + metric.WithDescription( + "Memory usage of the allocated heap objects.", + ), + metric.WithUnit("By"), + metric.WithInt64Callback(func(_ context.Context, o metric.Int64Observer) error { + var m runtime.MemStats + runtime.ReadMemStats(&m) + o.Observe(int64(m.HeapAlloc)) + return nil + }), + ); err != nil { + panic(err) + } +} + +// You can add Attributes by using the [WithAttributeSet] and [WithAttributes] options. +// +// Here's how you might add the HTTP status code attribute to your recordings. +func ExampleMeter_attributes() { + apiCounter, err := meter.Int64UpDownCounter( + "api.finished.counter", + metric.WithDescription("Number of finished API calls."), + metric.WithUnit("{call}"), + ) + if err != nil { + panic(err) + } + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + // do some work in an API call and set the response HTTP status code + statusCode := http.StatusOK + + apiCounter.Add(r.Context(), 1, + metric.WithAttributes(semconv.HTTPStatusCode(statusCode))) + }) +} diff --git a/metric/go.mod b/metric/go.mod index 49d6e8755ef..9579b924641 100644 --- a/metric/go.mod +++ b/metric/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 + go.opentelemetry.io/otel v1.19.0 ) require ( @@ -12,7 +12,7 @@ require ( github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/schema/go.mod b/schema/go.mod index 0c2d3e6d00f..bfc2ab62789 100644 --- a/schema/go.mod +++ b/schema/go.mod @@ -5,11 +5,10 @@ go 1.20 require ( github.com/Masterminds/semver/v3 v3.2.1 github.com/stretchr/testify v1.8.4 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/schema/go.sum b/schema/go.sum index f9c91c9cccd..839fe61dc7b 100644 --- a/schema/go.sum +++ b/schema/go.sum @@ -8,7 +8,5 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/schema/v1.0/parser.go b/schema/v1.0/parser.go index a284606bd9c..75a09bb0687 100644 --- a/schema/v1.0/parser.go +++ b/schema/v1.0/parser.go @@ -18,7 +18,7 @@ import ( "io" "os" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "go.opentelemetry.io/otel/schema/internal" "go.opentelemetry.io/otel/schema/v1.0/ast" @@ -43,6 +43,7 @@ func ParseFile(schemaFilePath string) (*ast.Schema, error) { func Parse(schemaFileContent io.Reader) (*ast.Schema, error) { var ts ast.Schema d := yaml.NewDecoder(schemaFileContent) + d.KnownFields(true) err := d.Decode(&ts) if err != nil { return nil, err diff --git a/schema/v1.0/parser_test.go b/schema/v1.0/parser_test.go index ab47452db72..36aba51ea5e 100644 --- a/schema/v1.0/parser_test.go +++ b/schema/v1.0/parser_test.go @@ -168,6 +168,10 @@ func TestFailParseSchemaFile(t *testing.T) { ts, err = ParseFile("testdata/invalid-schema-url.yaml") assert.Error(t, err) assert.Nil(t, ts) + + ts, err = ParseFile("testdata/unknown-field.yaml") + assert.ErrorContains(t, err, "field Resources not found in type ast.VersionDef") + assert.Nil(t, ts) } func TestFailParseSchema(t *testing.T) { diff --git a/schema/v1.0/testdata/unknown-field.yaml b/schema/v1.0/testdata/unknown-field.yaml new file mode 100644 index 00000000000..0d344e44cd9 --- /dev/null +++ b/schema/v1.0/testdata/unknown-field.yaml @@ -0,0 +1,15 @@ +file_format: 1.0.0 +schema_url: https://opentelemetry.io/schemas/1.0.0 + +versions: + 1.1.0: + all: # Valid entry. + changes: + - rename_attributes: + k8s.cluster.name: kubernetes.cluster.name + Resources: # Invalid uppercase. + changes: + - rename_attributes: + attribute_map: + browser.user_agent: user_agent.original + 1.0.0: diff --git a/schema/v1.1/parser.go b/schema/v1.1/parser.go index 1e1ca8db56c..43b70524f38 100644 --- a/schema/v1.1/parser.go +++ b/schema/v1.1/parser.go @@ -18,7 +18,7 @@ import ( "io" "os" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "go.opentelemetry.io/otel/schema/internal" "go.opentelemetry.io/otel/schema/v1.1/ast" @@ -43,7 +43,7 @@ func ParseFile(schemaFilePath string) (*ast.Schema, error) { func Parse(schemaFileContent io.Reader) (*ast.Schema, error) { var ts ast.Schema d := yaml.NewDecoder(schemaFileContent) - d.SetStrict(true) // Do not silently drop unknown fields. + d.KnownFields(true) err := d.Decode(&ts) if err != nil { return nil, err diff --git a/sdk/go.mod b/sdk/go.mod index 8bbab5328a1..6d707d62441 100644 --- a/sdk/go.mod +++ b/sdk/go.mod @@ -8,8 +8,8 @@ require ( github.com/go-logr/logr v1.2.4 github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/trace v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/trace v1.19.0 golang.org/x/sys v0.12.0 ) @@ -17,7 +17,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/metric v1.18.0 // indirect + go.opentelemetry.io/otel/metric v1.19.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/metric/aggregation.go b/sdk/metric/aggregation.go index 08ff6cc3dd8..faddbb0b61b 100644 --- a/sdk/metric/aggregation.go +++ b/sdk/metric/aggregation.go @@ -48,8 +48,8 @@ func (AggregationDrop) err() error { return nil } // make an aggregation selection based on instrument kind that differs from // the default. This Aggregation ensures the default is used. // -// See the "go.opentelemetry.io/otel/sdk/metric".DefaultAggregationSelector -// for information about the default instrument kind selection mapping. +// See the [DefaultAggregationSelector] for information about the default +// instrument kind selection mapping. type AggregationDefault struct{} // AggregationDefault has no parameters. var _ Aggregation = AggregationDefault{} @@ -161,7 +161,7 @@ type AggregationBase2ExponentialHistogram struct { // signed 32-bit integer index could be used. // // MaxScale has a minimum value of -10. Using a value of -10 means only - // two buckets will be use. + // two buckets will be used. MaxScale int32 // NoMinMax indicates whether to not record the min and max of the diff --git a/sdk/metric/doc.go b/sdk/metric/doc.go index 92878ce8bc2..53f80c42893 100644 --- a/sdk/metric/doc.go +++ b/sdk/metric/doc.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package metric provides an implementation of the OpenTelemetry metric SDK. +// Package metric provides an implementation of the OpenTelemetry metrics SDK. // // See https://opentelemetry.io/docs/concepts/signals/metrics/ for information // about the concept of OpenTelemetry metrics and @@ -27,8 +27,8 @@ // A MeterProvider needs to be configured to export the measured data, this is // done by configuring it with a Reader implementation (using the WithReader // MeterProviderOption). Readers take two forms: ones that push to an endpoint -// (NewPeriodicReader), and ones that an endpoint pulls from. See the -// go.opentelemetry.io/otel/exporters package for exporters that can be used as +// (NewPeriodicReader), and ones that an endpoint pulls from. See +// [go.opentelemetry.io/otel/exporters] for exporters that can be used as // or with these Readers. // // Each Reader, when registered with the MeterProvider, can be augmented with a @@ -41,4 +41,7 @@ // should be used to describe the unique runtime environment instrumented code // is being run on. That way when multiple instances of the code are collected // at a single endpoint their origin is decipherable. +// +// See [go.opentelemetry.io/otel/metric] for more information about +// the metric API. package metric // import "go.opentelemetry.io/otel/sdk/metric" diff --git a/sdk/metric/example_test.go b/sdk/metric/example_test.go index cf8728deb0f..81a59343bea 100644 --- a/sdk/metric/example_test.go +++ b/sdk/metric/example_test.go @@ -16,45 +16,238 @@ package metric_test import ( "context" + "fmt" "log" + "regexp" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/sdk/instrumentation" "go.opentelemetry.io/otel/sdk/metric" "go.opentelemetry.io/otel/sdk/resource" semconv "go.opentelemetry.io/otel/semconv/v1.21.0" ) +// To enable metrics in your application using the SDK, +// you'll need to have an initialized [MeterProvider] +// that will let you create a [go.opentelemetry.io/otel/metric.Meter]. +// +// Here's how you might initialize a metrics provider. func Example() { + // Create resource. + res, err := resource.Merge(resource.Default(), + resource.NewWithAttributes(semconv.SchemaURL, + semconv.ServiceName("my-service"), + semconv.ServiceVersion("0.1.0"), + )) + if err != nil { + log.Fatalln(err) + } + // This reader is used as a stand-in for a reader that will actually export - // data. See exporters in the go.opentelemetry.io/otel/exporters package - // for more information. + // data. See https://pkg.go.dev/go.opentelemetry.io/otel/exporters for + // exporters that can be used as or with readers. reader := metric.NewManualReader() - // See the go.opentelemetry.io/otel/sdk/resource package for more - // information about how to create and use Resources. - res := resource.NewWithAttributes( - semconv.SchemaURL, - semconv.ServiceName("my-service"), - semconv.ServiceVersion("v0.1.0"), - ) - + // Create a meter provider. + // You can pass this instance directly to your instrumented code if it + // accepts a MeterProvider instance. meterProvider := metric.NewMeterProvider( metric.WithResource(res), metric.WithReader(reader), ) - otel.SetMeterProvider(meterProvider) + + // Handle shutdown properly so that nothing leaks. defer func() { err := meterProvider.Shutdown(context.Background()) if err != nil { log.Fatalln(err) } }() - // The MeterProvider is configured and registered globally. You can now run - // your code instrumented with the OpenTelemetry API that uses the global - // MeterProvider without having to pass this MeterProvider instance. Or, - // you can pass this instance directly to your instrumented code if it - // accepts a MeterProvider instance. + + // Register as global meter provider so that it can be used via otel.Meter + // and accessed using otel.GetMeterProvider. + // Most instrumentation libraries use the global meter provider as default. + // If the global meter provider is not set then a no-op implementation + // is used, which fails to generate data. + otel.SetMeterProvider(meterProvider) +} + +func ExampleView() { + // The NewView function provides convenient creation of common Views + // construction. However, it is limited in what it can create. // - // See the go.opentelemetry.io/otel/metric package for more information - // about the metric API. + // When NewView is not able to provide the functionally needed, a custom + // View can be constructed directly. Here a custom View is constructed that + // uses Go's regular expression matching to ensure all data stream names + // have a suffix of the units it uses. + + re := regexp.MustCompile(`[._](ms|byte)$`) + var view metric.View = func(i metric.Instrument) (metric.Stream, bool) { + // In a custom View function, you need to explicitly copy + // the name, description, and unit. + s := metric.Stream{Name: i.Name, Description: i.Description, Unit: i.Unit} + // Any instrument that does not have a unit suffix defined, but has a + // dimensional unit defined, update the name with a unit suffix. + if re.MatchString(i.Name) { + return s, false + } + switch i.Unit { + case "ms": + s.Name += ".ms" + case "By": + s.Name += ".byte" + default: + return s, false + } + return s, true + } + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) + + // Below is an example of how the view will + // function in the SDK for certain instruments. + stream, _ := view(metric.Instrument{ + Name: "computation.time.ms", + Unit: "ms", + }) + fmt.Println("name:", stream.Name) + + stream, _ = view(metric.Instrument{ + Name: "heap.size", + Unit: "By", + }) + fmt.Println("name:", stream.Name) + // Output: + // name: computation.time.ms + // name: heap.size.byte +} + +func ExampleNewView() { + // Create a view that renames the "latency" instrument from the v0.34.0 + // version of the "http" instrumentation library as "request.latency". + view := metric.NewView(metric.Instrument{ + Name: "latency", + Scope: instrumentation.Scope{ + Name: "http", + Version: "0.34.0", + }, + }, metric.Stream{Name: "request.latency"}) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) + + // Below is an example of how the view will + // function in the SDK for certain instruments. + stream, _ := view(metric.Instrument{ + Name: "latency", + Description: "request latency", + Unit: "ms", + Kind: metric.InstrumentKindCounter, + Scope: instrumentation.Scope{ + Name: "http", + Version: "0.34.0", + SchemaURL: "https://opentelemetry.io/schemas/1.0.0", + }, + }) + fmt.Println("name:", stream.Name) + fmt.Println("description:", stream.Description) + fmt.Println("unit:", stream.Unit) + // Output: + // name: request.latency + // description: request latency + // unit: ms +} + +func ExampleNewView_wildcard() { + // Create a view that sets unit to milliseconds for any instrument with a + // name suffix of ".ms". + view := metric.NewView( + metric.Instrument{Name: "*.ms"}, + metric.Stream{Unit: "ms"}, + ) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) + + // Below is an example of how the view will + // function in the SDK for certain instruments. + stream, _ := view(metric.Instrument{ + Name: "computation.time.ms", + Unit: "1", + }) + fmt.Println("name:", stream.Name) + fmt.Println("unit:", stream.Unit) + // Output: + // name: computation.time.ms + // unit: ms +} + +func ExampleNewView_drop() { + // Create a view that drops the "latency" instrument from the "http" + // instrumentation library. + view := metric.NewView( + metric.Instrument{ + Name: "latency", + Scope: instrumentation.Scope{Name: "http"}, + }, + metric.Stream{Aggregation: metric.AggregationDrop{}}, + ) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) +} + +func ExampleNewView_attributeFilter() { + // Create a view that removes the "http.request.method" attribute recorded + // by the "latency" instrument from the "http" instrumentation library. + view := metric.NewView( + metric.Instrument{ + Name: "latency", + Scope: instrumentation.Scope{Name: "http"}, + }, + metric.Stream{AttributeFilter: attribute.NewDenyKeysFilter("http.request.method")}, + ) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) +} + +func ExampleNewView_exponentialHistogram() { + // Create a view that makes the "latency" instrument from the "http" + // instrumentation library to be reported as an exponential histogram. + view := metric.NewView( + metric.Instrument{ + Name: "latency", + Scope: instrumentation.Scope{Name: "http"}, + }, + metric.Stream{ + Aggregation: metric.AggregationBase2ExponentialHistogram{ + MaxSize: 160, + MaxScale: 20, + }, + }, + ) + + // The created view can then be registered with the OpenTelemetry metric + // SDK using the WithView option. + _ = metric.NewMeterProvider( + metric.WithView(view), + ) } diff --git a/sdk/metric/go.mod b/sdk/metric/go.mod index 171889f9299..bf140b694b6 100644 --- a/sdk/metric/go.mod +++ b/sdk/metric/go.mod @@ -6,15 +6,15 @@ require ( github.com/go-logr/logr v1.2.4 github.com/go-logr/stdr v1.2.2 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 - go.opentelemetry.io/otel/metric v1.18.0 - go.opentelemetry.io/otel/sdk v1.18.0 + go.opentelemetry.io/otel v1.19.0 + go.opentelemetry.io/otel/metric v1.19.0 + go.opentelemetry.io/otel/sdk v1.19.0 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - go.opentelemetry.io/otel/trace v1.18.0 // indirect + go.opentelemetry.io/otel/trace v1.19.0 // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/sdk/metric/meter.go b/sdk/metric/meter.go index 9d2de67c594..e5ec1ad4675 100644 --- a/sdk/metric/meter.go +++ b/sdk/metric/meter.go @@ -28,7 +28,7 @@ import ( var ( // ErrInstrumentName indicates the created instrument has an invalid name. - // Valid names must consist of 255 or fewer characters including alphanumeric, _, ., -, and start with a letter. + // Valid names must consist of 255 or fewer characters including alphanumeric, _, ., -, / and start with a letter. ErrInstrumentName = errors.New("invalid instrument name") ) @@ -262,8 +262,8 @@ func validateInstrumentName(name string) error { return nil } for _, c := range name[1:] { - if !isAlphanumeric(c) && c != '_' && c != '.' && c != '-' { - return fmt.Errorf("%w: %s: must only contain [A-Za-z0-9_.-]", ErrInstrumentName, name) + if !isAlphanumeric(c) && c != '_' && c != '.' && c != '-' && c != '/' { + return fmt.Errorf("%w: %s: must only contain [A-Za-z0-9_.-/]", ErrInstrumentName, name) } } return nil diff --git a/sdk/metric/meter_test.go b/sdk/metric/meter_test.go index 7c1d21f96cd..34a95ab7026 100644 --- a/sdk/metric/meter_test.go +++ b/sdk/metric/meter_test.go @@ -775,9 +775,12 @@ func TestValidateInstrumentName(t *testing.T) { { name: "nam.", }, + { + name: "nam/e", + }, { name: "name!", - wantErr: fmt.Errorf("%w: name!: must only contain [A-Za-z0-9_.-]", ErrInstrumentName), + wantErr: fmt.Errorf("%w: name!: must only contain [A-Za-z0-9_.-/]", ErrInstrumentName), }, { name: longName, diff --git a/sdk/metric/reader.go b/sdk/metric/reader.go index 44e09fb355d..65cedaf3c07 100644 --- a/sdk/metric/reader.go +++ b/sdk/metric/reader.go @@ -74,7 +74,7 @@ type Reader interface { // the SDK and stores it in out. An error is returned if this is called // after Shutdown or if out is nil. // - // This method needs to be concurrent safe, and the cancelation of the + // This method needs to be concurrent safe, and the cancellation of the // passed context is expected to be honored. Collect(ctx context.Context, rm *metricdata.ResourceMetrics) error // DO NOT CHANGE: any modification will not be backwards compatible and diff --git a/sdk/metric/version.go b/sdk/metric/version.go index 90bdd5c17c4..3de4e06dc4d 100644 --- a/sdk/metric/version.go +++ b/sdk/metric/version.go @@ -16,5 +16,5 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric" // version is the current release version of the metric SDK in use. func version() string { - return "0.41.0" + return "1.19.0" } diff --git a/sdk/metric/view.go b/sdk/metric/view.go index e4f350e1912..65f243befed 100644 --- a/sdk/metric/view.go +++ b/sdk/metric/view.go @@ -42,10 +42,10 @@ type View func(Instrument) (Stream, bool) // view that matches no instruments is returned. If you need to match a // zero-value field, create a View directly. // -// The Name field of criteria supports wildcard pattern matching. The wildcard -// "*" is recognized as matching zero or more characters, and "?" is recognized -// as matching exactly one character. For example, a pattern of "*" will match -// all instrument names. +// The Name field of criteria supports wildcard pattern matching. The "*" +// wildcard is recognized as matching zero or more characters, and "?" is +// recognized as matching exactly one character. For example, a pattern of "*" +// matches all instrument names. // // The Stream mask only applies updates for non-zero-value fields. By default, // the Instrument the View matches against will be use for the Name, diff --git a/sdk/metric/view_test.go b/sdk/metric/view_test.go index d9e3f9b6c81..0cf5646f243 100644 --- a/sdk/metric/view_test.go +++ b/sdk/metric/view_test.go @@ -15,8 +15,6 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric" import ( - "fmt" - "regexp" "testing" "github.com/go-logr/logr" @@ -493,134 +491,3 @@ func TestNewViewMultiInstMatchErrorLogged(t *testing.T) { }) assert.Contains(t, got, errMultiInst.Error()) } - -func ExampleNewView() { - // Create a view that renames the "latency" instrument from the v0.34.0 - // version of the "http" instrumentation library as "request.latency". - view := NewView(Instrument{ - Name: "latency", - Scope: instrumentation.Scope{ - Name: "http", - Version: "v0.34.0", - }, - }, Stream{Name: "request.latency"}) - - // The created view can then be registered with the OpenTelemetry metric - // SDK using the WithView option. Below is an example of how the view will - // function in the SDK for certain instruments. - - stream, _ := view(Instrument{ - Name: "latency", - Description: "request latency", - Unit: "ms", - Kind: InstrumentKindCounter, - Scope: instrumentation.Scope{ - Name: "http", - Version: "v0.34.0", - SchemaURL: "https://opentelemetry.io/schemas/1.0.0", - }, - }) - fmt.Println("name:", stream.Name) - fmt.Println("description:", stream.Description) - fmt.Println("unit:", stream.Unit) - // Output: - // name: request.latency - // description: request latency - // unit: ms -} - -func ExampleNewView_drop() { - // Create a view that sets the drop aggregator for all instrumentation from - // the "db" library, effectively turning-off all instrumentation from that - // library. - view := NewView( - Instrument{Scope: instrumentation.Scope{Name: "db"}}, - Stream{Aggregation: AggregationDrop{}}, - ) - - // The created view can then be registered with the OpenTelemetry metric - // SDK using the WithView option. Below is an example of how the view will - // function in the SDK for certain instruments. - - stream, _ := view(Instrument{ - Name: "queries", - Kind: InstrumentKindCounter, - Scope: instrumentation.Scope{Name: "db", Version: "v0.4.0"}, - }) - fmt.Println("name:", stream.Name) - fmt.Printf("aggregation: %#v", stream.Aggregation) - // Output: - // name: queries - // aggregation: metric.AggregationDrop{} -} - -func ExampleNewView_wildcard() { - // Create a view that sets unit to milliseconds for any instrument with a - // name suffix of ".ms". - view := NewView( - Instrument{Name: "*.ms"}, - Stream{Unit: "ms"}, - ) - - // The created view can then be registered with the OpenTelemetry metric - // SDK using the WithView option. Below is an example of how the view - // function in the SDK for certain instruments. - - stream, _ := view(Instrument{ - Name: "computation.time.ms", - Unit: "1", - }) - fmt.Println("name:", stream.Name) - fmt.Println("unit:", stream.Unit) - // Output: - // name: computation.time.ms - // unit: ms -} - -func ExampleView() { - // The NewView function provides convenient creation of common Views - // construction. However, it is limited in what it can create. - // - // When NewView is not able to provide the functionally needed, a custom - // View can be constructed directly. Here a custom View is constructed that - // uses Go's regular expression matching to ensure all data stream names - // have a suffix of the units it uses. - - re := regexp.MustCompile(`[._](ms|byte)$`) - var view View = func(i Instrument) (Stream, bool) { - s := Stream{Name: i.Name, Description: i.Description, Unit: i.Unit} - // Any instrument that does not have a unit suffix defined, but has a - // dimensional unit defined, update the name with a unit suffix. - if re.MatchString(i.Name) { - return s, false - } - switch i.Unit { - case "ms": - s.Name += ".ms" - case "By": - s.Name += ".byte" - default: - return s, false - } - return s, true - } - - // The created view can then be registered with the OpenTelemetry metric - // SDK using the WithView option. Below is an example of how the view will - // function in the SDK for certain instruments. - - stream, _ := view(Instrument{ - Name: "computation.time.ms", - Unit: "ms", - }) - fmt.Println("name:", stream.Name) - - stream, _ = view(Instrument{ - Name: "heap.size", - Unit: "By", - }) - fmt.Println("name:", stream.Name) - // Output: - // name: computation.time.ms - // name: heap.size.byte -} diff --git a/sdk/version.go b/sdk/version.go index 756bfed7588..72d2cb09f7b 100644 --- a/sdk/version.go +++ b/sdk/version.go @@ -16,5 +16,5 @@ package sdk // import "go.opentelemetry.io/otel/sdk" // Version is the current release version of the OpenTelemetry SDK in use. func Version() string { - return "1.18.0" + return "1.19.0" } diff --git a/trace/go.mod b/trace/go.mod index 50128ca4893..d20100801bb 100644 --- a/trace/go.mod +++ b/trace/go.mod @@ -7,7 +7,7 @@ replace go.opentelemetry.io/otel => ../ require ( github.com/google/go-cmp v0.5.9 github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.18.0 + go.opentelemetry.io/otel v1.19.0 ) require ( diff --git a/version.go b/version.go index d5f2746880d..ad64e199672 100644 --- a/version.go +++ b/version.go @@ -16,5 +16,5 @@ package otel // import "go.opentelemetry.io/otel" // Version is the current release version of OpenTelemetry in use. func Version() string { - return "1.18.0" + return "1.19.0" } diff --git a/versions.yaml b/versions.yaml index a4952d4934f..7d212769240 100644 --- a/versions.yaml +++ b/versions.yaml @@ -14,11 +14,12 @@ module-sets: stable-v1: - version: v1.18.0 + version: v1.19.0 modules: - go.opentelemetry.io/otel - go.opentelemetry.io/otel/bridge/opentracing - go.opentelemetry.io/otel/bridge/opentracing/test + - go.opentelemetry.io/otel/example/dice - go.opentelemetry.io/otel/example/fib - go.opentelemetry.io/otel/example/namedtracer - go.opentelemetry.io/otel/example/otel-collector @@ -31,23 +32,23 @@ module-sets: - go.opentelemetry.io/otel/exporters/zipkin - go.opentelemetry.io/otel/metric - go.opentelemetry.io/otel/sdk + - go.opentelemetry.io/otel/sdk/metric - go.opentelemetry.io/otel/trace experimental-metrics: - version: v0.41.0 + version: v0.42.0 modules: + - go.opentelemetry.io/otel/bridge/opencensus + - go.opentelemetry.io/otel/bridge/opencensus/test - go.opentelemetry.io/otel/example/opencensus - go.opentelemetry.io/otel/example/prometheus + - go.opentelemetry.io/otel/example/view - go.opentelemetry.io/otel/exporters/otlp/otlpmetric - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp - go.opentelemetry.io/otel/exporters/prometheus - go.opentelemetry.io/otel/exporters/stdout/stdoutmetric - - go.opentelemetry.io/otel/sdk/metric - - go.opentelemetry.io/otel/bridge/opencensus - - go.opentelemetry.io/otel/bridge/opencensus/test - - go.opentelemetry.io/otel/example/view experimental-schema: - version: v0.0.6 + version: v0.0.7 modules: - go.opentelemetry.io/otel/schema excluded-modules: