• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / azuredisk-csi-driver / 5612098751

20 Jul 2023 02:11PM UTC coverage: 82.363% (-0.5%) from 82.888%
5612098751

Pull #1912

github

Fricounet
fix: run go mod tidy to reorder go.mod
Pull Request #1912: Add otel trace instrumentation on gRPC calls

34 of 34 new or added lines in 3 files covered. (100.0%)

2830 of 3436 relevant lines covered (82.36%)

6.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/azuredisk/trace.go
1
/*
2
Copyright 2023 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package azuredisk
18

19
import (
20
        "context"
21
        "fmt"
22

23
        "go.opentelemetry.io/otel"
24
        "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
25
        "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
26
        "go.opentelemetry.io/otel/sdk/resource"
27
        "go.opentelemetry.io/otel/sdk/trace"
28
        "k8s.io/klog/v2"
29
)
30

31
func InitOtelTracing() (*otlptrace.Exporter, error) {
×
32
        // Setup OTLP exporter
×
33
        ctx := context.Background()
×
34
        exporter, err := otlptracegrpc.New(ctx)
×
35
        if err != nil {
×
36
                return nil, fmt.Errorf("failed to create the OTLP exporter: %w", err)
×
37
        }
×
38

39
        // Resource will auto populate spans with common attributes
40
        resource, err := resource.New(ctx,
×
41
                resource.WithFromEnv(), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables
×
42
                resource.WithProcess(),
×
43
                resource.WithOS(),
×
44
                resource.WithContainer(),
×
45
                resource.WithHost(),
×
46
        )
×
47
        if err != nil {
×
48
                klog.ErrorS(err, "Failed to create the OTLP resource, spans will lack some metadata")
×
49
        }
×
50

51
        // Create a trace provider with the exporter.
52
        // Use propagator and sampler defined in environment variables.
53
        traceProvider := trace.NewTracerProvider(trace.WithBatcher(exporter), trace.WithResource(resource))
×
54

×
55
        // Register the trace provider as global.
×
56
        otel.SetTracerProvider(traceProvider)
×
57

×
58
        return exporter, nil
×
59
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc