├── .mockery.yaml ├── .gitignore ├── .golangci.yaml ├── config.go ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── metrics.go ├── justfile ├── LICENSE ├── config_test.go ├── noop_test.go ├── mocks ├── embedded │ ├── Span.go │ ├── Meter.go │ ├── Tracer.go │ ├── Observer.go │ ├── Int64Gauge.go │ ├── Float64Gauge.go │ ├── Int64Counter.go │ ├── Registration.go │ ├── Int64Observer.go │ ├── MeterProvider.go │ ├── Float64Counter.go │ ├── Int64Histogram.go │ ├── TracerProvider.go │ ├── Float64Observer.go │ ├── Float64Histogram.go │ ├── Int64UpDownCounter.go │ ├── Float64UpDownCounter.go │ ├── Int64ObservableGauge.go │ ├── Float64ObservableGauge.go │ ├── Int64ObservableCounter.go │ ├── Float64ObservableCounter.go │ ├── Int64ObservableUpDownCounter.go │ └── Float64ObservableUpDownCounter.go ├── metric │ ├── Observable.go │ ├── AddOption.go │ ├── Callback.go │ ├── MeterOption.go │ ├── meterOptionFunc.go │ ├── RecordOption.go │ ├── ObserveOption.go │ ├── Int64Callback.go │ ├── Float64Callback.go │ ├── Int64GaugeOption.go │ ├── Float64GaugeOption.go │ ├── Int64CounterOption.go │ ├── Float64CounterOption.go │ ├── Int64HistogramOption.go │ ├── Float64HistogramOption.go │ ├── Int64Observable.go │ ├── Int64UpDownCounterOption.go │ ├── Float64Observable.go │ ├── Float64UpDownCounterOption.go │ ├── Int64ObservableGaugeOption.go │ ├── Float64ObservableGaugeOption.go │ ├── Int64ObservableCounterOption.go │ ├── Registration.go │ ├── Float64ObservableCounterOption.go │ ├── Int64ObservableUpDownCounterOption.go │ ├── Float64ObservableUpDownCounterOption.go │ ├── Int64Gauge.go │ ├── Int64Observer.go │ ├── Int64Counter.go │ ├── Float64Observer.go │ ├── Float64Gauge.go │ ├── Float64Counter.go │ ├── Int64Histogram.go │ ├── Float64Histogram.go │ └── Int64UpDownCounter.go └── trace │ ├── TracerOption.go │ ├── EventOption.go │ ├── spanOptionFunc.go │ ├── SpanEndOption.go │ ├── tracerOptionFunc.go │ ├── SpanStartOption.go │ └── SpanOption.go ├── noop.go ├── middleware.go ├── providers.go ├── README.md ├── go.mod ├── middleware_test.go └── gotel_test.go /.mockery.yaml: -------------------------------------------------------------------------------- 1 | filename: "{{.InterfaceName}}.go" 2 | dir: "mocks/{{.PackageName}}" 3 | issue-845-fix: True 4 | packages: 5 | go.opentelemetry.io/otel/trace: 6 | config: 7 | all: true 8 | recursive: true 9 | with-expecter: true 10 | go.opentelemetry.io/otel/metric: 11 | config: 12 | all: true 13 | recursive: true 14 | with-expecter: true 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # If you prefer the allow list template instead of the deny list, see community template: 2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore 3 | # 4 | # Binaries for programs and plugins 5 | *.exe 6 | *.exe~ 7 | *.dll 8 | *.so 9 | *.dylib 10 | 11 | # Test binary, built with `go test -c` 12 | *.test 13 | 14 | # Output of the go coverage tool, specifically when used with LiteIDE 15 | *.out 16 | 17 | # Dependency directories (remove the comment below to include it) 18 | # vendor/ 19 | 20 | # Go workspace file 21 | go.work 22 | go.work.sum 23 | 24 | # env file 25 | .env 26 | -------------------------------------------------------------------------------- /.golangci.yaml: -------------------------------------------------------------------------------- 1 | run: 2 | timeout: 10m 3 | issues: 4 | exclude-dirs: 5 | - "mocks" 6 | exclude-rules: 7 | - path: noop.go 8 | linters: 9 | - ireturn 10 | - nilnil 11 | - path: _test\.go 12 | linters: 13 | - funlen 14 | - dupl 15 | linters: 16 | enable-all: true 17 | disable: [ 18 | "paralleltest", 19 | "exportloopref", 20 | "depguard", 21 | "exhaustruct", 22 | "forbidigo", 23 | "revive", 24 | "gochecknoglobals", 25 | "gochecknoinits", 26 | "gofumpt", 27 | "errcheck", 28 | "varnamelen", 29 | "wsl", 30 | "mnd", 31 | "lll", 32 | "gci", 33 | "gomnd", 34 | "execinquery", 35 | "interfacebloat" 36 | ] 37 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | package gotel 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/caarlos0/env" 7 | ) 8 | 9 | // Config holds the configuration for the telemetry. 10 | type Config struct { 11 | ServiceName string `env:"SERVICE_NAME" envDefault:"gotel"` 12 | ServiceVersion string `env:"SERVICE_VERSION" envDefault:"0.0.1"` 13 | Enabled bool `env:"TELEMETRY_ENABLED" envDefault:"true"` 14 | } 15 | 16 | // NewConfigFromEnv creates a new telemetry config from the environment. 17 | func NewConfigFromEnv() (Config, error) { 18 | telem := Config{} 19 | if err := env.Parse(&telem); err != nil { 20 | return Config{}, fmt.Errorf("failed to parse telemetry config: %w", err) 21 | } 22 | 23 | return telem, nil 24 | } 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "monthly" 12 | - package-ecosystem: "github-actions" # See documentation for possible values 13 | directory: "./workflows" # Location of package manifests 14 | schedule: 15 | interval: "monthly" 16 | -------------------------------------------------------------------------------- /metrics.go: -------------------------------------------------------------------------------- 1 | package gotel 2 | 3 | // Metric represents a metric that can be collected by the server. 4 | type Metric struct { 5 | Name string 6 | Unit string 7 | Description string 8 | } 9 | 10 | // MetricRequestDurationMillis is a metric that measures the latency of HTTP requests processed by the server, in milliseconds. 11 | var MetricRequestDurationMillis = Metric{ 12 | Name: "request_duration_millis", 13 | Unit: "ms", 14 | Description: "Measures the latency of HTTP requests processed by the server, in milliseconds.", 15 | } 16 | 17 | // MetricRequestsInFlight is a metric that measures the number of requests currently being processed by the server. 18 | var MetricRequestsInFlight = Metric{ 19 | Name: "requests_inflight", 20 | Unit: "{count}", 21 | Description: "Measures the number of requests currently being processed by the server.", 22 | } 23 | -------------------------------------------------------------------------------- /justfile: -------------------------------------------------------------------------------- 1 | # Justfile 2 | # 3 | # To run a recipe: 4 | # just 5 | # 6 | # Example: 7 | # just build 8 | # 9 | 10 | set unstable := true 11 | 12 | # Default recipe 13 | default: help 14 | 15 | # Show help message 16 | help: 17 | @just --list 18 | 19 | # Build the gotel package 20 | build: 21 | go build . 22 | 23 | # Run linter (--fix to fix issues) 24 | lint *ARGS: 25 | golangci-lint run {{ ARGS }} 26 | 27 | # Run tests (--json to output coverage in json format) 28 | [script] 29 | test json="": 30 | if [ "{{ json }}" = "--json" ]; then 31 | go test -cover -json -race -v ./... | tee coverage.json 32 | else 33 | go test -race -v ./... 34 | fi 35 | 36 | # Generate mocks 37 | gen-mocks: 38 | mockery 39 | 40 | # Install dependencies 41 | [script] 42 | deps: 43 | go install github.com/vektra/mockery/v2@v2.50.0 44 | go install github.com/mfridman/tparse@latest 45 | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)"/bin v1.61.0 46 | go mod download -x 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Luca Cavallin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: gotel CI 5 | 6 | on: 7 | push: 8 | branches: ["main"] 9 | pull_request: 10 | branches: ["main"] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - uses: extractions/setup-just@v2 19 | 20 | - name: Set up Go 21 | uses: actions/setup-go@v4 22 | with: 23 | go-version-file: go.mod 24 | 25 | - name: Install dependencies 26 | run: just deps 27 | 28 | - name: Ensure generated files are up to date 29 | run: | 30 | just gen-mocks 31 | git diff --exit-code || true 32 | 33 | - name: Lint 34 | run: just lint 35 | 36 | - name: Build gotel 37 | run: just build 38 | 39 | - name: Test 40 | run: just test --json 41 | 42 | - name: Write test coverage report 43 | if: success() || failure() 44 | run: tparse -all -file=coverage.json -format=markdown | tee coverage.md 45 | -------------------------------------------------------------------------------- /config_test.go: -------------------------------------------------------------------------------- 1 | package gotel_test 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "github.com/lucavallin/gotel" 8 | "github.com/stretchr/testify/assert" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestNewConfigFromEnv(t *testing.T) { 13 | tests := []struct { 14 | name string 15 | envVars map[string]string 16 | want gotel.Config 17 | wantErr bool 18 | }{ 19 | { 20 | name: "success with default values", 21 | envVars: map[string]string{}, 22 | want: gotel.Config{ 23 | ServiceName: "test-service", 24 | ServiceVersion: "0.0.1", 25 | Enabled: true, 26 | }, 27 | wantErr: false, 28 | }, 29 | { 30 | name: "success with custom values", 31 | envVars: map[string]string{ 32 | "SERVICE_NAME": "test-service", 33 | "SERVICE_VERSION": "1.0.0", 34 | "TELEMETRY_ENABLED": "true", 35 | }, 36 | want: gotel.Config{ 37 | ServiceName: "test-service", 38 | ServiceVersion: "1.0.0", 39 | Enabled: true, 40 | }, 41 | wantErr: false, 42 | }, 43 | } 44 | 45 | for _, tt := range tests { 46 | t.Run(tt.name, func(t *testing.T) { 47 | // Clear environment before each test 48 | os.Clearenv() 49 | 50 | // Set environment variables for test 51 | for k, v := range tt.envVars { 52 | os.Setenv(k, v) 53 | } 54 | 55 | // Run test 56 | got, err := gotel.NewConfigFromEnv() 57 | if tt.wantErr { 58 | assert.Error(t, err) 59 | 60 | return 61 | } 62 | 63 | require.NoError(t, err) 64 | assert.Equal(t, tt.want, got) 65 | }) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /noop_test.go: -------------------------------------------------------------------------------- 1 | package gotel_test 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | 7 | "github.com/gin-gonic/gin" 8 | "github.com/lucavallin/gotel" 9 | "github.com/stretchr/testify/assert" 10 | "github.com/stretchr/testify/require" 11 | ) 12 | 13 | func TestNewNoopTelemetry(t *testing.T) { 14 | cfg := gotel.Config{ 15 | ServiceName: "test-service", 16 | ServiceVersion: "1.0.0", 17 | Enabled: false, 18 | } 19 | 20 | noop, err := gotel.NewNoopTelemetry(cfg) 21 | require.NoError(t, err) 22 | assert.NotNil(t, noop) 23 | 24 | // Test service name 25 | assert.Equal(t, cfg.ServiceName, noop.GetServiceName()) 26 | 27 | // Test logging (should not panic) 28 | assert.NotPanics(t, func() { 29 | noop.LogInfo("test") 30 | noop.LogErrorln("test") 31 | }) 32 | 33 | // Test metrics 34 | histogram, err := noop.MeterInt64Histogram(gotel.Metric{}) 35 | require.NoError(t, err) 36 | assert.Nil(t, histogram) 37 | 38 | counter, err := noop.MeterInt64UpDownCounter(gotel.Metric{}) 39 | require.NoError(t, err) 40 | assert.Nil(t, counter) 41 | 42 | // Test tracing 43 | ctx := context.Background() 44 | newCtx, span := noop.TraceStart(ctx, "test") 45 | assert.Equal(t, ctx, newCtx) 46 | assert.NotNil(t, span) 47 | 48 | // Test middleware functions 49 | assert.NotNil(t, noop.LogRequest()) 50 | assert.NotNil(t, noop.MeterRequestDuration()) 51 | assert.NotNil(t, noop.MeterRequestsInFlight()) 52 | 53 | // Test middleware execution 54 | c, _ := gin.CreateTestContext(nil) 55 | noop.LogRequest()(c) 56 | noop.MeterRequestDuration()(c) 57 | noop.MeterRequestsInFlight()(c) 58 | } 59 | -------------------------------------------------------------------------------- /mocks/embedded/Span.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockSpan is an autogenerated mock type for the Span type 8 | type MockSpan struct { 9 | mock.Mock 10 | } 11 | 12 | type MockSpan_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockSpan) EXPECT() *MockSpan_Expecter { 17 | return &MockSpan_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // span provides a mock function with no fields 21 | func (_m *MockSpan) span() { 22 | _m.Called() 23 | } 24 | 25 | // MockSpan_span_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'span' 26 | type MockSpan_span_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // span is a helper method to define mock.On call 31 | func (_e *MockSpan_Expecter) span() *MockSpan_span_Call { 32 | return &MockSpan_span_Call{Call: _e.mock.On("span")} 33 | } 34 | 35 | func (_c *MockSpan_span_Call) Run(run func()) *MockSpan_span_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockSpan_span_Call) Return() *MockSpan_span_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockSpan_span_Call) RunAndReturn(run func()) *MockSpan_span_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockSpan creates a new instance of MockSpan. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockSpan(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockSpan { 58 | mock := &MockSpan{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Meter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockMeter is an autogenerated mock type for the Meter type 8 | type MockMeter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockMeter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockMeter) EXPECT() *MockMeter_Expecter { 17 | return &MockMeter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // meter provides a mock function with no fields 21 | func (_m *MockMeter) meter() { 22 | _m.Called() 23 | } 24 | 25 | // MockMeter_meter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'meter' 26 | type MockMeter_meter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // meter is a helper method to define mock.On call 31 | func (_e *MockMeter_Expecter) meter() *MockMeter_meter_Call { 32 | return &MockMeter_meter_Call{Call: _e.mock.On("meter")} 33 | } 34 | 35 | func (_c *MockMeter_meter_Call) Run(run func()) *MockMeter_meter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockMeter_meter_Call) Return() *MockMeter_meter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockMeter_meter_Call) RunAndReturn(run func()) *MockMeter_meter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockMeter creates a new instance of MockMeter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockMeter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockMeter { 58 | mock := &MockMeter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Tracer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockTracer is an autogenerated mock type for the Tracer type 8 | type MockTracer struct { 9 | mock.Mock 10 | } 11 | 12 | type MockTracer_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockTracer) EXPECT() *MockTracer_Expecter { 17 | return &MockTracer_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // tracer provides a mock function with no fields 21 | func (_m *MockTracer) tracer() { 22 | _m.Called() 23 | } 24 | 25 | // MockTracer_tracer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'tracer' 26 | type MockTracer_tracer_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // tracer is a helper method to define mock.On call 31 | func (_e *MockTracer_Expecter) tracer() *MockTracer_tracer_Call { 32 | return &MockTracer_tracer_Call{Call: _e.mock.On("tracer")} 33 | } 34 | 35 | func (_c *MockTracer_tracer_Call) Run(run func()) *MockTracer_tracer_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockTracer_tracer_Call) Return() *MockTracer_tracer_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockTracer_tracer_Call) RunAndReturn(run func()) *MockTracer_tracer_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockTracer creates a new instance of MockTracer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockTracer(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockTracer { 58 | mock := &MockTracer{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Observer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockObserver is an autogenerated mock type for the Observer type 8 | type MockObserver struct { 9 | mock.Mock 10 | } 11 | 12 | type MockObserver_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockObserver) EXPECT() *MockObserver_Expecter { 17 | return &MockObserver_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // observer provides a mock function with no fields 21 | func (_m *MockObserver) observer() { 22 | _m.Called() 23 | } 24 | 25 | // MockObserver_observer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'observer' 26 | type MockObserver_observer_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // observer is a helper method to define mock.On call 31 | func (_e *MockObserver_Expecter) observer() *MockObserver_observer_Call { 32 | return &MockObserver_observer_Call{Call: _e.mock.On("observer")} 33 | } 34 | 35 | func (_c *MockObserver_observer_Call) Run(run func()) *MockObserver_observer_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockObserver_observer_Call) Return() *MockObserver_observer_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockObserver_observer_Call) RunAndReturn(run func()) *MockObserver_observer_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockObserver creates a new instance of MockObserver. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockObserver(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockObserver { 58 | mock := &MockObserver{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64Gauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64Gauge is an autogenerated mock type for the Int64Gauge type 8 | type MockInt64Gauge struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64Gauge_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64Gauge) EXPECT() *MockInt64Gauge_Expecter { 17 | return &MockInt64Gauge_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64Gauge provides a mock function with no fields 21 | func (_m *MockInt64Gauge) int64Gauge() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64Gauge_int64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Gauge' 26 | type MockInt64Gauge_int64Gauge_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64Gauge is a helper method to define mock.On call 31 | func (_e *MockInt64Gauge_Expecter) int64Gauge() *MockInt64Gauge_int64Gauge_Call { 32 | return &MockInt64Gauge_int64Gauge_Call{Call: _e.mock.On("int64Gauge")} 33 | } 34 | 35 | func (_c *MockInt64Gauge_int64Gauge_Call) Run(run func()) *MockInt64Gauge_int64Gauge_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64Gauge_int64Gauge_Call) Return() *MockInt64Gauge_int64Gauge_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64Gauge_int64Gauge_Call) RunAndReturn(run func()) *MockInt64Gauge_int64Gauge_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64Gauge creates a new instance of MockInt64Gauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64Gauge(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64Gauge { 58 | mock := &MockInt64Gauge{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/metric/Observable.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockObservable is an autogenerated mock type for the Observable type 8 | type MockObservable struct { 9 | mock.Mock 10 | } 11 | 12 | type MockObservable_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockObservable) EXPECT() *MockObservable_Expecter { 17 | return &MockObservable_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // observable provides a mock function with no fields 21 | func (_m *MockObservable) observable() { 22 | _m.Called() 23 | } 24 | 25 | // MockObservable_observable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'observable' 26 | type MockObservable_observable_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // observable is a helper method to define mock.On call 31 | func (_e *MockObservable_Expecter) observable() *MockObservable_observable_Call { 32 | return &MockObservable_observable_Call{Call: _e.mock.On("observable")} 33 | } 34 | 35 | func (_c *MockObservable_observable_Call) Run(run func()) *MockObservable_observable_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockObservable_observable_Call) Return() *MockObservable_observable_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockObservable_observable_Call) RunAndReturn(run func()) *MockObservable_observable_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockObservable creates a new instance of MockObservable. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockObservable(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockObservable { 58 | mock := &MockObservable{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Float64Gauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64Gauge is an autogenerated mock type for the Float64Gauge type 8 | type MockFloat64Gauge struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64Gauge_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64Gauge) EXPECT() *MockFloat64Gauge_Expecter { 17 | return &MockFloat64Gauge_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64Gauge provides a mock function with no fields 21 | func (_m *MockFloat64Gauge) float64Gauge() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64Gauge_float64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Gauge' 26 | type MockFloat64Gauge_float64Gauge_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64Gauge is a helper method to define mock.On call 31 | func (_e *MockFloat64Gauge_Expecter) float64Gauge() *MockFloat64Gauge_float64Gauge_Call { 32 | return &MockFloat64Gauge_float64Gauge_Call{Call: _e.mock.On("float64Gauge")} 33 | } 34 | 35 | func (_c *MockFloat64Gauge_float64Gauge_Call) Run(run func()) *MockFloat64Gauge_float64Gauge_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64Gauge_float64Gauge_Call) Return() *MockFloat64Gauge_float64Gauge_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64Gauge_float64Gauge_Call) RunAndReturn(run func()) *MockFloat64Gauge_float64Gauge_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64Gauge creates a new instance of MockFloat64Gauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64Gauge(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64Gauge { 58 | mock := &MockFloat64Gauge{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64Counter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64Counter is an autogenerated mock type for the Int64Counter type 8 | type MockInt64Counter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64Counter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64Counter) EXPECT() *MockInt64Counter_Expecter { 17 | return &MockInt64Counter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64Counter provides a mock function with no fields 21 | func (_m *MockInt64Counter) int64Counter() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64Counter_int64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Counter' 26 | type MockInt64Counter_int64Counter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64Counter is a helper method to define mock.On call 31 | func (_e *MockInt64Counter_Expecter) int64Counter() *MockInt64Counter_int64Counter_Call { 32 | return &MockInt64Counter_int64Counter_Call{Call: _e.mock.On("int64Counter")} 33 | } 34 | 35 | func (_c *MockInt64Counter_int64Counter_Call) Run(run func()) *MockInt64Counter_int64Counter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64Counter_int64Counter_Call) Return() *MockInt64Counter_int64Counter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64Counter_int64Counter_Call) RunAndReturn(run func()) *MockInt64Counter_int64Counter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64Counter creates a new instance of MockInt64Counter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64Counter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64Counter { 58 | mock := &MockInt64Counter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Registration.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockRegistration is an autogenerated mock type for the Registration type 8 | type MockRegistration struct { 9 | mock.Mock 10 | } 11 | 12 | type MockRegistration_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockRegistration) EXPECT() *MockRegistration_Expecter { 17 | return &MockRegistration_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // registration provides a mock function with no fields 21 | func (_m *MockRegistration) registration() { 22 | _m.Called() 23 | } 24 | 25 | // MockRegistration_registration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'registration' 26 | type MockRegistration_registration_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // registration is a helper method to define mock.On call 31 | func (_e *MockRegistration_Expecter) registration() *MockRegistration_registration_Call { 32 | return &MockRegistration_registration_Call{Call: _e.mock.On("registration")} 33 | } 34 | 35 | func (_c *MockRegistration_registration_Call) Run(run func()) *MockRegistration_registration_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockRegistration_registration_Call) Return() *MockRegistration_registration_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockRegistration_registration_Call) RunAndReturn(run func()) *MockRegistration_registration_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockRegistration creates a new instance of MockRegistration. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockRegistration(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockRegistration { 58 | mock := &MockRegistration{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64Observer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64Observer is an autogenerated mock type for the Int64Observer type 8 | type MockInt64Observer struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64Observer_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64Observer) EXPECT() *MockInt64Observer_Expecter { 17 | return &MockInt64Observer_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64Observer provides a mock function with no fields 21 | func (_m *MockInt64Observer) int64Observer() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64Observer_int64Observer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Observer' 26 | type MockInt64Observer_int64Observer_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64Observer is a helper method to define mock.On call 31 | func (_e *MockInt64Observer_Expecter) int64Observer() *MockInt64Observer_int64Observer_Call { 32 | return &MockInt64Observer_int64Observer_Call{Call: _e.mock.On("int64Observer")} 33 | } 34 | 35 | func (_c *MockInt64Observer_int64Observer_Call) Run(run func()) *MockInt64Observer_int64Observer_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64Observer_int64Observer_Call) Return() *MockInt64Observer_int64Observer_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64Observer_int64Observer_Call) RunAndReturn(run func()) *MockInt64Observer_int64Observer_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64Observer creates a new instance of MockInt64Observer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64Observer(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64Observer { 58 | mock := &MockInt64Observer{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/MeterProvider.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockMeterProvider is an autogenerated mock type for the MeterProvider type 8 | type MockMeterProvider struct { 9 | mock.Mock 10 | } 11 | 12 | type MockMeterProvider_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockMeterProvider) EXPECT() *MockMeterProvider_Expecter { 17 | return &MockMeterProvider_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // meterProvider provides a mock function with no fields 21 | func (_m *MockMeterProvider) meterProvider() { 22 | _m.Called() 23 | } 24 | 25 | // MockMeterProvider_meterProvider_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'meterProvider' 26 | type MockMeterProvider_meterProvider_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // meterProvider is a helper method to define mock.On call 31 | func (_e *MockMeterProvider_Expecter) meterProvider() *MockMeterProvider_meterProvider_Call { 32 | return &MockMeterProvider_meterProvider_Call{Call: _e.mock.On("meterProvider")} 33 | } 34 | 35 | func (_c *MockMeterProvider_meterProvider_Call) Run(run func()) *MockMeterProvider_meterProvider_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockMeterProvider_meterProvider_Call) Return() *MockMeterProvider_meterProvider_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockMeterProvider_meterProvider_Call) RunAndReturn(run func()) *MockMeterProvider_meterProvider_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockMeterProvider creates a new instance of MockMeterProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockMeterProvider(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockMeterProvider { 58 | mock := &MockMeterProvider{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /noop.go: -------------------------------------------------------------------------------- 1 | package gotel 2 | 3 | import ( 4 | "context" 5 | "os" 6 | 7 | "github.com/gin-gonic/gin" 8 | "go.opentelemetry.io/otel/metric" 9 | "go.opentelemetry.io/otel/trace" 10 | ) 11 | 12 | // NoopTelemetry is a no-op implementation of the TelemetryProvider interface. 13 | type NoopTelemetry struct { 14 | serviceName string 15 | } 16 | 17 | // NewNoopTelemetry creates a new NoopTelemetry instance. 18 | func NewNoopTelemetry(cfg Config) (*NoopTelemetry, error) { 19 | return &NoopTelemetry{serviceName: cfg.ServiceName}, nil 20 | } 21 | 22 | // GetServiceName returns the service name. 23 | func (t *NoopTelemetry) GetServiceName() string { return t.serviceName } 24 | 25 | // LogInfo logs nothing. 26 | func (t *NoopTelemetry) LogInfo(args ...interface{}) {} 27 | 28 | // LogErrorln logs nothing. 29 | func (t *NoopTelemetry) LogErrorln(args ...interface{}) {} 30 | 31 | // LogFatalln logs nothing, then exits. 32 | func (t *NoopTelemetry) LogFatalln(args ...interface{}) { 33 | os.Exit(1) 34 | } 35 | 36 | // LogRequest is a no-op middleware. 37 | func (t *NoopTelemetry) LogRequest() gin.HandlerFunc { 38 | return func(c *gin.Context) { c.Next() } 39 | } 40 | 41 | // MeterRequestDuration is a no-op middleware. 42 | func (t *NoopTelemetry) MeterRequestDuration() gin.HandlerFunc { 43 | return func(c *gin.Context) { c.Next() } 44 | } 45 | 46 | // MeterRequestsInFlight is a no-op middleware. 47 | func (t *NoopTelemetry) MeterRequestsInFlight() gin.HandlerFunc { 48 | return func(c *gin.Context) { c.Next() } 49 | } 50 | 51 | // TraceStart returns the context and span unchanged. 52 | func (t *NoopTelemetry) TraceStart(ctx context.Context, name string) (context.Context, trace.Span) { 53 | return ctx, trace.SpanFromContext(ctx) 54 | } 55 | 56 | // MeterInt64Histogram returns nil. 57 | func (t *NoopTelemetry) MeterInt64Histogram(metric Metric) (metric.Int64Histogram, error) { 58 | return nil, nil 59 | } 60 | 61 | // MeterInt64UpDownCounter returns nil. 62 | func (t *NoopTelemetry) MeterInt64UpDownCounter(metric Metric) (metric.Int64UpDownCounter, error) { 63 | return nil, nil 64 | } 65 | 66 | // Shutdown does nothing. 67 | func (t *NoopTelemetry) Shutdown(ctx context.Context) {} 68 | -------------------------------------------------------------------------------- /mocks/embedded/Float64Counter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64Counter is an autogenerated mock type for the Float64Counter type 8 | type MockFloat64Counter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64Counter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64Counter) EXPECT() *MockFloat64Counter_Expecter { 17 | return &MockFloat64Counter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64Counter provides a mock function with no fields 21 | func (_m *MockFloat64Counter) float64Counter() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64Counter_float64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Counter' 26 | type MockFloat64Counter_float64Counter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64Counter is a helper method to define mock.On call 31 | func (_e *MockFloat64Counter_Expecter) float64Counter() *MockFloat64Counter_float64Counter_Call { 32 | return &MockFloat64Counter_float64Counter_Call{Call: _e.mock.On("float64Counter")} 33 | } 34 | 35 | func (_c *MockFloat64Counter_float64Counter_Call) Run(run func()) *MockFloat64Counter_float64Counter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64Counter_float64Counter_Call) Return() *MockFloat64Counter_float64Counter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64Counter_float64Counter_Call) RunAndReturn(run func()) *MockFloat64Counter_float64Counter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64Counter creates a new instance of MockFloat64Counter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64Counter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64Counter { 58 | mock := &MockFloat64Counter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64Histogram.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64Histogram is an autogenerated mock type for the Int64Histogram type 8 | type MockInt64Histogram struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64Histogram_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64Histogram) EXPECT() *MockInt64Histogram_Expecter { 17 | return &MockInt64Histogram_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64Histogram provides a mock function with no fields 21 | func (_m *MockInt64Histogram) int64Histogram() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64Histogram_int64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Histogram' 26 | type MockInt64Histogram_int64Histogram_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64Histogram is a helper method to define mock.On call 31 | func (_e *MockInt64Histogram_Expecter) int64Histogram() *MockInt64Histogram_int64Histogram_Call { 32 | return &MockInt64Histogram_int64Histogram_Call{Call: _e.mock.On("int64Histogram")} 33 | } 34 | 35 | func (_c *MockInt64Histogram_int64Histogram_Call) Run(run func()) *MockInt64Histogram_int64Histogram_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64Histogram_int64Histogram_Call) Return() *MockInt64Histogram_int64Histogram_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64Histogram_int64Histogram_Call) RunAndReturn(run func()) *MockInt64Histogram_int64Histogram_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64Histogram creates a new instance of MockInt64Histogram. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64Histogram(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64Histogram { 58 | mock := &MockInt64Histogram{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/TracerProvider.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockTracerProvider is an autogenerated mock type for the TracerProvider type 8 | type MockTracerProvider struct { 9 | mock.Mock 10 | } 11 | 12 | type MockTracerProvider_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockTracerProvider) EXPECT() *MockTracerProvider_Expecter { 17 | return &MockTracerProvider_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // tracerProvider provides a mock function with no fields 21 | func (_m *MockTracerProvider) tracerProvider() { 22 | _m.Called() 23 | } 24 | 25 | // MockTracerProvider_tracerProvider_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'tracerProvider' 26 | type MockTracerProvider_tracerProvider_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // tracerProvider is a helper method to define mock.On call 31 | func (_e *MockTracerProvider_Expecter) tracerProvider() *MockTracerProvider_tracerProvider_Call { 32 | return &MockTracerProvider_tracerProvider_Call{Call: _e.mock.On("tracerProvider")} 33 | } 34 | 35 | func (_c *MockTracerProvider_tracerProvider_Call) Run(run func()) *MockTracerProvider_tracerProvider_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockTracerProvider_tracerProvider_Call) Return() *MockTracerProvider_tracerProvider_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockTracerProvider_tracerProvider_Call) RunAndReturn(run func()) *MockTracerProvider_tracerProvider_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockTracerProvider creates a new instance of MockTracerProvider. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockTracerProvider(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockTracerProvider { 58 | mock := &MockTracerProvider{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Float64Observer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64Observer is an autogenerated mock type for the Float64Observer type 8 | type MockFloat64Observer struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64Observer_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64Observer) EXPECT() *MockFloat64Observer_Expecter { 17 | return &MockFloat64Observer_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64Observer provides a mock function with no fields 21 | func (_m *MockFloat64Observer) float64Observer() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64Observer_float64Observer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Observer' 26 | type MockFloat64Observer_float64Observer_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64Observer is a helper method to define mock.On call 31 | func (_e *MockFloat64Observer_Expecter) float64Observer() *MockFloat64Observer_float64Observer_Call { 32 | return &MockFloat64Observer_float64Observer_Call{Call: _e.mock.On("float64Observer")} 33 | } 34 | 35 | func (_c *MockFloat64Observer_float64Observer_Call) Run(run func()) *MockFloat64Observer_float64Observer_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64Observer_float64Observer_Call) Return() *MockFloat64Observer_float64Observer_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64Observer_float64Observer_Call) RunAndReturn(run func()) *MockFloat64Observer_float64Observer_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64Observer creates a new instance of MockFloat64Observer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64Observer(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64Observer { 58 | mock := &MockFloat64Observer{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /middleware.go: -------------------------------------------------------------------------------- 1 | package gotel 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/gin-gonic/gin" 8 | 9 | "go.opentelemetry.io/otel/metric" 10 | "go.opentelemetry.io/otel/semconv/v1.20.0/httpconv" 11 | ) 12 | 13 | // LogRequest is a gin middleware that logs the request path. 14 | func (t *Telemetry) LogRequest() gin.HandlerFunc { 15 | return func(c *gin.Context) { 16 | t.LogInfo("request to ", c.Request.URL.Path) 17 | c.Next() 18 | t.LogInfo("end of request to ", c.Request.URL.Path) 19 | } 20 | } 21 | 22 | // MeterRequestDuration is a gin middleware that captures the duration of the request. 23 | func (t *Telemetry) MeterRequestDuration() gin.HandlerFunc { 24 | // init metric, here we are using histogram for capturing request duration 25 | histogram, err := t.MeterInt64Histogram(MetricRequestDurationMillis) 26 | if err != nil { 27 | t.LogFatalln(fmt.Errorf("failed to create histogram: %w", err)) 28 | } 29 | 30 | return func(c *gin.Context) { 31 | // capture the start time of the request 32 | startTime := time.Now() 33 | 34 | // execute next http handler 35 | c.Next() 36 | 37 | // record the request duration 38 | duration := time.Since(startTime) 39 | histogram.Record( 40 | c.Request.Context(), 41 | duration.Milliseconds(), 42 | metric.WithAttributes( 43 | httpconv.ServerRequest(t.GetServiceName(), c.Request)..., 44 | ), 45 | ) 46 | } 47 | } 48 | 49 | // MeterRequestsInFlight is a gin middleware that captures the number of requests in flight. 50 | func (t *Telemetry) MeterRequestsInFlight() gin.HandlerFunc { 51 | // init metric, here we are using counter for capturing request in flight 52 | counter, err := t.MeterInt64UpDownCounter(MetricRequestsInFlight) 53 | if err != nil { 54 | t.LogFatalln(fmt.Errorf("failed to create counter: %w", err)) 55 | } 56 | 57 | return func(c *gin.Context) { 58 | // define metric attributes 59 | attrs := metric.WithAttributes(httpconv.ServerRequest(t.GetServiceName(), c.Request)...) 60 | 61 | // increase the number of requests in flight 62 | counter.Add(c.Request.Context(), 1, attrs) 63 | 64 | // execute next http handler 65 | c.Next() 66 | 67 | // decrease the number of requests in flight 68 | counter.Add(c.Request.Context(), -1, attrs) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /mocks/embedded/Float64Histogram.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64Histogram is an autogenerated mock type for the Float64Histogram type 8 | type MockFloat64Histogram struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64Histogram_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64Histogram) EXPECT() *MockFloat64Histogram_Expecter { 17 | return &MockFloat64Histogram_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64Histogram provides a mock function with no fields 21 | func (_m *MockFloat64Histogram) float64Histogram() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64Histogram_float64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Histogram' 26 | type MockFloat64Histogram_float64Histogram_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64Histogram is a helper method to define mock.On call 31 | func (_e *MockFloat64Histogram_Expecter) float64Histogram() *MockFloat64Histogram_float64Histogram_Call { 32 | return &MockFloat64Histogram_float64Histogram_Call{Call: _e.mock.On("float64Histogram")} 33 | } 34 | 35 | func (_c *MockFloat64Histogram_float64Histogram_Call) Run(run func()) *MockFloat64Histogram_float64Histogram_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64Histogram_float64Histogram_Call) Return() *MockFloat64Histogram_float64Histogram_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64Histogram_float64Histogram_Call) RunAndReturn(run func()) *MockFloat64Histogram_float64Histogram_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64Histogram creates a new instance of MockFloat64Histogram. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64Histogram(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64Histogram { 58 | mock := &MockFloat64Histogram{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64UpDownCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64UpDownCounter is an autogenerated mock type for the Int64UpDownCounter type 8 | type MockInt64UpDownCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64UpDownCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64UpDownCounter) EXPECT() *MockInt64UpDownCounter_Expecter { 17 | return &MockInt64UpDownCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64UpDownCounter provides a mock function with no fields 21 | func (_m *MockInt64UpDownCounter) int64UpDownCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64UpDownCounter_int64UpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64UpDownCounter' 26 | type MockInt64UpDownCounter_int64UpDownCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64UpDownCounter is a helper method to define mock.On call 31 | func (_e *MockInt64UpDownCounter_Expecter) int64UpDownCounter() *MockInt64UpDownCounter_int64UpDownCounter_Call { 32 | return &MockInt64UpDownCounter_int64UpDownCounter_Call{Call: _e.mock.On("int64UpDownCounter")} 33 | } 34 | 35 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) Run(run func()) *MockInt64UpDownCounter_int64UpDownCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) Return() *MockInt64UpDownCounter_int64UpDownCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) RunAndReturn(run func()) *MockInt64UpDownCounter_int64UpDownCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64UpDownCounter creates a new instance of MockInt64UpDownCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64UpDownCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64UpDownCounter { 58 | mock := &MockInt64UpDownCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Float64UpDownCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64UpDownCounter is an autogenerated mock type for the Float64UpDownCounter type 8 | type MockFloat64UpDownCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64UpDownCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64UpDownCounter) EXPECT() *MockFloat64UpDownCounter_Expecter { 17 | return &MockFloat64UpDownCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64UpDownCounter provides a mock function with no fields 21 | func (_m *MockFloat64UpDownCounter) float64UpDownCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64UpDownCounter_float64UpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64UpDownCounter' 26 | type MockFloat64UpDownCounter_float64UpDownCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64UpDownCounter is a helper method to define mock.On call 31 | func (_e *MockFloat64UpDownCounter_Expecter) float64UpDownCounter() *MockFloat64UpDownCounter_float64UpDownCounter_Call { 32 | return &MockFloat64UpDownCounter_float64UpDownCounter_Call{Call: _e.mock.On("float64UpDownCounter")} 33 | } 34 | 35 | func (_c *MockFloat64UpDownCounter_float64UpDownCounter_Call) Run(run func()) *MockFloat64UpDownCounter_float64UpDownCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64UpDownCounter_float64UpDownCounter_Call) Return() *MockFloat64UpDownCounter_float64UpDownCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64UpDownCounter_float64UpDownCounter_Call) RunAndReturn(run func()) *MockFloat64UpDownCounter_float64UpDownCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64UpDownCounter creates a new instance of MockFloat64UpDownCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64UpDownCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64UpDownCounter { 58 | mock := &MockFloat64UpDownCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64ObservableGauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64ObservableGauge is an autogenerated mock type for the Int64ObservableGauge type 8 | type MockInt64ObservableGauge struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64ObservableGauge_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64ObservableGauge) EXPECT() *MockInt64ObservableGauge_Expecter { 17 | return &MockInt64ObservableGauge_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64ObservableGauge provides a mock function with no fields 21 | func (_m *MockInt64ObservableGauge) int64ObservableGauge() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64ObservableGauge_int64ObservableGauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64ObservableGauge' 26 | type MockInt64ObservableGauge_int64ObservableGauge_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64ObservableGauge is a helper method to define mock.On call 31 | func (_e *MockInt64ObservableGauge_Expecter) int64ObservableGauge() *MockInt64ObservableGauge_int64ObservableGauge_Call { 32 | return &MockInt64ObservableGauge_int64ObservableGauge_Call{Call: _e.mock.On("int64ObservableGauge")} 33 | } 34 | 35 | func (_c *MockInt64ObservableGauge_int64ObservableGauge_Call) Run(run func()) *MockInt64ObservableGauge_int64ObservableGauge_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64ObservableGauge_int64ObservableGauge_Call) Return() *MockInt64ObservableGauge_int64ObservableGauge_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64ObservableGauge_int64ObservableGauge_Call) RunAndReturn(run func()) *MockInt64ObservableGauge_int64ObservableGauge_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64ObservableGauge creates a new instance of MockInt64ObservableGauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64ObservableGauge(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64ObservableGauge { 58 | mock := &MockInt64ObservableGauge{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Float64ObservableGauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64ObservableGauge is an autogenerated mock type for the Float64ObservableGauge type 8 | type MockFloat64ObservableGauge struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64ObservableGauge_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64ObservableGauge) EXPECT() *MockFloat64ObservableGauge_Expecter { 17 | return &MockFloat64ObservableGauge_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64ObservableGauge provides a mock function with no fields 21 | func (_m *MockFloat64ObservableGauge) float64ObservableGauge() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64ObservableGauge_float64ObservableGauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64ObservableGauge' 26 | type MockFloat64ObservableGauge_float64ObservableGauge_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64ObservableGauge is a helper method to define mock.On call 31 | func (_e *MockFloat64ObservableGauge_Expecter) float64ObservableGauge() *MockFloat64ObservableGauge_float64ObservableGauge_Call { 32 | return &MockFloat64ObservableGauge_float64ObservableGauge_Call{Call: _e.mock.On("float64ObservableGauge")} 33 | } 34 | 35 | func (_c *MockFloat64ObservableGauge_float64ObservableGauge_Call) Run(run func()) *MockFloat64ObservableGauge_float64ObservableGauge_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64ObservableGauge_float64ObservableGauge_Call) Return() *MockFloat64ObservableGauge_float64ObservableGauge_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64ObservableGauge_float64ObservableGauge_Call) RunAndReturn(run func()) *MockFloat64ObservableGauge_float64ObservableGauge_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64ObservableGauge creates a new instance of MockFloat64ObservableGauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64ObservableGauge(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64ObservableGauge { 58 | mock := &MockFloat64ObservableGauge{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/embedded/Int64ObservableCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64ObservableCounter is an autogenerated mock type for the Int64ObservableCounter type 8 | type MockInt64ObservableCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64ObservableCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64ObservableCounter) EXPECT() *MockInt64ObservableCounter_Expecter { 17 | return &MockInt64ObservableCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64ObservableCounter provides a mock function with no fields 21 | func (_m *MockInt64ObservableCounter) int64ObservableCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64ObservableCounter_int64ObservableCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64ObservableCounter' 26 | type MockInt64ObservableCounter_int64ObservableCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64ObservableCounter is a helper method to define mock.On call 31 | func (_e *MockInt64ObservableCounter_Expecter) int64ObservableCounter() *MockInt64ObservableCounter_int64ObservableCounter_Call { 32 | return &MockInt64ObservableCounter_int64ObservableCounter_Call{Call: _e.mock.On("int64ObservableCounter")} 33 | } 34 | 35 | func (_c *MockInt64ObservableCounter_int64ObservableCounter_Call) Run(run func()) *MockInt64ObservableCounter_int64ObservableCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64ObservableCounter_int64ObservableCounter_Call) Return() *MockInt64ObservableCounter_int64ObservableCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64ObservableCounter_int64ObservableCounter_Call) RunAndReturn(run func()) *MockInt64ObservableCounter_int64ObservableCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64ObservableCounter creates a new instance of MockInt64ObservableCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64ObservableCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64ObservableCounter { 58 | mock := &MockInt64ObservableCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/metric/AddOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockAddOption is an autogenerated mock type for the AddOption type 11 | type MockAddOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockAddOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockAddOption) EXPECT() *MockAddOption_Expecter { 20 | return &MockAddOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyAdd provides a mock function with given fields: _a0 24 | func (_m *MockAddOption) applyAdd(_a0 metric.AddConfig) metric.AddConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyAdd") 29 | } 30 | 31 | var r0 metric.AddConfig 32 | if rf, ok := ret.Get(0).(func(metric.AddConfig) metric.AddConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.AddConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockAddOption_applyAdd_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyAdd' 42 | type MockAddOption_applyAdd_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyAdd is a helper method to define mock.On call 47 | // - _a0 metric.AddConfig 48 | func (_e *MockAddOption_Expecter) applyAdd(_a0 interface{}) *MockAddOption_applyAdd_Call { 49 | return &MockAddOption_applyAdd_Call{Call: _e.mock.On("applyAdd", _a0)} 50 | } 51 | 52 | func (_c *MockAddOption_applyAdd_Call) Run(run func(_a0 metric.AddConfig)) *MockAddOption_applyAdd_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.AddConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockAddOption_applyAdd_Call) Return(_a0 metric.AddConfig) *MockAddOption_applyAdd_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockAddOption_applyAdd_Call) RunAndReturn(run func(metric.AddConfig) metric.AddConfig) *MockAddOption_applyAdd_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockAddOption creates a new instance of MockAddOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockAddOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockAddOption { 75 | mock := &MockAddOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/embedded/Float64ObservableCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64ObservableCounter is an autogenerated mock type for the Float64ObservableCounter type 8 | type MockFloat64ObservableCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64ObservableCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64ObservableCounter) EXPECT() *MockFloat64ObservableCounter_Expecter { 17 | return &MockFloat64ObservableCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64ObservableCounter provides a mock function with no fields 21 | func (_m *MockFloat64ObservableCounter) float64ObservableCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64ObservableCounter_float64ObservableCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64ObservableCounter' 26 | type MockFloat64ObservableCounter_float64ObservableCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64ObservableCounter is a helper method to define mock.On call 31 | func (_e *MockFloat64ObservableCounter_Expecter) float64ObservableCounter() *MockFloat64ObservableCounter_float64ObservableCounter_Call { 32 | return &MockFloat64ObservableCounter_float64ObservableCounter_Call{Call: _e.mock.On("float64ObservableCounter")} 33 | } 34 | 35 | func (_c *MockFloat64ObservableCounter_float64ObservableCounter_Call) Run(run func()) *MockFloat64ObservableCounter_float64ObservableCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64ObservableCounter_float64ObservableCounter_Call) Return() *MockFloat64ObservableCounter_float64ObservableCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64ObservableCounter_float64ObservableCounter_Call) RunAndReturn(run func()) *MockFloat64ObservableCounter_float64ObservableCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64ObservableCounter creates a new instance of MockFloat64ObservableCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64ObservableCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64ObservableCounter { 58 | mock := &MockFloat64ObservableCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /providers.go: -------------------------------------------------------------------------------- 1 | package gotel 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "os" 7 | 8 | "go.opentelemetry.io/otel" 9 | "go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc" 10 | "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" 11 | "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" 12 | "go.opentelemetry.io/otel/sdk/log" 13 | "go.opentelemetry.io/otel/sdk/metric" 14 | "go.opentelemetry.io/otel/sdk/resource" 15 | "go.opentelemetry.io/otel/sdk/trace" 16 | semconv "go.opentelemetry.io/otel/semconv/v1.17.0" 17 | ) 18 | 19 | // newLoggerProvider creates a new logger provider with the OTLP gRPC exporter. 20 | func newLoggerProvider(ctx context.Context, res *resource.Resource) (*log.LoggerProvider, error) { 21 | exporter, err := otlploggrpc.New(ctx) 22 | if err != nil { 23 | return nil, fmt.Errorf("failed to create OTLP log exporter: %w", err) 24 | } 25 | 26 | processor := log.NewBatchProcessor(exporter) 27 | lp := log.NewLoggerProvider( 28 | log.WithProcessor(processor), 29 | log.WithResource(res), 30 | ) 31 | 32 | return lp, nil 33 | } 34 | 35 | // newMeterProvider creates a new meter provider with the OTLP gRPC exporter. 36 | func newMeterProvider(ctx context.Context, res *resource.Resource) (*metric.MeterProvider, error) { 37 | exporter, err := otlpmetricgrpc.New(ctx) 38 | if err != nil { 39 | return nil, fmt.Errorf("failed to create OTLP metric exporter: %w", err) 40 | } 41 | 42 | mp := metric.NewMeterProvider( 43 | metric.WithReader(metric.NewPeriodicReader(exporter)), 44 | metric.WithResource(res), 45 | ) 46 | otel.SetMeterProvider(mp) 47 | 48 | return mp, nil 49 | } 50 | 51 | // newTracerProvider creates a new tracer provider with the OTLP gRPC exporter. 52 | func newTracerProvider(ctx context.Context, res *resource.Resource) (*trace.TracerProvider, error) { 53 | exporter, err := otlptracegrpc.New(ctx) 54 | if err != nil { 55 | return nil, fmt.Errorf("failed to create OTLP trace exporter: %w", err) 56 | } 57 | 58 | // Create Resource 59 | tp := trace.NewTracerProvider( 60 | trace.WithBatcher(exporter), 61 | trace.WithResource(res), 62 | ) 63 | otel.SetTracerProvider(tp) 64 | 65 | return tp, nil 66 | } 67 | 68 | // newResource creates a new OTEL resource with the service name and version. 69 | func newResource(serviceName string, serviceVersion string) *resource.Resource { 70 | hostName, _ := os.Hostname() 71 | 72 | return resource.NewWithAttributes( 73 | semconv.SchemaURL, 74 | semconv.ServiceName(serviceName), 75 | semconv.ServiceVersion(serviceVersion), 76 | semconv.HostName(hostName), 77 | ) 78 | } 79 | -------------------------------------------------------------------------------- /mocks/trace/TracerOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockTracerOption is an autogenerated mock type for the TracerOption type 11 | type MockTracerOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockTracerOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockTracerOption) EXPECT() *MockTracerOption_Expecter { 20 | return &MockTracerOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // apply provides a mock function with given fields: _a0 24 | func (_m *MockTracerOption) apply(_a0 trace.TracerConfig) trace.TracerConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for apply") 29 | } 30 | 31 | var r0 trace.TracerConfig 32 | if rf, ok := ret.Get(0).(func(trace.TracerConfig) trace.TracerConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.TracerConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockTracerOption_apply_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'apply' 42 | type MockTracerOption_apply_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // apply is a helper method to define mock.On call 47 | // - _a0 trace.TracerConfig 48 | func (_e *MockTracerOption_Expecter) apply(_a0 interface{}) *MockTracerOption_apply_Call { 49 | return &MockTracerOption_apply_Call{Call: _e.mock.On("apply", _a0)} 50 | } 51 | 52 | func (_c *MockTracerOption_apply_Call) Run(run func(_a0 trace.TracerConfig)) *MockTracerOption_apply_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.TracerConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockTracerOption_apply_Call) Return(_a0 trace.TracerConfig) *MockTracerOption_apply_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockTracerOption_apply_Call) RunAndReturn(run func(trace.TracerConfig) trace.TracerConfig) *MockTracerOption_apply_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockTracerOption creates a new instance of MockTracerOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockTracerOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockTracerOption { 75 | mock := &MockTracerOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Callback.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockCallback is an autogenerated mock type for the Callback type 13 | type MockCallback struct { 14 | mock.Mock 15 | } 16 | 17 | type MockCallback_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockCallback) EXPECT() *MockCallback_Expecter { 22 | return &MockCallback_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Execute provides a mock function with given fields: _a0, _a1 26 | func (_m *MockCallback) Execute(_a0 context.Context, _a1 metric.Observer) error { 27 | ret := _m.Called(_a0, _a1) 28 | 29 | if len(ret) == 0 { 30 | panic("no return value specified for Execute") 31 | } 32 | 33 | var r0 error 34 | if rf, ok := ret.Get(0).(func(context.Context, metric.Observer) error); ok { 35 | r0 = rf(_a0, _a1) 36 | } else { 37 | r0 = ret.Error(0) 38 | } 39 | 40 | return r0 41 | } 42 | 43 | // MockCallback_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 44 | type MockCallback_Execute_Call struct { 45 | *mock.Call 46 | } 47 | 48 | // Execute is a helper method to define mock.On call 49 | // - _a0 context.Context 50 | // - _a1 metric.Observer 51 | func (_e *MockCallback_Expecter) Execute(_a0 interface{}, _a1 interface{}) *MockCallback_Execute_Call { 52 | return &MockCallback_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} 53 | } 54 | 55 | func (_c *MockCallback_Execute_Call) Run(run func(_a0 context.Context, _a1 metric.Observer)) *MockCallback_Execute_Call { 56 | _c.Call.Run(func(args mock.Arguments) { 57 | run(args[0].(context.Context), args[1].(metric.Observer)) 58 | }) 59 | return _c 60 | } 61 | 62 | func (_c *MockCallback_Execute_Call) Return(_a0 error) *MockCallback_Execute_Call { 63 | _c.Call.Return(_a0) 64 | return _c 65 | } 66 | 67 | func (_c *MockCallback_Execute_Call) RunAndReturn(run func(context.Context, metric.Observer) error) *MockCallback_Execute_Call { 68 | _c.Call.Return(run) 69 | return _c 70 | } 71 | 72 | // NewMockCallback creates a new instance of MockCallback. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 73 | // The first argument is typically a *testing.T value. 74 | func NewMockCallback(t interface { 75 | mock.TestingT 76 | Cleanup(func()) 77 | }) *MockCallback { 78 | mock := &MockCallback{} 79 | mock.Mock.Test(t) 80 | 81 | t.Cleanup(func() { mock.AssertExpectations(t) }) 82 | 83 | return mock 84 | } 85 | -------------------------------------------------------------------------------- /mocks/trace/EventOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockEventOption is an autogenerated mock type for the EventOption type 11 | type MockEventOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockEventOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockEventOption) EXPECT() *MockEventOption_Expecter { 20 | return &MockEventOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyEvent provides a mock function with given fields: _a0 24 | func (_m *MockEventOption) applyEvent(_a0 trace.EventConfig) trace.EventConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyEvent") 29 | } 30 | 31 | var r0 trace.EventConfig 32 | if rf, ok := ret.Get(0).(func(trace.EventConfig) trace.EventConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.EventConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockEventOption_applyEvent_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyEvent' 42 | type MockEventOption_applyEvent_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyEvent is a helper method to define mock.On call 47 | // - _a0 trace.EventConfig 48 | func (_e *MockEventOption_Expecter) applyEvent(_a0 interface{}) *MockEventOption_applyEvent_Call { 49 | return &MockEventOption_applyEvent_Call{Call: _e.mock.On("applyEvent", _a0)} 50 | } 51 | 52 | func (_c *MockEventOption_applyEvent_Call) Run(run func(_a0 trace.EventConfig)) *MockEventOption_applyEvent_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.EventConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockEventOption_applyEvent_Call) Return(_a0 trace.EventConfig) *MockEventOption_applyEvent_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockEventOption_applyEvent_Call) RunAndReturn(run func(trace.EventConfig) trace.EventConfig) *MockEventOption_applyEvent_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockEventOption creates a new instance of MockEventOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockEventOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockEventOption { 75 | mock := &MockEventOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/trace/spanOptionFunc.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockspanOptionFunc is an autogenerated mock type for the spanOptionFunc type 11 | type MockspanOptionFunc struct { 12 | mock.Mock 13 | } 14 | 15 | type MockspanOptionFunc_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockspanOptionFunc) EXPECT() *MockspanOptionFunc_Expecter { 20 | return &MockspanOptionFunc_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // Execute provides a mock function with given fields: _a0 24 | func (_m *MockspanOptionFunc) Execute(_a0 trace.SpanConfig) trace.SpanConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for Execute") 29 | } 30 | 31 | var r0 trace.SpanConfig 32 | if rf, ok := ret.Get(0).(func(trace.SpanConfig) trace.SpanConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.SpanConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockspanOptionFunc_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 42 | type MockspanOptionFunc_Execute_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // Execute is a helper method to define mock.On call 47 | // - _a0 trace.SpanConfig 48 | func (_e *MockspanOptionFunc_Expecter) Execute(_a0 interface{}) *MockspanOptionFunc_Execute_Call { 49 | return &MockspanOptionFunc_Execute_Call{Call: _e.mock.On("Execute", _a0)} 50 | } 51 | 52 | func (_c *MockspanOptionFunc_Execute_Call) Run(run func(_a0 trace.SpanConfig)) *MockspanOptionFunc_Execute_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.SpanConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockspanOptionFunc_Execute_Call) Return(_a0 trace.SpanConfig) *MockspanOptionFunc_Execute_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockspanOptionFunc_Execute_Call) RunAndReturn(run func(trace.SpanConfig) trace.SpanConfig) *MockspanOptionFunc_Execute_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockspanOptionFunc creates a new instance of MockspanOptionFunc. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockspanOptionFunc(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockspanOptionFunc { 75 | mock := &MockspanOptionFunc{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/MeterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockMeterOption is an autogenerated mock type for the MeterOption type 11 | type MockMeterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockMeterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockMeterOption) EXPECT() *MockMeterOption_Expecter { 20 | return &MockMeterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyMeter provides a mock function with given fields: _a0 24 | func (_m *MockMeterOption) applyMeter(_a0 metric.MeterConfig) metric.MeterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyMeter") 29 | } 30 | 31 | var r0 metric.MeterConfig 32 | if rf, ok := ret.Get(0).(func(metric.MeterConfig) metric.MeterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.MeterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockMeterOption_applyMeter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyMeter' 42 | type MockMeterOption_applyMeter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyMeter is a helper method to define mock.On call 47 | // - _a0 metric.MeterConfig 48 | func (_e *MockMeterOption_Expecter) applyMeter(_a0 interface{}) *MockMeterOption_applyMeter_Call { 49 | return &MockMeterOption_applyMeter_Call{Call: _e.mock.On("applyMeter", _a0)} 50 | } 51 | 52 | func (_c *MockMeterOption_applyMeter_Call) Run(run func(_a0 metric.MeterConfig)) *MockMeterOption_applyMeter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.MeterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockMeterOption_applyMeter_Call) Return(_a0 metric.MeterConfig) *MockMeterOption_applyMeter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockMeterOption_applyMeter_Call) RunAndReturn(run func(metric.MeterConfig) metric.MeterConfig) *MockMeterOption_applyMeter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockMeterOption creates a new instance of MockMeterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockMeterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockMeterOption { 75 | mock := &MockMeterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gotel 2 | 3 | `gotel` is a Go library for handy observability. It is a wrapper around the OpenTelemetry Go library that provides a simplified API for instrumenting your Go applications. 4 | 5 | `gotel` offers the following features: 6 | 7 | - A simplified API for instrumenting your Go applications: log messages, metrics, and traces. 8 | - OpenTelemetry exporters via OTLP gRPC 9 | - A configuration struct that can be loaded from environment variables. 10 | - A no-op telemetry provider that can be used as a fallback when the exporter fails. 11 | 12 | ## Installation 13 | 14 | To install `gotel`, use `go get`: 15 | 16 | ```sh 17 | go get github.com/lucavallin/gotel 18 | ``` 19 | 20 | ## Usage 21 | 22 | To use `gotel`, you need to create an instance `gotel.Telemetry` and use it to instrument your application. Here is an example: 23 | 24 | ```go 25 | package main 26 | 27 | import ( 28 | "context" 29 | "fmt" 30 | "os" 31 | 32 | "github.com/lucavallin/gotel" 33 | ) 34 | 35 | func main() { 36 | ctx := context.Background() 37 | 38 | telemConfig, err := gotel.NewConfigFromEnv() 39 | if err != nil { 40 | fmt.Println("failed to load telemetry config") 41 | os.Exit(1) 42 | } 43 | 44 | // Initialize telemetry. If the exporter fails, fallback to nop. 45 | var telem gotel.TelemetryProvider 46 | telem, err = gotel.NewTelemetry(ctx, telemConfig) 47 | if err != nil { 48 | fmt.Println("failed to create telemetry, falling back to no-op telemetry") 49 | telem, _ = gotel.NewNoopTelemetry(telemConfig) 50 | } 51 | defer telem.Shutdown(ctx) 52 | 53 | telem.LogInfo("telemetry initialized") 54 | } 55 | ``` 56 | 57 | `gotel` also provides middleware for `gin`, which can be used to instrument your web applications. Here is an example: 58 | 59 | ```go 60 | ... 61 | r := gin.New() 62 | r.Use(telem.LogRequest()) 63 | r.Use(telem.MeterRequestDuration()) 64 | r.Use(telem.MeterRequestsInFlight()) 65 | ... 66 | ``` 67 | 68 | ## Development 69 | 70 | The repository contains a `justfile` with useful commands for development. To see the list of available commands, run `just`: 71 | 72 | ```sh 73 | ❯ just 74 | Available recipes: 75 | build # Build the gotel package 76 | default # Default recipe 77 | deps # Install dependencies 78 | gen-mocks # Generate mocks 79 | help # Show help message 80 | lint *ARGS # Run linter (--fix to fix issues) 81 | test json="" # Run tests (--json to output coverage in json format) 82 | ``` 83 | 84 | ## Contributing 85 | 86 | Contributions are welcome! For bug reports, feature requests, or questions, please [open an issue](https://github.com/lucavallin/gotel/issues/new). For pull requests, fork the repository and submit a PR. 87 | -------------------------------------------------------------------------------- /mocks/metric/meterOptionFunc.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockmeterOptionFunc is an autogenerated mock type for the meterOptionFunc type 11 | type MockmeterOptionFunc struct { 12 | mock.Mock 13 | } 14 | 15 | type MockmeterOptionFunc_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockmeterOptionFunc) EXPECT() *MockmeterOptionFunc_Expecter { 20 | return &MockmeterOptionFunc_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // Execute provides a mock function with given fields: _a0 24 | func (_m *MockmeterOptionFunc) Execute(_a0 metric.MeterConfig) metric.MeterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for Execute") 29 | } 30 | 31 | var r0 metric.MeterConfig 32 | if rf, ok := ret.Get(0).(func(metric.MeterConfig) metric.MeterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.MeterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockmeterOptionFunc_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 42 | type MockmeterOptionFunc_Execute_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // Execute is a helper method to define mock.On call 47 | // - _a0 metric.MeterConfig 48 | func (_e *MockmeterOptionFunc_Expecter) Execute(_a0 interface{}) *MockmeterOptionFunc_Execute_Call { 49 | return &MockmeterOptionFunc_Execute_Call{Call: _e.mock.On("Execute", _a0)} 50 | } 51 | 52 | func (_c *MockmeterOptionFunc_Execute_Call) Run(run func(_a0 metric.MeterConfig)) *MockmeterOptionFunc_Execute_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.MeterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockmeterOptionFunc_Execute_Call) Return(_a0 metric.MeterConfig) *MockmeterOptionFunc_Execute_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockmeterOptionFunc_Execute_Call) RunAndReturn(run func(metric.MeterConfig) metric.MeterConfig) *MockmeterOptionFunc_Execute_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockmeterOptionFunc creates a new instance of MockmeterOptionFunc. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockmeterOptionFunc(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockmeterOptionFunc { 75 | mock := &MockmeterOptionFunc{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/RecordOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockRecordOption is an autogenerated mock type for the RecordOption type 11 | type MockRecordOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockRecordOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockRecordOption) EXPECT() *MockRecordOption_Expecter { 20 | return &MockRecordOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyRecord provides a mock function with given fields: _a0 24 | func (_m *MockRecordOption) applyRecord(_a0 metric.RecordConfig) metric.RecordConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyRecord") 29 | } 30 | 31 | var r0 metric.RecordConfig 32 | if rf, ok := ret.Get(0).(func(metric.RecordConfig) metric.RecordConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.RecordConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockRecordOption_applyRecord_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyRecord' 42 | type MockRecordOption_applyRecord_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyRecord is a helper method to define mock.On call 47 | // - _a0 metric.RecordConfig 48 | func (_e *MockRecordOption_Expecter) applyRecord(_a0 interface{}) *MockRecordOption_applyRecord_Call { 49 | return &MockRecordOption_applyRecord_Call{Call: _e.mock.On("applyRecord", _a0)} 50 | } 51 | 52 | func (_c *MockRecordOption_applyRecord_Call) Run(run func(_a0 metric.RecordConfig)) *MockRecordOption_applyRecord_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.RecordConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockRecordOption_applyRecord_Call) Return(_a0 metric.RecordConfig) *MockRecordOption_applyRecord_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockRecordOption_applyRecord_Call) RunAndReturn(run func(metric.RecordConfig) metric.RecordConfig) *MockRecordOption_applyRecord_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockRecordOption creates a new instance of MockRecordOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockRecordOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockRecordOption { 75 | mock := &MockRecordOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/trace/SpanEndOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockSpanEndOption is an autogenerated mock type for the SpanEndOption type 11 | type MockSpanEndOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockSpanEndOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockSpanEndOption) EXPECT() *MockSpanEndOption_Expecter { 20 | return &MockSpanEndOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applySpanEnd provides a mock function with given fields: _a0 24 | func (_m *MockSpanEndOption) applySpanEnd(_a0 trace.SpanConfig) trace.SpanConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applySpanEnd") 29 | } 30 | 31 | var r0 trace.SpanConfig 32 | if rf, ok := ret.Get(0).(func(trace.SpanConfig) trace.SpanConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.SpanConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockSpanEndOption_applySpanEnd_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applySpanEnd' 42 | type MockSpanEndOption_applySpanEnd_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applySpanEnd is a helper method to define mock.On call 47 | // - _a0 trace.SpanConfig 48 | func (_e *MockSpanEndOption_Expecter) applySpanEnd(_a0 interface{}) *MockSpanEndOption_applySpanEnd_Call { 49 | return &MockSpanEndOption_applySpanEnd_Call{Call: _e.mock.On("applySpanEnd", _a0)} 50 | } 51 | 52 | func (_c *MockSpanEndOption_applySpanEnd_Call) Run(run func(_a0 trace.SpanConfig)) *MockSpanEndOption_applySpanEnd_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.SpanConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockSpanEndOption_applySpanEnd_Call) Return(_a0 trace.SpanConfig) *MockSpanEndOption_applySpanEnd_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockSpanEndOption_applySpanEnd_Call) RunAndReturn(run func(trace.SpanConfig) trace.SpanConfig) *MockSpanEndOption_applySpanEnd_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockSpanEndOption creates a new instance of MockSpanEndOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockSpanEndOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockSpanEndOption { 75 | mock := &MockSpanEndOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/trace/tracerOptionFunc.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MocktracerOptionFunc is an autogenerated mock type for the tracerOptionFunc type 11 | type MocktracerOptionFunc struct { 12 | mock.Mock 13 | } 14 | 15 | type MocktracerOptionFunc_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MocktracerOptionFunc) EXPECT() *MocktracerOptionFunc_Expecter { 20 | return &MocktracerOptionFunc_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // Execute provides a mock function with given fields: _a0 24 | func (_m *MocktracerOptionFunc) Execute(_a0 trace.TracerConfig) trace.TracerConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for Execute") 29 | } 30 | 31 | var r0 trace.TracerConfig 32 | if rf, ok := ret.Get(0).(func(trace.TracerConfig) trace.TracerConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.TracerConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MocktracerOptionFunc_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 42 | type MocktracerOptionFunc_Execute_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // Execute is a helper method to define mock.On call 47 | // - _a0 trace.TracerConfig 48 | func (_e *MocktracerOptionFunc_Expecter) Execute(_a0 interface{}) *MocktracerOptionFunc_Execute_Call { 49 | return &MocktracerOptionFunc_Execute_Call{Call: _e.mock.On("Execute", _a0)} 50 | } 51 | 52 | func (_c *MocktracerOptionFunc_Execute_Call) Run(run func(_a0 trace.TracerConfig)) *MocktracerOptionFunc_Execute_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.TracerConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MocktracerOptionFunc_Execute_Call) Return(_a0 trace.TracerConfig) *MocktracerOptionFunc_Execute_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MocktracerOptionFunc_Execute_Call) RunAndReturn(run func(trace.TracerConfig) trace.TracerConfig) *MocktracerOptionFunc_Execute_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMocktracerOptionFunc creates a new instance of MocktracerOptionFunc. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMocktracerOptionFunc(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MocktracerOptionFunc { 75 | mock := &MocktracerOptionFunc{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/embedded/Int64ObservableUpDownCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64ObservableUpDownCounter is an autogenerated mock type for the Int64ObservableUpDownCounter type 8 | type MockInt64ObservableUpDownCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64ObservableUpDownCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64ObservableUpDownCounter) EXPECT() *MockInt64ObservableUpDownCounter_Expecter { 17 | return &MockInt64ObservableUpDownCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64ObservableUpDownCounter provides a mock function with no fields 21 | func (_m *MockInt64ObservableUpDownCounter) int64ObservableUpDownCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64ObservableUpDownCounter' 26 | type MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64ObservableUpDownCounter is a helper method to define mock.On call 31 | func (_e *MockInt64ObservableUpDownCounter_Expecter) int64ObservableUpDownCounter() *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call { 32 | return &MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call{Call: _e.mock.On("int64ObservableUpDownCounter")} 33 | } 34 | 35 | func (_c *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call) Run(run func()) *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call) Return() *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call) RunAndReturn(run func()) *MockInt64ObservableUpDownCounter_int64ObservableUpDownCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockInt64ObservableUpDownCounter creates a new instance of MockInt64ObservableUpDownCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockInt64ObservableUpDownCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockInt64ObservableUpDownCounter { 58 | mock := &MockInt64ObservableUpDownCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/metric/ObserveOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockObserveOption is an autogenerated mock type for the ObserveOption type 11 | type MockObserveOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockObserveOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockObserveOption) EXPECT() *MockObserveOption_Expecter { 20 | return &MockObserveOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyObserve provides a mock function with given fields: _a0 24 | func (_m *MockObserveOption) applyObserve(_a0 metric.ObserveConfig) metric.ObserveConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyObserve") 29 | } 30 | 31 | var r0 metric.ObserveConfig 32 | if rf, ok := ret.Get(0).(func(metric.ObserveConfig) metric.ObserveConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.ObserveConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockObserveOption_applyObserve_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyObserve' 42 | type MockObserveOption_applyObserve_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyObserve is a helper method to define mock.On call 47 | // - _a0 metric.ObserveConfig 48 | func (_e *MockObserveOption_Expecter) applyObserve(_a0 interface{}) *MockObserveOption_applyObserve_Call { 49 | return &MockObserveOption_applyObserve_Call{Call: _e.mock.On("applyObserve", _a0)} 50 | } 51 | 52 | func (_c *MockObserveOption_applyObserve_Call) Run(run func(_a0 metric.ObserveConfig)) *MockObserveOption_applyObserve_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.ObserveConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockObserveOption_applyObserve_Call) Return(_a0 metric.ObserveConfig) *MockObserveOption_applyObserve_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockObserveOption_applyObserve_Call) RunAndReturn(run func(metric.ObserveConfig) metric.ObserveConfig) *MockObserveOption_applyObserve_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockObserveOption creates a new instance of MockObserveOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockObserveOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockObserveOption { 75 | mock := &MockObserveOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64Callback.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockInt64Callback is an autogenerated mock type for the Int64Callback type 13 | type MockInt64Callback struct { 14 | mock.Mock 15 | } 16 | 17 | type MockInt64Callback_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockInt64Callback) EXPECT() *MockInt64Callback_Expecter { 22 | return &MockInt64Callback_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Execute provides a mock function with given fields: _a0, _a1 26 | func (_m *MockInt64Callback) Execute(_a0 context.Context, _a1 metric.Int64Observer) error { 27 | ret := _m.Called(_a0, _a1) 28 | 29 | if len(ret) == 0 { 30 | panic("no return value specified for Execute") 31 | } 32 | 33 | var r0 error 34 | if rf, ok := ret.Get(0).(func(context.Context, metric.Int64Observer) error); ok { 35 | r0 = rf(_a0, _a1) 36 | } else { 37 | r0 = ret.Error(0) 38 | } 39 | 40 | return r0 41 | } 42 | 43 | // MockInt64Callback_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 44 | type MockInt64Callback_Execute_Call struct { 45 | *mock.Call 46 | } 47 | 48 | // Execute is a helper method to define mock.On call 49 | // - _a0 context.Context 50 | // - _a1 metric.Int64Observer 51 | func (_e *MockInt64Callback_Expecter) Execute(_a0 interface{}, _a1 interface{}) *MockInt64Callback_Execute_Call { 52 | return &MockInt64Callback_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} 53 | } 54 | 55 | func (_c *MockInt64Callback_Execute_Call) Run(run func(_a0 context.Context, _a1 metric.Int64Observer)) *MockInt64Callback_Execute_Call { 56 | _c.Call.Run(func(args mock.Arguments) { 57 | run(args[0].(context.Context), args[1].(metric.Int64Observer)) 58 | }) 59 | return _c 60 | } 61 | 62 | func (_c *MockInt64Callback_Execute_Call) Return(_a0 error) *MockInt64Callback_Execute_Call { 63 | _c.Call.Return(_a0) 64 | return _c 65 | } 66 | 67 | func (_c *MockInt64Callback_Execute_Call) RunAndReturn(run func(context.Context, metric.Int64Observer) error) *MockInt64Callback_Execute_Call { 68 | _c.Call.Return(run) 69 | return _c 70 | } 71 | 72 | // NewMockInt64Callback creates a new instance of MockInt64Callback. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 73 | // The first argument is typically a *testing.T value. 74 | func NewMockInt64Callback(t interface { 75 | mock.TestingT 76 | Cleanup(func()) 77 | }) *MockInt64Callback { 78 | mock := &MockInt64Callback{} 79 | mock.Mock.Test(t) 80 | 81 | t.Cleanup(func() { mock.AssertExpectations(t) }) 82 | 83 | return mock 84 | } 85 | -------------------------------------------------------------------------------- /mocks/trace/SpanStartOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockSpanStartOption is an autogenerated mock type for the SpanStartOption type 11 | type MockSpanStartOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockSpanStartOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockSpanStartOption) EXPECT() *MockSpanStartOption_Expecter { 20 | return &MockSpanStartOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applySpanStart provides a mock function with given fields: _a0 24 | func (_m *MockSpanStartOption) applySpanStart(_a0 trace.SpanConfig) trace.SpanConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applySpanStart") 29 | } 30 | 31 | var r0 trace.SpanConfig 32 | if rf, ok := ret.Get(0).(func(trace.SpanConfig) trace.SpanConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.SpanConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockSpanStartOption_applySpanStart_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applySpanStart' 42 | type MockSpanStartOption_applySpanStart_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applySpanStart is a helper method to define mock.On call 47 | // - _a0 trace.SpanConfig 48 | func (_e *MockSpanStartOption_Expecter) applySpanStart(_a0 interface{}) *MockSpanStartOption_applySpanStart_Call { 49 | return &MockSpanStartOption_applySpanStart_Call{Call: _e.mock.On("applySpanStart", _a0)} 50 | } 51 | 52 | func (_c *MockSpanStartOption_applySpanStart_Call) Run(run func(_a0 trace.SpanConfig)) *MockSpanStartOption_applySpanStart_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.SpanConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockSpanStartOption_applySpanStart_Call) Return(_a0 trace.SpanConfig) *MockSpanStartOption_applySpanStart_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockSpanStartOption_applySpanStart_Call) RunAndReturn(run func(trace.SpanConfig) trace.SpanConfig) *MockSpanStartOption_applySpanStart_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockSpanStartOption creates a new instance of MockSpanStartOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockSpanStartOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockSpanStartOption { 75 | mock := &MockSpanStartOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/embedded/Float64ObservableUpDownCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package embedded 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64ObservableUpDownCounter is an autogenerated mock type for the Float64ObservableUpDownCounter type 8 | type MockFloat64ObservableUpDownCounter struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64ObservableUpDownCounter_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64ObservableUpDownCounter) EXPECT() *MockFloat64ObservableUpDownCounter_Expecter { 17 | return &MockFloat64ObservableUpDownCounter_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64ObservableUpDownCounter provides a mock function with no fields 21 | func (_m *MockFloat64ObservableUpDownCounter) float64ObservableUpDownCounter() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64ObservableUpDownCounter' 26 | type MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64ObservableUpDownCounter is a helper method to define mock.On call 31 | func (_e *MockFloat64ObservableUpDownCounter_Expecter) float64ObservableUpDownCounter() *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call { 32 | return &MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call{Call: _e.mock.On("float64ObservableUpDownCounter")} 33 | } 34 | 35 | func (_c *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call) Run(run func()) *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call) Return() *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call) RunAndReturn(run func()) *MockFloat64ObservableUpDownCounter_float64ObservableUpDownCounter_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // NewMockFloat64ObservableUpDownCounter creates a new instance of MockFloat64ObservableUpDownCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 53 | // The first argument is typically a *testing.T value. 54 | func NewMockFloat64ObservableUpDownCounter(t interface { 55 | mock.TestingT 56 | Cleanup(func()) 57 | }) *MockFloat64ObservableUpDownCounter { 58 | mock := &MockFloat64ObservableUpDownCounter{} 59 | mock.Mock.Test(t) 60 | 61 | t.Cleanup(func() { mock.AssertExpectations(t) }) 62 | 63 | return mock 64 | } 65 | -------------------------------------------------------------------------------- /mocks/metric/Float64Callback.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockFloat64Callback is an autogenerated mock type for the Float64Callback type 13 | type MockFloat64Callback struct { 14 | mock.Mock 15 | } 16 | 17 | type MockFloat64Callback_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockFloat64Callback) EXPECT() *MockFloat64Callback_Expecter { 22 | return &MockFloat64Callback_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Execute provides a mock function with given fields: _a0, _a1 26 | func (_m *MockFloat64Callback) Execute(_a0 context.Context, _a1 metric.Float64Observer) error { 27 | ret := _m.Called(_a0, _a1) 28 | 29 | if len(ret) == 0 { 30 | panic("no return value specified for Execute") 31 | } 32 | 33 | var r0 error 34 | if rf, ok := ret.Get(0).(func(context.Context, metric.Float64Observer) error); ok { 35 | r0 = rf(_a0, _a1) 36 | } else { 37 | r0 = ret.Error(0) 38 | } 39 | 40 | return r0 41 | } 42 | 43 | // MockFloat64Callback_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' 44 | type MockFloat64Callback_Execute_Call struct { 45 | *mock.Call 46 | } 47 | 48 | // Execute is a helper method to define mock.On call 49 | // - _a0 context.Context 50 | // - _a1 metric.Float64Observer 51 | func (_e *MockFloat64Callback_Expecter) Execute(_a0 interface{}, _a1 interface{}) *MockFloat64Callback_Execute_Call { 52 | return &MockFloat64Callback_Execute_Call{Call: _e.mock.On("Execute", _a0, _a1)} 53 | } 54 | 55 | func (_c *MockFloat64Callback_Execute_Call) Run(run func(_a0 context.Context, _a1 metric.Float64Observer)) *MockFloat64Callback_Execute_Call { 56 | _c.Call.Run(func(args mock.Arguments) { 57 | run(args[0].(context.Context), args[1].(metric.Float64Observer)) 58 | }) 59 | return _c 60 | } 61 | 62 | func (_c *MockFloat64Callback_Execute_Call) Return(_a0 error) *MockFloat64Callback_Execute_Call { 63 | _c.Call.Return(_a0) 64 | return _c 65 | } 66 | 67 | func (_c *MockFloat64Callback_Execute_Call) RunAndReturn(run func(context.Context, metric.Float64Observer) error) *MockFloat64Callback_Execute_Call { 68 | _c.Call.Return(run) 69 | return _c 70 | } 71 | 72 | // NewMockFloat64Callback creates a new instance of MockFloat64Callback. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 73 | // The first argument is typically a *testing.T value. 74 | func NewMockFloat64Callback(t interface { 75 | mock.TestingT 76 | Cleanup(func()) 77 | }) *MockFloat64Callback { 78 | mock := &MockFloat64Callback{} 79 | mock.Mock.Test(t) 80 | 81 | t.Cleanup(func() { mock.AssertExpectations(t) }) 82 | 83 | return mock 84 | } 85 | -------------------------------------------------------------------------------- /mocks/metric/Int64GaugeOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64GaugeOption is an autogenerated mock type for the Int64GaugeOption type 11 | type MockInt64GaugeOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64GaugeOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64GaugeOption) EXPECT() *MockInt64GaugeOption_Expecter { 20 | return &MockInt64GaugeOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64Gauge provides a mock function with given fields: _a0 24 | func (_m *MockInt64GaugeOption) applyInt64Gauge(_a0 metric.Int64GaugeConfig) metric.Int64GaugeConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64Gauge") 29 | } 30 | 31 | var r0 metric.Int64GaugeConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64GaugeConfig) metric.Int64GaugeConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64GaugeConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64GaugeOption_applyInt64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64Gauge' 42 | type MockInt64GaugeOption_applyInt64Gauge_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64Gauge is a helper method to define mock.On call 47 | // - _a0 metric.Int64GaugeConfig 48 | func (_e *MockInt64GaugeOption_Expecter) applyInt64Gauge(_a0 interface{}) *MockInt64GaugeOption_applyInt64Gauge_Call { 49 | return &MockInt64GaugeOption_applyInt64Gauge_Call{Call: _e.mock.On("applyInt64Gauge", _a0)} 50 | } 51 | 52 | func (_c *MockInt64GaugeOption_applyInt64Gauge_Call) Run(run func(_a0 metric.Int64GaugeConfig)) *MockInt64GaugeOption_applyInt64Gauge_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64GaugeConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64GaugeOption_applyInt64Gauge_Call) Return(_a0 metric.Int64GaugeConfig) *MockInt64GaugeOption_applyInt64Gauge_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64GaugeOption_applyInt64Gauge_Call) RunAndReturn(run func(metric.Int64GaugeConfig) metric.Int64GaugeConfig) *MockInt64GaugeOption_applyInt64Gauge_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64GaugeOption creates a new instance of MockInt64GaugeOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64GaugeOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64GaugeOption { 75 | mock := &MockInt64GaugeOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Float64GaugeOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64GaugeOption is an autogenerated mock type for the Float64GaugeOption type 11 | type MockFloat64GaugeOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64GaugeOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64GaugeOption) EXPECT() *MockFloat64GaugeOption_Expecter { 20 | return &MockFloat64GaugeOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64Gauge provides a mock function with given fields: _a0 24 | func (_m *MockFloat64GaugeOption) applyFloat64Gauge(_a0 metric.Float64GaugeConfig) metric.Float64GaugeConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64Gauge") 29 | } 30 | 31 | var r0 metric.Float64GaugeConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64GaugeConfig) metric.Float64GaugeConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64GaugeConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64GaugeOption_applyFloat64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64Gauge' 42 | type MockFloat64GaugeOption_applyFloat64Gauge_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64Gauge is a helper method to define mock.On call 47 | // - _a0 metric.Float64GaugeConfig 48 | func (_e *MockFloat64GaugeOption_Expecter) applyFloat64Gauge(_a0 interface{}) *MockFloat64GaugeOption_applyFloat64Gauge_Call { 49 | return &MockFloat64GaugeOption_applyFloat64Gauge_Call{Call: _e.mock.On("applyFloat64Gauge", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64GaugeOption_applyFloat64Gauge_Call) Run(run func(_a0 metric.Float64GaugeConfig)) *MockFloat64GaugeOption_applyFloat64Gauge_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64GaugeConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64GaugeOption_applyFloat64Gauge_Call) Return(_a0 metric.Float64GaugeConfig) *MockFloat64GaugeOption_applyFloat64Gauge_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64GaugeOption_applyFloat64Gauge_Call) RunAndReturn(run func(metric.Float64GaugeConfig) metric.Float64GaugeConfig) *MockFloat64GaugeOption_applyFloat64Gauge_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64GaugeOption creates a new instance of MockFloat64GaugeOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64GaugeOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64GaugeOption { 75 | mock := &MockFloat64GaugeOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64CounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64CounterOption is an autogenerated mock type for the Int64CounterOption type 11 | type MockInt64CounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64CounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64CounterOption) EXPECT() *MockInt64CounterOption_Expecter { 20 | return &MockInt64CounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64Counter provides a mock function with given fields: _a0 24 | func (_m *MockInt64CounterOption) applyInt64Counter(_a0 metric.Int64CounterConfig) metric.Int64CounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64Counter") 29 | } 30 | 31 | var r0 metric.Int64CounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64CounterConfig) metric.Int64CounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64CounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64CounterOption_applyInt64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64Counter' 42 | type MockInt64CounterOption_applyInt64Counter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64Counter is a helper method to define mock.On call 47 | // - _a0 metric.Int64CounterConfig 48 | func (_e *MockInt64CounterOption_Expecter) applyInt64Counter(_a0 interface{}) *MockInt64CounterOption_applyInt64Counter_Call { 49 | return &MockInt64CounterOption_applyInt64Counter_Call{Call: _e.mock.On("applyInt64Counter", _a0)} 50 | } 51 | 52 | func (_c *MockInt64CounterOption_applyInt64Counter_Call) Run(run func(_a0 metric.Int64CounterConfig)) *MockInt64CounterOption_applyInt64Counter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64CounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64CounterOption_applyInt64Counter_Call) Return(_a0 metric.Int64CounterConfig) *MockInt64CounterOption_applyInt64Counter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64CounterOption_applyInt64Counter_Call) RunAndReturn(run func(metric.Int64CounterConfig) metric.Int64CounterConfig) *MockInt64CounterOption_applyInt64Counter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64CounterOption creates a new instance of MockInt64CounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64CounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64CounterOption { 75 | mock := &MockInt64CounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Float64CounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64CounterOption is an autogenerated mock type for the Float64CounterOption type 11 | type MockFloat64CounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64CounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64CounterOption) EXPECT() *MockFloat64CounterOption_Expecter { 20 | return &MockFloat64CounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64Counter provides a mock function with given fields: _a0 24 | func (_m *MockFloat64CounterOption) applyFloat64Counter(_a0 metric.Float64CounterConfig) metric.Float64CounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64Counter") 29 | } 30 | 31 | var r0 metric.Float64CounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64CounterConfig) metric.Float64CounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64CounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64CounterOption_applyFloat64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64Counter' 42 | type MockFloat64CounterOption_applyFloat64Counter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64Counter is a helper method to define mock.On call 47 | // - _a0 metric.Float64CounterConfig 48 | func (_e *MockFloat64CounterOption_Expecter) applyFloat64Counter(_a0 interface{}) *MockFloat64CounterOption_applyFloat64Counter_Call { 49 | return &MockFloat64CounterOption_applyFloat64Counter_Call{Call: _e.mock.On("applyFloat64Counter", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64CounterOption_applyFloat64Counter_Call) Run(run func(_a0 metric.Float64CounterConfig)) *MockFloat64CounterOption_applyFloat64Counter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64CounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64CounterOption_applyFloat64Counter_Call) Return(_a0 metric.Float64CounterConfig) *MockFloat64CounterOption_applyFloat64Counter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64CounterOption_applyFloat64Counter_Call) RunAndReturn(run func(metric.Float64CounterConfig) metric.Float64CounterConfig) *MockFloat64CounterOption_applyFloat64Counter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64CounterOption creates a new instance of MockFloat64CounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64CounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64CounterOption { 75 | mock := &MockFloat64CounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64HistogramOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64HistogramOption is an autogenerated mock type for the Int64HistogramOption type 11 | type MockInt64HistogramOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64HistogramOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64HistogramOption) EXPECT() *MockInt64HistogramOption_Expecter { 20 | return &MockInt64HistogramOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64Histogram provides a mock function with given fields: _a0 24 | func (_m *MockInt64HistogramOption) applyInt64Histogram(_a0 metric.Int64HistogramConfig) metric.Int64HistogramConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64Histogram") 29 | } 30 | 31 | var r0 metric.Int64HistogramConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64HistogramConfig) metric.Int64HistogramConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64HistogramConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64HistogramOption_applyInt64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64Histogram' 42 | type MockInt64HistogramOption_applyInt64Histogram_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64Histogram is a helper method to define mock.On call 47 | // - _a0 metric.Int64HistogramConfig 48 | func (_e *MockInt64HistogramOption_Expecter) applyInt64Histogram(_a0 interface{}) *MockInt64HistogramOption_applyInt64Histogram_Call { 49 | return &MockInt64HistogramOption_applyInt64Histogram_Call{Call: _e.mock.On("applyInt64Histogram", _a0)} 50 | } 51 | 52 | func (_c *MockInt64HistogramOption_applyInt64Histogram_Call) Run(run func(_a0 metric.Int64HistogramConfig)) *MockInt64HistogramOption_applyInt64Histogram_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64HistogramConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64HistogramOption_applyInt64Histogram_Call) Return(_a0 metric.Int64HistogramConfig) *MockInt64HistogramOption_applyInt64Histogram_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64HistogramOption_applyInt64Histogram_Call) RunAndReturn(run func(metric.Int64HistogramConfig) metric.Int64HistogramConfig) *MockInt64HistogramOption_applyInt64Histogram_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64HistogramOption creates a new instance of MockInt64HistogramOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64HistogramOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64HistogramOption { 75 | mock := &MockInt64HistogramOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Float64HistogramOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64HistogramOption is an autogenerated mock type for the Float64HistogramOption type 11 | type MockFloat64HistogramOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64HistogramOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64HistogramOption) EXPECT() *MockFloat64HistogramOption_Expecter { 20 | return &MockFloat64HistogramOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64Histogram provides a mock function with given fields: _a0 24 | func (_m *MockFloat64HistogramOption) applyFloat64Histogram(_a0 metric.Float64HistogramConfig) metric.Float64HistogramConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64Histogram") 29 | } 30 | 31 | var r0 metric.Float64HistogramConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64HistogramConfig) metric.Float64HistogramConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64HistogramConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64HistogramOption_applyFloat64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64Histogram' 42 | type MockFloat64HistogramOption_applyFloat64Histogram_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64Histogram is a helper method to define mock.On call 47 | // - _a0 metric.Float64HistogramConfig 48 | func (_e *MockFloat64HistogramOption_Expecter) applyFloat64Histogram(_a0 interface{}) *MockFloat64HistogramOption_applyFloat64Histogram_Call { 49 | return &MockFloat64HistogramOption_applyFloat64Histogram_Call{Call: _e.mock.On("applyFloat64Histogram", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64HistogramOption_applyFloat64Histogram_Call) Run(run func(_a0 metric.Float64HistogramConfig)) *MockFloat64HistogramOption_applyFloat64Histogram_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64HistogramConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64HistogramOption_applyFloat64Histogram_Call) Return(_a0 metric.Float64HistogramConfig) *MockFloat64HistogramOption_applyFloat64Histogram_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64HistogramOption_applyFloat64Histogram_Call) RunAndReturn(run func(metric.Float64HistogramConfig) metric.Float64HistogramConfig) *MockFloat64HistogramOption_applyFloat64Histogram_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64HistogramOption creates a new instance of MockFloat64HistogramOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64HistogramOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64HistogramOption { 75 | mock := &MockFloat64HistogramOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64Observable.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockInt64Observable is an autogenerated mock type for the Int64Observable type 8 | type MockInt64Observable struct { 9 | mock.Mock 10 | } 11 | 12 | type MockInt64Observable_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockInt64Observable) EXPECT() *MockInt64Observable_Expecter { 17 | return &MockInt64Observable_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // int64Observable provides a mock function with no fields 21 | func (_m *MockInt64Observable) int64Observable() { 22 | _m.Called() 23 | } 24 | 25 | // MockInt64Observable_int64Observable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Observable' 26 | type MockInt64Observable_int64Observable_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // int64Observable is a helper method to define mock.On call 31 | func (_e *MockInt64Observable_Expecter) int64Observable() *MockInt64Observable_int64Observable_Call { 32 | return &MockInt64Observable_int64Observable_Call{Call: _e.mock.On("int64Observable")} 33 | } 34 | 35 | func (_c *MockInt64Observable_int64Observable_Call) Run(run func()) *MockInt64Observable_int64Observable_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockInt64Observable_int64Observable_Call) Return() *MockInt64Observable_int64Observable_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockInt64Observable_int64Observable_Call) RunAndReturn(run func()) *MockInt64Observable_int64Observable_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // observable provides a mock function with no fields 53 | func (_m *MockInt64Observable) observable() { 54 | _m.Called() 55 | } 56 | 57 | // MockInt64Observable_observable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'observable' 58 | type MockInt64Observable_observable_Call struct { 59 | *mock.Call 60 | } 61 | 62 | // observable is a helper method to define mock.On call 63 | func (_e *MockInt64Observable_Expecter) observable() *MockInt64Observable_observable_Call { 64 | return &MockInt64Observable_observable_Call{Call: _e.mock.On("observable")} 65 | } 66 | 67 | func (_c *MockInt64Observable_observable_Call) Run(run func()) *MockInt64Observable_observable_Call { 68 | _c.Call.Run(func(args mock.Arguments) { 69 | run() 70 | }) 71 | return _c 72 | } 73 | 74 | func (_c *MockInt64Observable_observable_Call) Return() *MockInt64Observable_observable_Call { 75 | _c.Call.Return() 76 | return _c 77 | } 78 | 79 | func (_c *MockInt64Observable_observable_Call) RunAndReturn(run func()) *MockInt64Observable_observable_Call { 80 | _c.Run(run) 81 | return _c 82 | } 83 | 84 | // NewMockInt64Observable creates a new instance of MockInt64Observable. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 85 | // The first argument is typically a *testing.T value. 86 | func NewMockInt64Observable(t interface { 87 | mock.TestingT 88 | Cleanup(func()) 89 | }) *MockInt64Observable { 90 | mock := &MockInt64Observable{} 91 | mock.Mock.Test(t) 92 | 93 | t.Cleanup(func() { mock.AssertExpectations(t) }) 94 | 95 | return mock 96 | } 97 | -------------------------------------------------------------------------------- /mocks/metric/Int64UpDownCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64UpDownCounterOption is an autogenerated mock type for the Int64UpDownCounterOption type 11 | type MockInt64UpDownCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64UpDownCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64UpDownCounterOption) EXPECT() *MockInt64UpDownCounterOption_Expecter { 20 | return &MockInt64UpDownCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64UpDownCounter provides a mock function with given fields: _a0 24 | func (_m *MockInt64UpDownCounterOption) applyInt64UpDownCounter(_a0 metric.Int64UpDownCounterConfig) metric.Int64UpDownCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64UpDownCounter") 29 | } 30 | 31 | var r0 metric.Int64UpDownCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64UpDownCounterConfig) metric.Int64UpDownCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64UpDownCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64UpDownCounter' 42 | type MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64UpDownCounter is a helper method to define mock.On call 47 | // - _a0 metric.Int64UpDownCounterConfig 48 | func (_e *MockInt64UpDownCounterOption_Expecter) applyInt64UpDownCounter(_a0 interface{}) *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call { 49 | return &MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call{Call: _e.mock.On("applyInt64UpDownCounter", _a0)} 50 | } 51 | 52 | func (_c *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call) Run(run func(_a0 metric.Int64UpDownCounterConfig)) *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64UpDownCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call) Return(_a0 metric.Int64UpDownCounterConfig) *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call) RunAndReturn(run func(metric.Int64UpDownCounterConfig) metric.Int64UpDownCounterConfig) *MockInt64UpDownCounterOption_applyInt64UpDownCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64UpDownCounterOption creates a new instance of MockInt64UpDownCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64UpDownCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64UpDownCounterOption { 75 | mock := &MockInt64UpDownCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/lucavallin/gotel 2 | 3 | go 1.23.4 4 | 5 | require ( 6 | github.com/caarlos0/env v3.5.0+incompatible 7 | github.com/gin-gonic/gin v1.11.0 8 | github.com/stretchr/testify v1.11.1 9 | go.opentelemetry.io/contrib/bridges/otelzap v0.13.0 10 | go.opentelemetry.io/otel v1.38.0 11 | go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.14.0 12 | go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.38.0 13 | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.38.0 14 | go.opentelemetry.io/otel/metric v1.38.0 15 | go.opentelemetry.io/otel/sdk v1.38.0 16 | go.opentelemetry.io/otel/sdk/log v0.14.0 17 | go.opentelemetry.io/otel/sdk/metric v1.38.0 18 | go.opentelemetry.io/otel/trace v1.38.0 19 | go.uber.org/zap v1.27.0 20 | ) 21 | 22 | require ( 23 | github.com/bytedance/sonic v1.14.0 // indirect 24 | github.com/bytedance/sonic/loader v0.3.0 // indirect 25 | github.com/cenkalti/backoff/v5 v5.0.3 // indirect 26 | github.com/cloudwego/base64x v0.1.6 // indirect 27 | github.com/davecgh/go-spew v1.1.1 // indirect 28 | github.com/gabriel-vasile/mimetype v1.4.8 // indirect 29 | github.com/gin-contrib/sse v1.1.0 // indirect 30 | github.com/go-logr/logr v1.4.3 // indirect 31 | github.com/go-logr/stdr v1.2.2 // indirect 32 | github.com/go-playground/locales v0.14.1 // indirect 33 | github.com/go-playground/universal-translator v0.18.1 // indirect 34 | github.com/go-playground/validator/v10 v10.27.0 // indirect 35 | github.com/goccy/go-json v0.10.2 // indirect 36 | github.com/goccy/go-yaml v1.18.0 // indirect 37 | github.com/google/uuid v1.6.0 // indirect 38 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.2 // indirect 39 | github.com/json-iterator/go v1.1.12 // indirect 40 | github.com/klauspost/cpuid/v2 v2.3.0 // indirect 41 | github.com/leodido/go-urn v1.4.0 // indirect 42 | github.com/mattn/go-isatty v0.0.20 // indirect 43 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 44 | github.com/modern-go/reflect2 v1.0.2 // indirect 45 | github.com/pelletier/go-toml/v2 v2.2.4 // indirect 46 | github.com/pmezard/go-difflib v1.0.0 // indirect 47 | github.com/quic-go/qpack v0.5.1 // indirect 48 | github.com/quic-go/quic-go v0.54.0 // indirect 49 | github.com/stretchr/objx v0.5.2 // indirect 50 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 51 | github.com/ugorji/go/codec v1.3.0 // indirect 52 | go.opentelemetry.io/auto/sdk v1.1.0 // indirect 53 | go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.38.0 // indirect 54 | go.opentelemetry.io/otel/log v0.14.0 // indirect 55 | go.opentelemetry.io/proto/otlp v1.7.1 // indirect 56 | go.uber.org/mock v0.5.0 // indirect 57 | go.uber.org/multierr v1.11.0 // indirect 58 | golang.org/x/arch v0.20.0 // indirect 59 | golang.org/x/crypto v0.41.0 // indirect 60 | golang.org/x/mod v0.26.0 // indirect 61 | golang.org/x/net v0.43.0 // indirect 62 | golang.org/x/sync v0.16.0 // indirect 63 | golang.org/x/sys v0.35.0 // indirect 64 | golang.org/x/text v0.28.0 // indirect 65 | golang.org/x/tools v0.35.0 // indirect 66 | google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 // indirect 67 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect 68 | google.golang.org/grpc v1.75.0 // indirect 69 | google.golang.org/protobuf v1.36.9 // indirect 70 | gopkg.in/yaml.v3 v3.0.1 // indirect 71 | ) 72 | -------------------------------------------------------------------------------- /mocks/metric/Float64Observable.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockFloat64Observable is an autogenerated mock type for the Float64Observable type 8 | type MockFloat64Observable struct { 9 | mock.Mock 10 | } 11 | 12 | type MockFloat64Observable_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockFloat64Observable) EXPECT() *MockFloat64Observable_Expecter { 17 | return &MockFloat64Observable_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // float64Observable provides a mock function with no fields 21 | func (_m *MockFloat64Observable) float64Observable() { 22 | _m.Called() 23 | } 24 | 25 | // MockFloat64Observable_float64Observable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Observable' 26 | type MockFloat64Observable_float64Observable_Call struct { 27 | *mock.Call 28 | } 29 | 30 | // float64Observable is a helper method to define mock.On call 31 | func (_e *MockFloat64Observable_Expecter) float64Observable() *MockFloat64Observable_float64Observable_Call { 32 | return &MockFloat64Observable_float64Observable_Call{Call: _e.mock.On("float64Observable")} 33 | } 34 | 35 | func (_c *MockFloat64Observable_float64Observable_Call) Run(run func()) *MockFloat64Observable_float64Observable_Call { 36 | _c.Call.Run(func(args mock.Arguments) { 37 | run() 38 | }) 39 | return _c 40 | } 41 | 42 | func (_c *MockFloat64Observable_float64Observable_Call) Return() *MockFloat64Observable_float64Observable_Call { 43 | _c.Call.Return() 44 | return _c 45 | } 46 | 47 | func (_c *MockFloat64Observable_float64Observable_Call) RunAndReturn(run func()) *MockFloat64Observable_float64Observable_Call { 48 | _c.Run(run) 49 | return _c 50 | } 51 | 52 | // observable provides a mock function with no fields 53 | func (_m *MockFloat64Observable) observable() { 54 | _m.Called() 55 | } 56 | 57 | // MockFloat64Observable_observable_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'observable' 58 | type MockFloat64Observable_observable_Call struct { 59 | *mock.Call 60 | } 61 | 62 | // observable is a helper method to define mock.On call 63 | func (_e *MockFloat64Observable_Expecter) observable() *MockFloat64Observable_observable_Call { 64 | return &MockFloat64Observable_observable_Call{Call: _e.mock.On("observable")} 65 | } 66 | 67 | func (_c *MockFloat64Observable_observable_Call) Run(run func()) *MockFloat64Observable_observable_Call { 68 | _c.Call.Run(func(args mock.Arguments) { 69 | run() 70 | }) 71 | return _c 72 | } 73 | 74 | func (_c *MockFloat64Observable_observable_Call) Return() *MockFloat64Observable_observable_Call { 75 | _c.Call.Return() 76 | return _c 77 | } 78 | 79 | func (_c *MockFloat64Observable_observable_Call) RunAndReturn(run func()) *MockFloat64Observable_observable_Call { 80 | _c.Run(run) 81 | return _c 82 | } 83 | 84 | // NewMockFloat64Observable creates a new instance of MockFloat64Observable. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 85 | // The first argument is typically a *testing.T value. 86 | func NewMockFloat64Observable(t interface { 87 | mock.TestingT 88 | Cleanup(func()) 89 | }) *MockFloat64Observable { 90 | mock := &MockFloat64Observable{} 91 | mock.Mock.Test(t) 92 | 93 | t.Cleanup(func() { mock.AssertExpectations(t) }) 94 | 95 | return mock 96 | } 97 | -------------------------------------------------------------------------------- /mocks/metric/Float64UpDownCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64UpDownCounterOption is an autogenerated mock type for the Float64UpDownCounterOption type 11 | type MockFloat64UpDownCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64UpDownCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64UpDownCounterOption) EXPECT() *MockFloat64UpDownCounterOption_Expecter { 20 | return &MockFloat64UpDownCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64UpDownCounter provides a mock function with given fields: _a0 24 | func (_m *MockFloat64UpDownCounterOption) applyFloat64UpDownCounter(_a0 metric.Float64UpDownCounterConfig) metric.Float64UpDownCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64UpDownCounter") 29 | } 30 | 31 | var r0 metric.Float64UpDownCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64UpDownCounterConfig) metric.Float64UpDownCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64UpDownCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64UpDownCounter' 42 | type MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64UpDownCounter is a helper method to define mock.On call 47 | // - _a0 metric.Float64UpDownCounterConfig 48 | func (_e *MockFloat64UpDownCounterOption_Expecter) applyFloat64UpDownCounter(_a0 interface{}) *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call { 49 | return &MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call{Call: _e.mock.On("applyFloat64UpDownCounter", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call) Run(run func(_a0 metric.Float64UpDownCounterConfig)) *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64UpDownCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call) Return(_a0 metric.Float64UpDownCounterConfig) *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call) RunAndReturn(run func(metric.Float64UpDownCounterConfig) metric.Float64UpDownCounterConfig) *MockFloat64UpDownCounterOption_applyFloat64UpDownCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64UpDownCounterOption creates a new instance of MockFloat64UpDownCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64UpDownCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64UpDownCounterOption { 75 | mock := &MockFloat64UpDownCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64ObservableGaugeOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64ObservableGaugeOption is an autogenerated mock type for the Int64ObservableGaugeOption type 11 | type MockInt64ObservableGaugeOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64ObservableGaugeOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64ObservableGaugeOption) EXPECT() *MockInt64ObservableGaugeOption_Expecter { 20 | return &MockInt64ObservableGaugeOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64ObservableGauge provides a mock function with given fields: _a0 24 | func (_m *MockInt64ObservableGaugeOption) applyInt64ObservableGauge(_a0 metric.Int64ObservableGaugeConfig) metric.Int64ObservableGaugeConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64ObservableGauge") 29 | } 30 | 31 | var r0 metric.Int64ObservableGaugeConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64ObservableGaugeConfig) metric.Int64ObservableGaugeConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64ObservableGaugeConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64ObservableGauge' 42 | type MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64ObservableGauge is a helper method to define mock.On call 47 | // - _a0 metric.Int64ObservableGaugeConfig 48 | func (_e *MockInt64ObservableGaugeOption_Expecter) applyInt64ObservableGauge(_a0 interface{}) *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call { 49 | return &MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call{Call: _e.mock.On("applyInt64ObservableGauge", _a0)} 50 | } 51 | 52 | func (_c *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call) Run(run func(_a0 metric.Int64ObservableGaugeConfig)) *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64ObservableGaugeConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call) Return(_a0 metric.Int64ObservableGaugeConfig) *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call) RunAndReturn(run func(metric.Int64ObservableGaugeConfig) metric.Int64ObservableGaugeConfig) *MockInt64ObservableGaugeOption_applyInt64ObservableGauge_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64ObservableGaugeOption creates a new instance of MockInt64ObservableGaugeOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64ObservableGaugeOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64ObservableGaugeOption { 75 | mock := &MockInt64ObservableGaugeOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Float64ObservableGaugeOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64ObservableGaugeOption is an autogenerated mock type for the Float64ObservableGaugeOption type 11 | type MockFloat64ObservableGaugeOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64ObservableGaugeOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64ObservableGaugeOption) EXPECT() *MockFloat64ObservableGaugeOption_Expecter { 20 | return &MockFloat64ObservableGaugeOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64ObservableGauge provides a mock function with given fields: _a0 24 | func (_m *MockFloat64ObservableGaugeOption) applyFloat64ObservableGauge(_a0 metric.Float64ObservableGaugeConfig) metric.Float64ObservableGaugeConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64ObservableGauge") 29 | } 30 | 31 | var r0 metric.Float64ObservableGaugeConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64ObservableGaugeConfig) metric.Float64ObservableGaugeConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64ObservableGaugeConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64ObservableGauge' 42 | type MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64ObservableGauge is a helper method to define mock.On call 47 | // - _a0 metric.Float64ObservableGaugeConfig 48 | func (_e *MockFloat64ObservableGaugeOption_Expecter) applyFloat64ObservableGauge(_a0 interface{}) *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call { 49 | return &MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call{Call: _e.mock.On("applyFloat64ObservableGauge", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call) Run(run func(_a0 metric.Float64ObservableGaugeConfig)) *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64ObservableGaugeConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call) Return(_a0 metric.Float64ObservableGaugeConfig) *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call) RunAndReturn(run func(metric.Float64ObservableGaugeConfig) metric.Float64ObservableGaugeConfig) *MockFloat64ObservableGaugeOption_applyFloat64ObservableGauge_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64ObservableGaugeOption creates a new instance of MockFloat64ObservableGaugeOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64ObservableGaugeOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64ObservableGaugeOption { 75 | mock := &MockFloat64ObservableGaugeOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64ObservableCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64ObservableCounterOption is an autogenerated mock type for the Int64ObservableCounterOption type 11 | type MockInt64ObservableCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64ObservableCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64ObservableCounterOption) EXPECT() *MockInt64ObservableCounterOption_Expecter { 20 | return &MockInt64ObservableCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64ObservableCounter provides a mock function with given fields: _a0 24 | func (_m *MockInt64ObservableCounterOption) applyInt64ObservableCounter(_a0 metric.Int64ObservableCounterConfig) metric.Int64ObservableCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64ObservableCounter") 29 | } 30 | 31 | var r0 metric.Int64ObservableCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64ObservableCounterConfig) metric.Int64ObservableCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64ObservableCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64ObservableCounter' 42 | type MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64ObservableCounter is a helper method to define mock.On call 47 | // - _a0 metric.Int64ObservableCounterConfig 48 | func (_e *MockInt64ObservableCounterOption_Expecter) applyInt64ObservableCounter(_a0 interface{}) *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call { 49 | return &MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call{Call: _e.mock.On("applyInt64ObservableCounter", _a0)} 50 | } 51 | 52 | func (_c *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call) Run(run func(_a0 metric.Int64ObservableCounterConfig)) *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64ObservableCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call) Return(_a0 metric.Int64ObservableCounterConfig) *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call) RunAndReturn(run func(metric.Int64ObservableCounterConfig) metric.Int64ObservableCounterConfig) *MockInt64ObservableCounterOption_applyInt64ObservableCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64ObservableCounterOption creates a new instance of MockInt64ObservableCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64ObservableCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64ObservableCounterOption { 75 | mock := &MockInt64ObservableCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Registration.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // MockRegistration is an autogenerated mock type for the Registration type 8 | type MockRegistration struct { 9 | mock.Mock 10 | } 11 | 12 | type MockRegistration_Expecter struct { 13 | mock *mock.Mock 14 | } 15 | 16 | func (_m *MockRegistration) EXPECT() *MockRegistration_Expecter { 17 | return &MockRegistration_Expecter{mock: &_m.Mock} 18 | } 19 | 20 | // Unregister provides a mock function with no fields 21 | func (_m *MockRegistration) Unregister() error { 22 | ret := _m.Called() 23 | 24 | if len(ret) == 0 { 25 | panic("no return value specified for Unregister") 26 | } 27 | 28 | var r0 error 29 | if rf, ok := ret.Get(0).(func() error); ok { 30 | r0 = rf() 31 | } else { 32 | r0 = ret.Error(0) 33 | } 34 | 35 | return r0 36 | } 37 | 38 | // MockRegistration_Unregister_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unregister' 39 | type MockRegistration_Unregister_Call struct { 40 | *mock.Call 41 | } 42 | 43 | // Unregister is a helper method to define mock.On call 44 | func (_e *MockRegistration_Expecter) Unregister() *MockRegistration_Unregister_Call { 45 | return &MockRegistration_Unregister_Call{Call: _e.mock.On("Unregister")} 46 | } 47 | 48 | func (_c *MockRegistration_Unregister_Call) Run(run func()) *MockRegistration_Unregister_Call { 49 | _c.Call.Run(func(args mock.Arguments) { 50 | run() 51 | }) 52 | return _c 53 | } 54 | 55 | func (_c *MockRegistration_Unregister_Call) Return(_a0 error) *MockRegistration_Unregister_Call { 56 | _c.Call.Return(_a0) 57 | return _c 58 | } 59 | 60 | func (_c *MockRegistration_Unregister_Call) RunAndReturn(run func() error) *MockRegistration_Unregister_Call { 61 | _c.Call.Return(run) 62 | return _c 63 | } 64 | 65 | // registration provides a mock function with no fields 66 | func (_m *MockRegistration) registration() { 67 | _m.Called() 68 | } 69 | 70 | // MockRegistration_registration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'registration' 71 | type MockRegistration_registration_Call struct { 72 | *mock.Call 73 | } 74 | 75 | // registration is a helper method to define mock.On call 76 | func (_e *MockRegistration_Expecter) registration() *MockRegistration_registration_Call { 77 | return &MockRegistration_registration_Call{Call: _e.mock.On("registration")} 78 | } 79 | 80 | func (_c *MockRegistration_registration_Call) Run(run func()) *MockRegistration_registration_Call { 81 | _c.Call.Run(func(args mock.Arguments) { 82 | run() 83 | }) 84 | return _c 85 | } 86 | 87 | func (_c *MockRegistration_registration_Call) Return() *MockRegistration_registration_Call { 88 | _c.Call.Return() 89 | return _c 90 | } 91 | 92 | func (_c *MockRegistration_registration_Call) RunAndReturn(run func()) *MockRegistration_registration_Call { 93 | _c.Run(run) 94 | return _c 95 | } 96 | 97 | // NewMockRegistration creates a new instance of MockRegistration. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 98 | // The first argument is typically a *testing.T value. 99 | func NewMockRegistration(t interface { 100 | mock.TestingT 101 | Cleanup(func()) 102 | }) *MockRegistration { 103 | mock := &MockRegistration{} 104 | mock.Mock.Test(t) 105 | 106 | t.Cleanup(func() { mock.AssertExpectations(t) }) 107 | 108 | return mock 109 | } 110 | -------------------------------------------------------------------------------- /mocks/metric/Float64ObservableCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64ObservableCounterOption is an autogenerated mock type for the Float64ObservableCounterOption type 11 | type MockFloat64ObservableCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64ObservableCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64ObservableCounterOption) EXPECT() *MockFloat64ObservableCounterOption_Expecter { 20 | return &MockFloat64ObservableCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64ObservableCounter provides a mock function with given fields: _a0 24 | func (_m *MockFloat64ObservableCounterOption) applyFloat64ObservableCounter(_a0 metric.Float64ObservableCounterConfig) metric.Float64ObservableCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64ObservableCounter") 29 | } 30 | 31 | var r0 metric.Float64ObservableCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64ObservableCounterConfig) metric.Float64ObservableCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64ObservableCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64ObservableCounter' 42 | type MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64ObservableCounter is a helper method to define mock.On call 47 | // - _a0 metric.Float64ObservableCounterConfig 48 | func (_e *MockFloat64ObservableCounterOption_Expecter) applyFloat64ObservableCounter(_a0 interface{}) *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call { 49 | return &MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call{Call: _e.mock.On("applyFloat64ObservableCounter", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call) Run(run func(_a0 metric.Float64ObservableCounterConfig)) *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64ObservableCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call) Return(_a0 metric.Float64ObservableCounterConfig) *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call) RunAndReturn(run func(metric.Float64ObservableCounterConfig) metric.Float64ObservableCounterConfig) *MockFloat64ObservableCounterOption_applyFloat64ObservableCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64ObservableCounterOption creates a new instance of MockFloat64ObservableCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64ObservableCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64ObservableCounterOption { 75 | mock := &MockFloat64ObservableCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Int64ObservableUpDownCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64ObservableUpDownCounterOption is an autogenerated mock type for the Int64ObservableUpDownCounterOption type 11 | type MockInt64ObservableUpDownCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64ObservableUpDownCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64ObservableUpDownCounterOption) EXPECT() *MockInt64ObservableUpDownCounterOption_Expecter { 20 | return &MockInt64ObservableUpDownCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyInt64ObservableUpDownCounter provides a mock function with given fields: _a0 24 | func (_m *MockInt64ObservableUpDownCounterOption) applyInt64ObservableUpDownCounter(_a0 metric.Int64ObservableUpDownCounterConfig) metric.Int64ObservableUpDownCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyInt64ObservableUpDownCounter") 29 | } 30 | 31 | var r0 metric.Int64ObservableUpDownCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Int64ObservableUpDownCounterConfig) metric.Int64ObservableUpDownCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Int64ObservableUpDownCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyInt64ObservableUpDownCounter' 42 | type MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyInt64ObservableUpDownCounter is a helper method to define mock.On call 47 | // - _a0 metric.Int64ObservableUpDownCounterConfig 48 | func (_e *MockInt64ObservableUpDownCounterOption_Expecter) applyInt64ObservableUpDownCounter(_a0 interface{}) *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call { 49 | return &MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call{Call: _e.mock.On("applyInt64ObservableUpDownCounter", _a0)} 50 | } 51 | 52 | func (_c *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call) Run(run func(_a0 metric.Int64ObservableUpDownCounterConfig)) *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Int64ObservableUpDownCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call) Return(_a0 metric.Int64ObservableUpDownCounterConfig) *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call) RunAndReturn(run func(metric.Int64ObservableUpDownCounterConfig) metric.Int64ObservableUpDownCounterConfig) *MockInt64ObservableUpDownCounterOption_applyInt64ObservableUpDownCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockInt64ObservableUpDownCounterOption creates a new instance of MockInt64ObservableUpDownCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockInt64ObservableUpDownCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockInt64ObservableUpDownCounterOption { 75 | mock := &MockInt64ObservableUpDownCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /mocks/metric/Float64ObservableUpDownCounterOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64ObservableUpDownCounterOption is an autogenerated mock type for the Float64ObservableUpDownCounterOption type 11 | type MockFloat64ObservableUpDownCounterOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64ObservableUpDownCounterOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64ObservableUpDownCounterOption) EXPECT() *MockFloat64ObservableUpDownCounterOption_Expecter { 20 | return &MockFloat64ObservableUpDownCounterOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applyFloat64ObservableUpDownCounter provides a mock function with given fields: _a0 24 | func (_m *MockFloat64ObservableUpDownCounterOption) applyFloat64ObservableUpDownCounter(_a0 metric.Float64ObservableUpDownCounterConfig) metric.Float64ObservableUpDownCounterConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applyFloat64ObservableUpDownCounter") 29 | } 30 | 31 | var r0 metric.Float64ObservableUpDownCounterConfig 32 | if rf, ok := ret.Get(0).(func(metric.Float64ObservableUpDownCounterConfig) metric.Float64ObservableUpDownCounterConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(metric.Float64ObservableUpDownCounterConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applyFloat64ObservableUpDownCounter' 42 | type MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applyFloat64ObservableUpDownCounter is a helper method to define mock.On call 47 | // - _a0 metric.Float64ObservableUpDownCounterConfig 48 | func (_e *MockFloat64ObservableUpDownCounterOption_Expecter) applyFloat64ObservableUpDownCounter(_a0 interface{}) *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call { 49 | return &MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call{Call: _e.mock.On("applyFloat64ObservableUpDownCounter", _a0)} 50 | } 51 | 52 | func (_c *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call) Run(run func(_a0 metric.Float64ObservableUpDownCounterConfig)) *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(metric.Float64ObservableUpDownCounterConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call) Return(_a0 metric.Float64ObservableUpDownCounterConfig) *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call) RunAndReturn(run func(metric.Float64ObservableUpDownCounterConfig) metric.Float64ObservableUpDownCounterConfig) *MockFloat64ObservableUpDownCounterOption_applyFloat64ObservableUpDownCounter_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // NewMockFloat64ObservableUpDownCounterOption creates a new instance of MockFloat64ObservableUpDownCounterOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 70 | // The first argument is typically a *testing.T value. 71 | func NewMockFloat64ObservableUpDownCounterOption(t interface { 72 | mock.TestingT 73 | Cleanup(func()) 74 | }) *MockFloat64ObservableUpDownCounterOption { 75 | mock := &MockFloat64ObservableUpDownCounterOption{} 76 | mock.Mock.Test(t) 77 | 78 | t.Cleanup(func() { mock.AssertExpectations(t) }) 79 | 80 | return mock 81 | } 82 | -------------------------------------------------------------------------------- /middleware_test.go: -------------------------------------------------------------------------------- 1 | package gotel_test 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "net/http/httptest" 7 | "testing" 8 | 9 | "github.com/gin-gonic/gin" 10 | "github.com/lucavallin/gotel" 11 | mockmetric "github.com/lucavallin/gotel/mocks/metric" 12 | "github.com/stretchr/testify/assert" 13 | ) 14 | 15 | func TestTelemetry_LogRequest(t *testing.T) { 16 | t.Run("logs request info", func(t *testing.T) { 17 | // Setup 18 | gin.SetMode(gin.TestMode) 19 | telemetry, _ := gotel.NewTelemetry(context.Background(), gotel.Config{ 20 | ServiceName: "test-service", 21 | ServiceVersion: "1.0.0", 22 | Enabled: true, 23 | }) 24 | defer telemetry.Shutdown(context.Background()) 25 | 26 | // Create test router with middleware 27 | r := gin.New() 28 | r.Use(telemetry.LogRequest()) 29 | r.GET("/test", func(c *gin.Context) { 30 | c.Status(http.StatusOK) 31 | }) 32 | 33 | // Create and execute request 34 | w := httptest.NewRecorder() 35 | req := httptest.NewRequest(http.MethodGet, "/test", nil) 36 | r.ServeHTTP(w, req) 37 | 38 | assert.Equal(t, http.StatusOK, w.Code) 39 | }) 40 | } 41 | 42 | func TestTelemetry_MeterRequestDuration(t *testing.T) { 43 | t.Run("records request duration", func(t *testing.T) { 44 | // Setup 45 | gin.SetMode(gin.TestMode) 46 | mockHist := mockmetric.NewMockInt64Histogram(t) 47 | telemetry, _ := gotel.NewTelemetry(context.Background(), gotel.Config{ 48 | ServiceName: "test-service", 49 | ServiceVersion: "1.0.0", 50 | Enabled: true, 51 | }) 52 | defer telemetry.Shutdown(context.Background()) 53 | 54 | // Create test router with middleware 55 | r := gin.New() 56 | r.Use(telemetry.MeterRequestDuration()) 57 | r.GET("/test", func(c *gin.Context) { 58 | c.Status(http.StatusOK) 59 | }) 60 | 61 | // Create and execute request 62 | w := httptest.NewRecorder() 63 | req := httptest.NewRequest(http.MethodGet, "/test", nil) 64 | r.ServeHTTP(w, req) 65 | 66 | assert.Equal(t, http.StatusOK, w.Code) 67 | mockHist.AssertExpectations(t) 68 | }) 69 | } 70 | 71 | func TestTelemetry_MeterRequestsInFlight(t *testing.T) { 72 | t.Run("tracks concurrent requests", func(t *testing.T) { 73 | // Setup 74 | gin.SetMode(gin.TestMode) 75 | mockCount := mockmetric.NewMockFloat64UpDownCounter(t) 76 | telemetry, _ := gotel.NewTelemetry(context.Background(), gotel.Config{ 77 | ServiceName: "test-service", 78 | ServiceVersion: "1.0.0", 79 | Enabled: true, 80 | }) 81 | defer telemetry.Shutdown(context.Background()) 82 | 83 | // Create test router with middleware 84 | r := gin.New() 85 | r.Use(telemetry.MeterRequestsInFlight()) 86 | r.GET("/test", func(c *gin.Context) { 87 | c.Status(http.StatusOK) 88 | }) 89 | 90 | // Create and execute request 91 | w := httptest.NewRecorder() 92 | req := httptest.NewRequest(http.MethodGet, "/test", nil) 93 | r.ServeHTTP(w, req) 94 | 95 | assert.Equal(t, http.StatusOK, w.Code) 96 | mockCount.AssertExpectations(t) 97 | }) 98 | 99 | t.Run("handles multiple concurrent requests", func(t *testing.T) { 100 | // Setup 101 | gin.SetMode(gin.TestMode) 102 | mockCount := mockmetric.NewMockFloat64UpDownCounter(t) 103 | telemetry, _ := gotel.NewTelemetry(context.Background(), gotel.Config{ 104 | ServiceName: "test-service", 105 | ServiceVersion: "1.0.0", 106 | Enabled: true, 107 | }) 108 | defer telemetry.Shutdown(context.Background()) 109 | 110 | // Create test router with middleware 111 | r := gin.New() 112 | r.Use(telemetry.MeterRequestsInFlight()) 113 | r.GET("/test", func(c *gin.Context) { 114 | c.Status(http.StatusOK) 115 | }) 116 | 117 | // Execute two concurrent requests 118 | for range [2]int{} { 119 | w := httptest.NewRecorder() 120 | req := httptest.NewRequest(http.MethodGet, "/test", nil) 121 | r.ServeHTTP(w, req) 122 | assert.Equal(t, http.StatusOK, w.Code) 123 | } 124 | 125 | mockCount.AssertExpectations(t) 126 | }) 127 | } 128 | -------------------------------------------------------------------------------- /mocks/metric/Int64Gauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockInt64Gauge is an autogenerated mock type for the Int64Gauge type 13 | type MockInt64Gauge struct { 14 | mock.Mock 15 | } 16 | 17 | type MockInt64Gauge_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockInt64Gauge) EXPECT() *MockInt64Gauge_Expecter { 22 | return &MockInt64Gauge_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Record provides a mock function with given fields: ctx, value, options 26 | func (_m *MockInt64Gauge) Record(ctx context.Context, value int64, options ...metric.RecordOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, value) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockInt64Gauge_Record_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Record' 38 | type MockInt64Gauge_Record_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Record is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - value int64 45 | // - options ...metric.RecordOption 46 | func (_e *MockInt64Gauge_Expecter) Record(ctx interface{}, value interface{}, options ...interface{}) *MockInt64Gauge_Record_Call { 47 | return &MockInt64Gauge_Record_Call{Call: _e.mock.On("Record", 48 | append([]interface{}{ctx, value}, options...)...)} 49 | } 50 | 51 | func (_c *MockInt64Gauge_Record_Call) Run(run func(ctx context.Context, value int64, options ...metric.RecordOption)) *MockInt64Gauge_Record_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.RecordOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.RecordOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(int64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64Gauge_Record_Call) Return() *MockInt64Gauge_Record_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockInt64Gauge_Record_Call) RunAndReturn(run func(context.Context, int64, ...metric.RecordOption)) *MockInt64Gauge_Record_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // int64Gauge provides a mock function with no fields 75 | func (_m *MockInt64Gauge) int64Gauge() { 76 | _m.Called() 77 | } 78 | 79 | // MockInt64Gauge_int64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Gauge' 80 | type MockInt64Gauge_int64Gauge_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // int64Gauge is a helper method to define mock.On call 85 | func (_e *MockInt64Gauge_Expecter) int64Gauge() *MockInt64Gauge_int64Gauge_Call { 86 | return &MockInt64Gauge_int64Gauge_Call{Call: _e.mock.On("int64Gauge")} 87 | } 88 | 89 | func (_c *MockInt64Gauge_int64Gauge_Call) Run(run func()) *MockInt64Gauge_int64Gauge_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockInt64Gauge_int64Gauge_Call) Return() *MockInt64Gauge_int64Gauge_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockInt64Gauge_int64Gauge_Call) RunAndReturn(run func()) *MockInt64Gauge_int64Gauge_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockInt64Gauge creates a new instance of MockInt64Gauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockInt64Gauge(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockInt64Gauge { 112 | mock := &MockInt64Gauge{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /mocks/metric/Int64Observer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockInt64Observer is an autogenerated mock type for the Int64Observer type 11 | type MockInt64Observer struct { 12 | mock.Mock 13 | } 14 | 15 | type MockInt64Observer_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockInt64Observer) EXPECT() *MockInt64Observer_Expecter { 20 | return &MockInt64Observer_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // Observe provides a mock function with given fields: value, options 24 | func (_m *MockInt64Observer) Observe(value int64, options ...metric.ObserveOption) { 25 | _va := make([]interface{}, len(options)) 26 | for _i := range options { 27 | _va[_i] = options[_i] 28 | } 29 | var _ca []interface{} 30 | _ca = append(_ca, value) 31 | _ca = append(_ca, _va...) 32 | _m.Called(_ca...) 33 | } 34 | 35 | // MockInt64Observer_Observe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Observe' 36 | type MockInt64Observer_Observe_Call struct { 37 | *mock.Call 38 | } 39 | 40 | // Observe is a helper method to define mock.On call 41 | // - value int64 42 | // - options ...metric.ObserveOption 43 | func (_e *MockInt64Observer_Expecter) Observe(value interface{}, options ...interface{}) *MockInt64Observer_Observe_Call { 44 | return &MockInt64Observer_Observe_Call{Call: _e.mock.On("Observe", 45 | append([]interface{}{value}, options...)...)} 46 | } 47 | 48 | func (_c *MockInt64Observer_Observe_Call) Run(run func(value int64, options ...metric.ObserveOption)) *MockInt64Observer_Observe_Call { 49 | _c.Call.Run(func(args mock.Arguments) { 50 | variadicArgs := make([]metric.ObserveOption, len(args)-1) 51 | for i, a := range args[1:] { 52 | if a != nil { 53 | variadicArgs[i] = a.(metric.ObserveOption) 54 | } 55 | } 56 | run(args[0].(int64), variadicArgs...) 57 | }) 58 | return _c 59 | } 60 | 61 | func (_c *MockInt64Observer_Observe_Call) Return() *MockInt64Observer_Observe_Call { 62 | _c.Call.Return() 63 | return _c 64 | } 65 | 66 | func (_c *MockInt64Observer_Observe_Call) RunAndReturn(run func(int64, ...metric.ObserveOption)) *MockInt64Observer_Observe_Call { 67 | _c.Run(run) 68 | return _c 69 | } 70 | 71 | // int64Observer provides a mock function with no fields 72 | func (_m *MockInt64Observer) int64Observer() { 73 | _m.Called() 74 | } 75 | 76 | // MockInt64Observer_int64Observer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Observer' 77 | type MockInt64Observer_int64Observer_Call struct { 78 | *mock.Call 79 | } 80 | 81 | // int64Observer is a helper method to define mock.On call 82 | func (_e *MockInt64Observer_Expecter) int64Observer() *MockInt64Observer_int64Observer_Call { 83 | return &MockInt64Observer_int64Observer_Call{Call: _e.mock.On("int64Observer")} 84 | } 85 | 86 | func (_c *MockInt64Observer_int64Observer_Call) Run(run func()) *MockInt64Observer_int64Observer_Call { 87 | _c.Call.Run(func(args mock.Arguments) { 88 | run() 89 | }) 90 | return _c 91 | } 92 | 93 | func (_c *MockInt64Observer_int64Observer_Call) Return() *MockInt64Observer_int64Observer_Call { 94 | _c.Call.Return() 95 | return _c 96 | } 97 | 98 | func (_c *MockInt64Observer_int64Observer_Call) RunAndReturn(run func()) *MockInt64Observer_int64Observer_Call { 99 | _c.Run(run) 100 | return _c 101 | } 102 | 103 | // NewMockInt64Observer creates a new instance of MockInt64Observer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 104 | // The first argument is typically a *testing.T value. 105 | func NewMockInt64Observer(t interface { 106 | mock.TestingT 107 | Cleanup(func()) 108 | }) *MockInt64Observer { 109 | mock := &MockInt64Observer{} 110 | mock.Mock.Test(t) 111 | 112 | t.Cleanup(func() { mock.AssertExpectations(t) }) 113 | 114 | return mock 115 | } 116 | -------------------------------------------------------------------------------- /mocks/metric/Int64Counter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockInt64Counter is an autogenerated mock type for the Int64Counter type 13 | type MockInt64Counter struct { 14 | mock.Mock 15 | } 16 | 17 | type MockInt64Counter_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockInt64Counter) EXPECT() *MockInt64Counter_Expecter { 22 | return &MockInt64Counter_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Add provides a mock function with given fields: ctx, incr, options 26 | func (_m *MockInt64Counter) Add(ctx context.Context, incr int64, options ...metric.AddOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, incr) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockInt64Counter_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' 38 | type MockInt64Counter_Add_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Add is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - incr int64 45 | // - options ...metric.AddOption 46 | func (_e *MockInt64Counter_Expecter) Add(ctx interface{}, incr interface{}, options ...interface{}) *MockInt64Counter_Add_Call { 47 | return &MockInt64Counter_Add_Call{Call: _e.mock.On("Add", 48 | append([]interface{}{ctx, incr}, options...)...)} 49 | } 50 | 51 | func (_c *MockInt64Counter_Add_Call) Run(run func(ctx context.Context, incr int64, options ...metric.AddOption)) *MockInt64Counter_Add_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.AddOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.AddOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(int64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64Counter_Add_Call) Return() *MockInt64Counter_Add_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockInt64Counter_Add_Call) RunAndReturn(run func(context.Context, int64, ...metric.AddOption)) *MockInt64Counter_Add_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // int64Counter provides a mock function with no fields 75 | func (_m *MockInt64Counter) int64Counter() { 76 | _m.Called() 77 | } 78 | 79 | // MockInt64Counter_int64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Counter' 80 | type MockInt64Counter_int64Counter_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // int64Counter is a helper method to define mock.On call 85 | func (_e *MockInt64Counter_Expecter) int64Counter() *MockInt64Counter_int64Counter_Call { 86 | return &MockInt64Counter_int64Counter_Call{Call: _e.mock.On("int64Counter")} 87 | } 88 | 89 | func (_c *MockInt64Counter_int64Counter_Call) Run(run func()) *MockInt64Counter_int64Counter_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockInt64Counter_int64Counter_Call) Return() *MockInt64Counter_int64Counter_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockInt64Counter_int64Counter_Call) RunAndReturn(run func()) *MockInt64Counter_int64Counter_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockInt64Counter creates a new instance of MockInt64Counter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockInt64Counter(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockInt64Counter { 112 | mock := &MockInt64Counter{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /mocks/metric/Float64Observer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | metric "go.opentelemetry.io/otel/metric" 8 | ) 9 | 10 | // MockFloat64Observer is an autogenerated mock type for the Float64Observer type 11 | type MockFloat64Observer struct { 12 | mock.Mock 13 | } 14 | 15 | type MockFloat64Observer_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockFloat64Observer) EXPECT() *MockFloat64Observer_Expecter { 20 | return &MockFloat64Observer_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // Observe provides a mock function with given fields: value, options 24 | func (_m *MockFloat64Observer) Observe(value float64, options ...metric.ObserveOption) { 25 | _va := make([]interface{}, len(options)) 26 | for _i := range options { 27 | _va[_i] = options[_i] 28 | } 29 | var _ca []interface{} 30 | _ca = append(_ca, value) 31 | _ca = append(_ca, _va...) 32 | _m.Called(_ca...) 33 | } 34 | 35 | // MockFloat64Observer_Observe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Observe' 36 | type MockFloat64Observer_Observe_Call struct { 37 | *mock.Call 38 | } 39 | 40 | // Observe is a helper method to define mock.On call 41 | // - value float64 42 | // - options ...metric.ObserveOption 43 | func (_e *MockFloat64Observer_Expecter) Observe(value interface{}, options ...interface{}) *MockFloat64Observer_Observe_Call { 44 | return &MockFloat64Observer_Observe_Call{Call: _e.mock.On("Observe", 45 | append([]interface{}{value}, options...)...)} 46 | } 47 | 48 | func (_c *MockFloat64Observer_Observe_Call) Run(run func(value float64, options ...metric.ObserveOption)) *MockFloat64Observer_Observe_Call { 49 | _c.Call.Run(func(args mock.Arguments) { 50 | variadicArgs := make([]metric.ObserveOption, len(args)-1) 51 | for i, a := range args[1:] { 52 | if a != nil { 53 | variadicArgs[i] = a.(metric.ObserveOption) 54 | } 55 | } 56 | run(args[0].(float64), variadicArgs...) 57 | }) 58 | return _c 59 | } 60 | 61 | func (_c *MockFloat64Observer_Observe_Call) Return() *MockFloat64Observer_Observe_Call { 62 | _c.Call.Return() 63 | return _c 64 | } 65 | 66 | func (_c *MockFloat64Observer_Observe_Call) RunAndReturn(run func(float64, ...metric.ObserveOption)) *MockFloat64Observer_Observe_Call { 67 | _c.Run(run) 68 | return _c 69 | } 70 | 71 | // float64Observer provides a mock function with no fields 72 | func (_m *MockFloat64Observer) float64Observer() { 73 | _m.Called() 74 | } 75 | 76 | // MockFloat64Observer_float64Observer_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Observer' 77 | type MockFloat64Observer_float64Observer_Call struct { 78 | *mock.Call 79 | } 80 | 81 | // float64Observer is a helper method to define mock.On call 82 | func (_e *MockFloat64Observer_Expecter) float64Observer() *MockFloat64Observer_float64Observer_Call { 83 | return &MockFloat64Observer_float64Observer_Call{Call: _e.mock.On("float64Observer")} 84 | } 85 | 86 | func (_c *MockFloat64Observer_float64Observer_Call) Run(run func()) *MockFloat64Observer_float64Observer_Call { 87 | _c.Call.Run(func(args mock.Arguments) { 88 | run() 89 | }) 90 | return _c 91 | } 92 | 93 | func (_c *MockFloat64Observer_float64Observer_Call) Return() *MockFloat64Observer_float64Observer_Call { 94 | _c.Call.Return() 95 | return _c 96 | } 97 | 98 | func (_c *MockFloat64Observer_float64Observer_Call) RunAndReturn(run func()) *MockFloat64Observer_float64Observer_Call { 99 | _c.Run(run) 100 | return _c 101 | } 102 | 103 | // NewMockFloat64Observer creates a new instance of MockFloat64Observer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 104 | // The first argument is typically a *testing.T value. 105 | func NewMockFloat64Observer(t interface { 106 | mock.TestingT 107 | Cleanup(func()) 108 | }) *MockFloat64Observer { 109 | mock := &MockFloat64Observer{} 110 | mock.Mock.Test(t) 111 | 112 | t.Cleanup(func() { mock.AssertExpectations(t) }) 113 | 114 | return mock 115 | } 116 | -------------------------------------------------------------------------------- /mocks/metric/Float64Gauge.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockFloat64Gauge is an autogenerated mock type for the Float64Gauge type 13 | type MockFloat64Gauge struct { 14 | mock.Mock 15 | } 16 | 17 | type MockFloat64Gauge_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockFloat64Gauge) EXPECT() *MockFloat64Gauge_Expecter { 22 | return &MockFloat64Gauge_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Record provides a mock function with given fields: ctx, value, options 26 | func (_m *MockFloat64Gauge) Record(ctx context.Context, value float64, options ...metric.RecordOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, value) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockFloat64Gauge_Record_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Record' 38 | type MockFloat64Gauge_Record_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Record is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - value float64 45 | // - options ...metric.RecordOption 46 | func (_e *MockFloat64Gauge_Expecter) Record(ctx interface{}, value interface{}, options ...interface{}) *MockFloat64Gauge_Record_Call { 47 | return &MockFloat64Gauge_Record_Call{Call: _e.mock.On("Record", 48 | append([]interface{}{ctx, value}, options...)...)} 49 | } 50 | 51 | func (_c *MockFloat64Gauge_Record_Call) Run(run func(ctx context.Context, value float64, options ...metric.RecordOption)) *MockFloat64Gauge_Record_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.RecordOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.RecordOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(float64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64Gauge_Record_Call) Return() *MockFloat64Gauge_Record_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockFloat64Gauge_Record_Call) RunAndReturn(run func(context.Context, float64, ...metric.RecordOption)) *MockFloat64Gauge_Record_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // float64Gauge provides a mock function with no fields 75 | func (_m *MockFloat64Gauge) float64Gauge() { 76 | _m.Called() 77 | } 78 | 79 | // MockFloat64Gauge_float64Gauge_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Gauge' 80 | type MockFloat64Gauge_float64Gauge_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // float64Gauge is a helper method to define mock.On call 85 | func (_e *MockFloat64Gauge_Expecter) float64Gauge() *MockFloat64Gauge_float64Gauge_Call { 86 | return &MockFloat64Gauge_float64Gauge_Call{Call: _e.mock.On("float64Gauge")} 87 | } 88 | 89 | func (_c *MockFloat64Gauge_float64Gauge_Call) Run(run func()) *MockFloat64Gauge_float64Gauge_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockFloat64Gauge_float64Gauge_Call) Return() *MockFloat64Gauge_float64Gauge_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockFloat64Gauge_float64Gauge_Call) RunAndReturn(run func()) *MockFloat64Gauge_float64Gauge_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockFloat64Gauge creates a new instance of MockFloat64Gauge. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockFloat64Gauge(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockFloat64Gauge { 112 | mock := &MockFloat64Gauge{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /mocks/metric/Float64Counter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockFloat64Counter is an autogenerated mock type for the Float64Counter type 13 | type MockFloat64Counter struct { 14 | mock.Mock 15 | } 16 | 17 | type MockFloat64Counter_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockFloat64Counter) EXPECT() *MockFloat64Counter_Expecter { 22 | return &MockFloat64Counter_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Add provides a mock function with given fields: ctx, incr, options 26 | func (_m *MockFloat64Counter) Add(ctx context.Context, incr float64, options ...metric.AddOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, incr) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockFloat64Counter_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' 38 | type MockFloat64Counter_Add_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Add is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - incr float64 45 | // - options ...metric.AddOption 46 | func (_e *MockFloat64Counter_Expecter) Add(ctx interface{}, incr interface{}, options ...interface{}) *MockFloat64Counter_Add_Call { 47 | return &MockFloat64Counter_Add_Call{Call: _e.mock.On("Add", 48 | append([]interface{}{ctx, incr}, options...)...)} 49 | } 50 | 51 | func (_c *MockFloat64Counter_Add_Call) Run(run func(ctx context.Context, incr float64, options ...metric.AddOption)) *MockFloat64Counter_Add_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.AddOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.AddOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(float64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64Counter_Add_Call) Return() *MockFloat64Counter_Add_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockFloat64Counter_Add_Call) RunAndReturn(run func(context.Context, float64, ...metric.AddOption)) *MockFloat64Counter_Add_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // float64Counter provides a mock function with no fields 75 | func (_m *MockFloat64Counter) float64Counter() { 76 | _m.Called() 77 | } 78 | 79 | // MockFloat64Counter_float64Counter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Counter' 80 | type MockFloat64Counter_float64Counter_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // float64Counter is a helper method to define mock.On call 85 | func (_e *MockFloat64Counter_Expecter) float64Counter() *MockFloat64Counter_float64Counter_Call { 86 | return &MockFloat64Counter_float64Counter_Call{Call: _e.mock.On("float64Counter")} 87 | } 88 | 89 | func (_c *MockFloat64Counter_float64Counter_Call) Run(run func()) *MockFloat64Counter_float64Counter_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockFloat64Counter_float64Counter_Call) Return() *MockFloat64Counter_float64Counter_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockFloat64Counter_float64Counter_Call) RunAndReturn(run func()) *MockFloat64Counter_float64Counter_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockFloat64Counter creates a new instance of MockFloat64Counter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockFloat64Counter(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockFloat64Counter { 112 | mock := &MockFloat64Counter{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /gotel_test.go: -------------------------------------------------------------------------------- 1 | package gotel_test 2 | 3 | import ( 4 | "context" 5 | "testing" 6 | 7 | "github.com/lucavallin/gotel" 8 | "github.com/stretchr/testify/assert" 9 | "github.com/stretchr/testify/require" 10 | ) 11 | 12 | func TestNewTelemetry(t *testing.T) { 13 | tests := []struct { 14 | name string 15 | cfg gotel.Config 16 | wantErr bool 17 | }{ 18 | { 19 | name: "success with telemetry enabled", 20 | cfg: gotel.Config{ 21 | ServiceName: "test-service", 22 | ServiceVersion: "1.0.0", 23 | Enabled: true, 24 | }, 25 | wantErr: false, 26 | }, 27 | } 28 | 29 | for _, tt := range tests { 30 | t.Run(tt.name, func(t *testing.T) { 31 | ctx := context.Background() 32 | telem, err := gotel.NewTelemetry(ctx, tt.cfg) 33 | if tt.wantErr { 34 | require.Error(t, err) 35 | assert.Nil(t, telem) 36 | 37 | return 38 | } 39 | 40 | require.NoError(t, err) 41 | assert.NotNil(t, telem) 42 | 43 | // Basic functionality test 44 | assert.Equal(t, tt.cfg.ServiceName, telem.GetServiceName()) 45 | 46 | // Test metrics creation 47 | histogram, err := telem.MeterInt64Histogram(gotel.MetricRequestDurationMillis) 48 | if tt.cfg.Enabled { 49 | require.NoError(t, err) 50 | assert.NotNil(t, histogram) 51 | } else { 52 | assert.Nil(t, histogram) 53 | } 54 | 55 | counter, err := telem.MeterInt64UpDownCounter(gotel.MetricRequestsInFlight) 56 | if tt.cfg.Enabled { 57 | require.NoError(t, err) 58 | assert.NotNil(t, counter) 59 | } else { 60 | assert.Nil(t, counter) 61 | } 62 | 63 | // Clean up 64 | telem.Shutdown(ctx) 65 | }) 66 | } 67 | } 68 | 69 | func TestTelemetry_MeterInt64Histogram(t *testing.T) { 70 | ctx := context.Background() 71 | telem, err := gotel.NewTelemetry(ctx, gotel.Config{ 72 | ServiceName: "test-service", 73 | ServiceVersion: "1.0.0", 74 | Enabled: true, 75 | }) 76 | require.NoError(t, err) 77 | defer telem.Shutdown(ctx) 78 | 79 | tests := []struct { 80 | name string 81 | metric gotel.Metric 82 | wantErr bool 83 | }{ 84 | { 85 | name: "success with valid metric", 86 | metric: gotel.Metric{ 87 | Name: "test_histogram", 88 | Unit: "ms", 89 | Description: "Test histogram", 90 | }, 91 | wantErr: false, 92 | }, 93 | } 94 | 95 | for _, tt := range tests { 96 | t.Run(tt.name, func(t *testing.T) { 97 | histogram, err := telem.MeterInt64Histogram(tt.metric) 98 | if tt.wantErr { 99 | require.Error(t, err) 100 | assert.Nil(t, histogram) 101 | 102 | return 103 | } 104 | 105 | require.NoError(t, err) 106 | assert.NotNil(t, histogram) 107 | }) 108 | } 109 | } 110 | 111 | func TestTelemetry_MeterInt64UpDownCounter(t *testing.T) { 112 | ctx := context.Background() 113 | telem, err := gotel.NewTelemetry(ctx, gotel.Config{ 114 | ServiceName: "test-service", 115 | ServiceVersion: "1.0.0", 116 | }) 117 | require.NoError(t, err) 118 | defer telem.Shutdown(ctx) 119 | 120 | tests := []struct { 121 | name string 122 | metric gotel.Metric 123 | wantErr bool 124 | }{ 125 | { 126 | name: "success with valid metric", 127 | metric: gotel.Metric{ 128 | Name: "test_counter", 129 | Unit: "1", 130 | Description: "Test counter", 131 | }, 132 | wantErr: false, 133 | }, 134 | } 135 | 136 | for _, tt := range tests { 137 | t.Run(tt.name, func(t *testing.T) { 138 | counter, err := telem.MeterInt64UpDownCounter(tt.metric) 139 | if tt.wantErr { 140 | require.Error(t, err) 141 | assert.Nil(t, counter) 142 | 143 | return 144 | } 145 | 146 | require.NoError(t, err) 147 | assert.NotNil(t, counter) 148 | }) 149 | } 150 | } 151 | 152 | func TestTelemetry_TraceStart(t *testing.T) { 153 | ctx := context.Background() 154 | telem, err := gotel.NewTelemetry(ctx, gotel.Config{ 155 | ServiceName: "test-service", 156 | ServiceVersion: "1.0.0", 157 | Enabled: true, 158 | }) 159 | require.NoError(t, err) 160 | defer telem.Shutdown(ctx) 161 | 162 | newCtx, span := telem.TraceStart(ctx, "test-span") 163 | assert.NotNil(t, newCtx) 164 | assert.NotNil(t, span) 165 | span.End() 166 | } 167 | -------------------------------------------------------------------------------- /mocks/metric/Int64Histogram.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockInt64Histogram is an autogenerated mock type for the Int64Histogram type 13 | type MockInt64Histogram struct { 14 | mock.Mock 15 | } 16 | 17 | type MockInt64Histogram_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockInt64Histogram) EXPECT() *MockInt64Histogram_Expecter { 22 | return &MockInt64Histogram_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Record provides a mock function with given fields: ctx, incr, options 26 | func (_m *MockInt64Histogram) Record(ctx context.Context, incr int64, options ...metric.RecordOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, incr) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockInt64Histogram_Record_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Record' 38 | type MockInt64Histogram_Record_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Record is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - incr int64 45 | // - options ...metric.RecordOption 46 | func (_e *MockInt64Histogram_Expecter) Record(ctx interface{}, incr interface{}, options ...interface{}) *MockInt64Histogram_Record_Call { 47 | return &MockInt64Histogram_Record_Call{Call: _e.mock.On("Record", 48 | append([]interface{}{ctx, incr}, options...)...)} 49 | } 50 | 51 | func (_c *MockInt64Histogram_Record_Call) Run(run func(ctx context.Context, incr int64, options ...metric.RecordOption)) *MockInt64Histogram_Record_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.RecordOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.RecordOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(int64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64Histogram_Record_Call) Return() *MockInt64Histogram_Record_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockInt64Histogram_Record_Call) RunAndReturn(run func(context.Context, int64, ...metric.RecordOption)) *MockInt64Histogram_Record_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // int64Histogram provides a mock function with no fields 75 | func (_m *MockInt64Histogram) int64Histogram() { 76 | _m.Called() 77 | } 78 | 79 | // MockInt64Histogram_int64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64Histogram' 80 | type MockInt64Histogram_int64Histogram_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // int64Histogram is a helper method to define mock.On call 85 | func (_e *MockInt64Histogram_Expecter) int64Histogram() *MockInt64Histogram_int64Histogram_Call { 86 | return &MockInt64Histogram_int64Histogram_Call{Call: _e.mock.On("int64Histogram")} 87 | } 88 | 89 | func (_c *MockInt64Histogram_int64Histogram_Call) Run(run func()) *MockInt64Histogram_int64Histogram_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockInt64Histogram_int64Histogram_Call) Return() *MockInt64Histogram_int64Histogram_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockInt64Histogram_int64Histogram_Call) RunAndReturn(run func()) *MockInt64Histogram_int64Histogram_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockInt64Histogram creates a new instance of MockInt64Histogram. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockInt64Histogram(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockInt64Histogram { 112 | mock := &MockInt64Histogram{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /mocks/metric/Float64Histogram.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockFloat64Histogram is an autogenerated mock type for the Float64Histogram type 13 | type MockFloat64Histogram struct { 14 | mock.Mock 15 | } 16 | 17 | type MockFloat64Histogram_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockFloat64Histogram) EXPECT() *MockFloat64Histogram_Expecter { 22 | return &MockFloat64Histogram_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Record provides a mock function with given fields: ctx, incr, options 26 | func (_m *MockFloat64Histogram) Record(ctx context.Context, incr float64, options ...metric.RecordOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, incr) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockFloat64Histogram_Record_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Record' 38 | type MockFloat64Histogram_Record_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Record is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - incr float64 45 | // - options ...metric.RecordOption 46 | func (_e *MockFloat64Histogram_Expecter) Record(ctx interface{}, incr interface{}, options ...interface{}) *MockFloat64Histogram_Record_Call { 47 | return &MockFloat64Histogram_Record_Call{Call: _e.mock.On("Record", 48 | append([]interface{}{ctx, incr}, options...)...)} 49 | } 50 | 51 | func (_c *MockFloat64Histogram_Record_Call) Run(run func(ctx context.Context, incr float64, options ...metric.RecordOption)) *MockFloat64Histogram_Record_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.RecordOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.RecordOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(float64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockFloat64Histogram_Record_Call) Return() *MockFloat64Histogram_Record_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockFloat64Histogram_Record_Call) RunAndReturn(run func(context.Context, float64, ...metric.RecordOption)) *MockFloat64Histogram_Record_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // float64Histogram provides a mock function with no fields 75 | func (_m *MockFloat64Histogram) float64Histogram() { 76 | _m.Called() 77 | } 78 | 79 | // MockFloat64Histogram_float64Histogram_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'float64Histogram' 80 | type MockFloat64Histogram_float64Histogram_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // float64Histogram is a helper method to define mock.On call 85 | func (_e *MockFloat64Histogram_Expecter) float64Histogram() *MockFloat64Histogram_float64Histogram_Call { 86 | return &MockFloat64Histogram_float64Histogram_Call{Call: _e.mock.On("float64Histogram")} 87 | } 88 | 89 | func (_c *MockFloat64Histogram_float64Histogram_Call) Run(run func()) *MockFloat64Histogram_float64Histogram_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockFloat64Histogram_float64Histogram_Call) Return() *MockFloat64Histogram_float64Histogram_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockFloat64Histogram_float64Histogram_Call) RunAndReturn(run func()) *MockFloat64Histogram_float64Histogram_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockFloat64Histogram creates a new instance of MockFloat64Histogram. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockFloat64Histogram(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockFloat64Histogram { 112 | mock := &MockFloat64Histogram{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | -------------------------------------------------------------------------------- /mocks/trace/SpanOption.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package trace 4 | 5 | import ( 6 | mock "github.com/stretchr/testify/mock" 7 | trace "go.opentelemetry.io/otel/trace" 8 | ) 9 | 10 | // MockSpanOption is an autogenerated mock type for the SpanOption type 11 | type MockSpanOption struct { 12 | mock.Mock 13 | } 14 | 15 | type MockSpanOption_Expecter struct { 16 | mock *mock.Mock 17 | } 18 | 19 | func (_m *MockSpanOption) EXPECT() *MockSpanOption_Expecter { 20 | return &MockSpanOption_Expecter{mock: &_m.Mock} 21 | } 22 | 23 | // applySpanEnd provides a mock function with given fields: _a0 24 | func (_m *MockSpanOption) applySpanEnd(_a0 trace.SpanConfig) trace.SpanConfig { 25 | ret := _m.Called(_a0) 26 | 27 | if len(ret) == 0 { 28 | panic("no return value specified for applySpanEnd") 29 | } 30 | 31 | var r0 trace.SpanConfig 32 | if rf, ok := ret.Get(0).(func(trace.SpanConfig) trace.SpanConfig); ok { 33 | r0 = rf(_a0) 34 | } else { 35 | r0 = ret.Get(0).(trace.SpanConfig) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // MockSpanOption_applySpanEnd_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applySpanEnd' 42 | type MockSpanOption_applySpanEnd_Call struct { 43 | *mock.Call 44 | } 45 | 46 | // applySpanEnd is a helper method to define mock.On call 47 | // - _a0 trace.SpanConfig 48 | func (_e *MockSpanOption_Expecter) applySpanEnd(_a0 interface{}) *MockSpanOption_applySpanEnd_Call { 49 | return &MockSpanOption_applySpanEnd_Call{Call: _e.mock.On("applySpanEnd", _a0)} 50 | } 51 | 52 | func (_c *MockSpanOption_applySpanEnd_Call) Run(run func(_a0 trace.SpanConfig)) *MockSpanOption_applySpanEnd_Call { 53 | _c.Call.Run(func(args mock.Arguments) { 54 | run(args[0].(trace.SpanConfig)) 55 | }) 56 | return _c 57 | } 58 | 59 | func (_c *MockSpanOption_applySpanEnd_Call) Return(_a0 trace.SpanConfig) *MockSpanOption_applySpanEnd_Call { 60 | _c.Call.Return(_a0) 61 | return _c 62 | } 63 | 64 | func (_c *MockSpanOption_applySpanEnd_Call) RunAndReturn(run func(trace.SpanConfig) trace.SpanConfig) *MockSpanOption_applySpanEnd_Call { 65 | _c.Call.Return(run) 66 | return _c 67 | } 68 | 69 | // applySpanStart provides a mock function with given fields: _a0 70 | func (_m *MockSpanOption) applySpanStart(_a0 trace.SpanConfig) trace.SpanConfig { 71 | ret := _m.Called(_a0) 72 | 73 | if len(ret) == 0 { 74 | panic("no return value specified for applySpanStart") 75 | } 76 | 77 | var r0 trace.SpanConfig 78 | if rf, ok := ret.Get(0).(func(trace.SpanConfig) trace.SpanConfig); ok { 79 | r0 = rf(_a0) 80 | } else { 81 | r0 = ret.Get(0).(trace.SpanConfig) 82 | } 83 | 84 | return r0 85 | } 86 | 87 | // MockSpanOption_applySpanStart_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'applySpanStart' 88 | type MockSpanOption_applySpanStart_Call struct { 89 | *mock.Call 90 | } 91 | 92 | // applySpanStart is a helper method to define mock.On call 93 | // - _a0 trace.SpanConfig 94 | func (_e *MockSpanOption_Expecter) applySpanStart(_a0 interface{}) *MockSpanOption_applySpanStart_Call { 95 | return &MockSpanOption_applySpanStart_Call{Call: _e.mock.On("applySpanStart", _a0)} 96 | } 97 | 98 | func (_c *MockSpanOption_applySpanStart_Call) Run(run func(_a0 trace.SpanConfig)) *MockSpanOption_applySpanStart_Call { 99 | _c.Call.Run(func(args mock.Arguments) { 100 | run(args[0].(trace.SpanConfig)) 101 | }) 102 | return _c 103 | } 104 | 105 | func (_c *MockSpanOption_applySpanStart_Call) Return(_a0 trace.SpanConfig) *MockSpanOption_applySpanStart_Call { 106 | _c.Call.Return(_a0) 107 | return _c 108 | } 109 | 110 | func (_c *MockSpanOption_applySpanStart_Call) RunAndReturn(run func(trace.SpanConfig) trace.SpanConfig) *MockSpanOption_applySpanStart_Call { 111 | _c.Call.Return(run) 112 | return _c 113 | } 114 | 115 | // NewMockSpanOption creates a new instance of MockSpanOption. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 116 | // The first argument is typically a *testing.T value. 117 | func NewMockSpanOption(t interface { 118 | mock.TestingT 119 | Cleanup(func()) 120 | }) *MockSpanOption { 121 | mock := &MockSpanOption{} 122 | mock.Mock.Test(t) 123 | 124 | t.Cleanup(func() { mock.AssertExpectations(t) }) 125 | 126 | return mock 127 | } 128 | -------------------------------------------------------------------------------- /mocks/metric/Int64UpDownCounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v2.50.0. DO NOT EDIT. 2 | 3 | package metric 4 | 5 | import ( 6 | context "context" 7 | 8 | mock "github.com/stretchr/testify/mock" 9 | metric "go.opentelemetry.io/otel/metric" 10 | ) 11 | 12 | // MockInt64UpDownCounter is an autogenerated mock type for the Int64UpDownCounter type 13 | type MockInt64UpDownCounter struct { 14 | mock.Mock 15 | } 16 | 17 | type MockInt64UpDownCounter_Expecter struct { 18 | mock *mock.Mock 19 | } 20 | 21 | func (_m *MockInt64UpDownCounter) EXPECT() *MockInt64UpDownCounter_Expecter { 22 | return &MockInt64UpDownCounter_Expecter{mock: &_m.Mock} 23 | } 24 | 25 | // Add provides a mock function with given fields: ctx, incr, options 26 | func (_m *MockInt64UpDownCounter) Add(ctx context.Context, incr int64, options ...metric.AddOption) { 27 | _va := make([]interface{}, len(options)) 28 | for _i := range options { 29 | _va[_i] = options[_i] 30 | } 31 | var _ca []interface{} 32 | _ca = append(_ca, ctx, incr) 33 | _ca = append(_ca, _va...) 34 | _m.Called(_ca...) 35 | } 36 | 37 | // MockInt64UpDownCounter_Add_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Add' 38 | type MockInt64UpDownCounter_Add_Call struct { 39 | *mock.Call 40 | } 41 | 42 | // Add is a helper method to define mock.On call 43 | // - ctx context.Context 44 | // - incr int64 45 | // - options ...metric.AddOption 46 | func (_e *MockInt64UpDownCounter_Expecter) Add(ctx interface{}, incr interface{}, options ...interface{}) *MockInt64UpDownCounter_Add_Call { 47 | return &MockInt64UpDownCounter_Add_Call{Call: _e.mock.On("Add", 48 | append([]interface{}{ctx, incr}, options...)...)} 49 | } 50 | 51 | func (_c *MockInt64UpDownCounter_Add_Call) Run(run func(ctx context.Context, incr int64, options ...metric.AddOption)) *MockInt64UpDownCounter_Add_Call { 52 | _c.Call.Run(func(args mock.Arguments) { 53 | variadicArgs := make([]metric.AddOption, len(args)-2) 54 | for i, a := range args[2:] { 55 | if a != nil { 56 | variadicArgs[i] = a.(metric.AddOption) 57 | } 58 | } 59 | run(args[0].(context.Context), args[1].(int64), variadicArgs...) 60 | }) 61 | return _c 62 | } 63 | 64 | func (_c *MockInt64UpDownCounter_Add_Call) Return() *MockInt64UpDownCounter_Add_Call { 65 | _c.Call.Return() 66 | return _c 67 | } 68 | 69 | func (_c *MockInt64UpDownCounter_Add_Call) RunAndReturn(run func(context.Context, int64, ...metric.AddOption)) *MockInt64UpDownCounter_Add_Call { 70 | _c.Run(run) 71 | return _c 72 | } 73 | 74 | // int64UpDownCounter provides a mock function with no fields 75 | func (_m *MockInt64UpDownCounter) int64UpDownCounter() { 76 | _m.Called() 77 | } 78 | 79 | // MockInt64UpDownCounter_int64UpDownCounter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'int64UpDownCounter' 80 | type MockInt64UpDownCounter_int64UpDownCounter_Call struct { 81 | *mock.Call 82 | } 83 | 84 | // int64UpDownCounter is a helper method to define mock.On call 85 | func (_e *MockInt64UpDownCounter_Expecter) int64UpDownCounter() *MockInt64UpDownCounter_int64UpDownCounter_Call { 86 | return &MockInt64UpDownCounter_int64UpDownCounter_Call{Call: _e.mock.On("int64UpDownCounter")} 87 | } 88 | 89 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) Run(run func()) *MockInt64UpDownCounter_int64UpDownCounter_Call { 90 | _c.Call.Run(func(args mock.Arguments) { 91 | run() 92 | }) 93 | return _c 94 | } 95 | 96 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) Return() *MockInt64UpDownCounter_int64UpDownCounter_Call { 97 | _c.Call.Return() 98 | return _c 99 | } 100 | 101 | func (_c *MockInt64UpDownCounter_int64UpDownCounter_Call) RunAndReturn(run func()) *MockInt64UpDownCounter_int64UpDownCounter_Call { 102 | _c.Run(run) 103 | return _c 104 | } 105 | 106 | // NewMockInt64UpDownCounter creates a new instance of MockInt64UpDownCounter. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. 107 | // The first argument is typically a *testing.T value. 108 | func NewMockInt64UpDownCounter(t interface { 109 | mock.TestingT 110 | Cleanup(func()) 111 | }) *MockInt64UpDownCounter { 112 | mock := &MockInt64UpDownCounter{} 113 | mock.Mock.Test(t) 114 | 115 | t.Cleanup(func() { mock.AssertExpectations(t) }) 116 | 117 | return mock 118 | } 119 | --------------------------------------------------------------------------------