Debian Codegraph @

runtimevar/otel_test.go

raw
1 // Copyright 2019-2025 The Go Cloud Development Kit Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package runtimevar_test
16
17 import (
18 "context"
19 "gocloud.dev/gcerrors"
20 "gocloud.dev/internal/testing/oteltest"
21 "gocloud.dev/runtimevar"
22 "gocloud.dev/runtimevar/constantvar"
23 "testing"
24 )
25
26 const (
27 pkgName = "gocloud.dev/runtimevar"
28 driver = "gocloud.dev/runtimevar/constantvar"
29 )
30
31 func TestOpenTelemetry(t *testing.T) {
32 ctx := context.Background()
33 te := oteltest.NewTestExporter(t, runtimevar.OpenTelemetryViews)
34 defer te.Shutdown(ctx)
35
36 v := constantvar.New(1)
37 defer v.Close()
38 if _, err := v.Watch(ctx); err != nil {
39 t.Fatal(err)
40 }
41 cctx, cancel := context.WithCancel(ctx)
42 cancel()
43 _, _ = v.Watch(cctx)
44
45 // Check metrics - during migration, we may need to look for different metric names.
46 metrics := te.GetMetrics(ctx)
47
48 diff := oteltest.DiffMetrics(metrics, pkgName, driver, []oteltest.Call{
49 {Method: "", Code: gcerrors.OK},
50 })
51 if diff != "" {
52 t.Error(diff)
53 }
54 }