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

elastic / cloudbeat / 16114132341

07 Jul 2025 10:09AM UTC coverage: 76.124% (-0.07%) from 76.193%
16114132341

Pull #3430

github

orestisfl
Add mocks
Pull Request #3430: Add OpenTelemetry

147 of 205 new or added lines in 7 files covered. (71.71%)

2 existing lines in 1 file now uncovered.

9463 of 12431 relevant lines covered (76.12%)

16.58 hits per line

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

67.86
/internal/infra/observability/context.go
1
// Licensed to Elasticsearch B.V. under one or more contributor
2
// license agreements. See the NOTICE file distributed with
3
// this work for additional information regarding copyright
4
// ownership. Elasticsearch B.V. licenses this file to you under
5
// the Apache License, Version 2.0 (the "License"); you may
6
// not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17

18
package observability
19

20
import (
21
        "context"
22

23
        "go.opentelemetry.io/otel"
24
        "go.opentelemetry.io/otel/metric"
25
        "go.opentelemetry.io/otel/trace"
26
)
27

28
type contextKeyType int
29

30
const contextKey contextKeyType = iota
31

32
func otelFromContext(ctx context.Context) otelProviders {
38✔
33
        if ctx != nil {
76✔
34
                if otl, ok := ctx.Value(contextKey).(otelProviders); ok {
41✔
35
                        return otl
3✔
36
                }
3✔
37
                if span := trace.SpanFromContext(ctx); span.SpanContext().IsValid() {
35✔
NEW
38
                        return otelProviders{
×
NEW
39
                                traceProvider: tracerNoShutdown{span.TracerProvider()},
×
NEW
40
                                meterProvider: meterNoShutdown{otel.GetMeterProvider()},
×
NEW
41
                        }
×
NEW
42
                }
×
43
        }
44
        return otelProviders{
35✔
45
                traceProvider: tracerNoShutdown{otel.GetTracerProvider()},
35✔
46
                meterProvider: meterNoShutdown{otel.GetMeterProvider()},
35✔
47
        }
35✔
48
}
49

50
func contextWithOTel(ctx context.Context, otl otelProviders) context.Context {
1✔
51
        return context.WithValue(ctx, contextKey, otl)
1✔
52
}
1✔
53

54
func TracerFromContext(ctx context.Context, name string, opts ...trace.TracerOption) trace.Tracer {
26✔
55
        return otelFromContext(ctx).traceProvider.Tracer(name, opts...)
26✔
56
}
26✔
57

58
func MeterFromContext(ctx context.Context, name string, opts ...metric.MeterOption) metric.Meter {
11✔
59
        return otelFromContext(ctx).meterProvider.Meter(name, opts...)
11✔
60
}
11✔
61

62
type (
63
        meterNoShutdown struct {
64
                metric.MeterProvider
65
        }
66
        tracerNoShutdown struct {
67
                trace.TracerProvider
68
        }
69
)
70

NEW
71
func (m meterNoShutdown) ForceFlush(context.Context) error  { return nil }
×
NEW
72
func (m meterNoShutdown) Shutdown(context.Context) error    { return nil }
×
NEW
73
func (t tracerNoShutdown) ForceFlush(context.Context) error { return nil }
×
NEW
74
func (t tracerNoShutdown) Shutdown(context.Context) error   { return nil }
×
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