Skip to content

Commit 86b09d6

Browse files
committed
chore: Expanding lll coverage to telemetry
1 parent adca279 commit 86b09d6

6 files changed

Lines changed: 29 additions & 11 deletions

File tree

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ linters:
121121
# trying to get this merged in.
122122
- linters:
123123
- lll
124-
path-except: '^(internal/awshelper/|internal/cas/|internal/cli/commands/(backend/(delete|migrate)|catalog/tui/command|dag/graph|exec|find|help|list|scaffold|stack)/|internal/cloner/|internal/configbridge/|internal/engine/|internal/errorconfig/|internal/errors/|internal/experiment/|internal/gcphelper/|internal/git/|internal/os/exec/|internal/prepare/|internal/queue/|internal/runner/(common|graph|run/creds|runcfg)/|internal/stacks/(generate|output)/|internal/tf/cache/(controllers|middleware)/|internal/tflint/|internal/tips/|internal/vfs/|internal/worktrees/|pkg/log/(format/(options|placeholders)|writer)/)'
124+
path-except: '^(internal/awshelper/|internal/cas/|internal/cli/commands/(backend/(delete|migrate)|catalog/tui/command|dag/graph|exec|find|help|list|scaffold|stack)/|internal/cloner/|internal/configbridge/|internal/engine/|internal/errorconfig/|internal/errors/|internal/experiment/|internal/gcphelper/|internal/git/|internal/os/exec/|internal/prepare/|internal/queue/|internal/runner/(common|graph|run/creds|runcfg)/|internal/stacks/(generate|output)/|internal/telemetry/|internal/tf/cache/(controllers|middleware)/|internal/tflint/|internal/tips/|internal/vfs/|internal/worktrees/|pkg/log/(format/(options|placeholders)|writer)/)'
125125
paths:
126126
- docs
127127
- _ci

internal/telemetry/context.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func TelemeterFromContext(ctx context.Context) *Telemeter {
3131
return new(Telemeter)
3232
}
3333

34-
// TraceParentFromContext returns the W3C traceparent header value from the context's span, or an error if not available.
34+
// TraceParentFromContext returns the W3C traceparent header value from
35+
// the context's span, or an error if not available.
3536
func TraceParentFromContext(ctx context.Context, telemetry *Options) string {
3637
span := trace.SpanFromContext(ctx)
3738
spanContext := span.SpanContext()

internal/telemetry/meter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ func NewMeter(ctx context.Context, appName, appVersion string, writer io.Writer,
7171
}
7272

7373
// Time collects time for function execution
74-
func (meter *Meter) Time(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error {
74+
func (meter *Meter) Time(
75+
ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error,
76+
) error {
7577
if meter == nil || meter.exporter == nil {
7678
return fn(ctx)
7779
}

internal/telemetry/opts.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ type Options struct {
1010
TraceParent string
1111
// MetricExporter is the type of metrics exporter.
1212
MetricExporter string
13-
// TraceExporterInsecureEndpoint is useful for collecting traces locally. If set to true, the exporter will not validate the server certificate.
13+
// TraceExporterInsecureEndpoint is useful for collecting traces locally.
14+
// If set to true, the exporter will not validate the server certificate.
1415
TraceExporterInsecureEndpoint bool
15-
// MetricExporterInsecureEndpoint is useful for local metrics collection. if set to true, the exporter will not validate the server's certificate.
16+
// MetricExporterInsecureEndpoint is useful for local metrics collection.
17+
// If set to true, the exporter will not validate the server's certificate.
1618
MetricExporterInsecureEndpoint bool
1719
}

internal/telemetry/telemeter.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type Telemeter struct {
1717
}
1818

1919
// NewTelemeter initializes the telemetry collector.
20-
func NewTelemeter(ctx context.Context, l log.Logger, appName, appVersion string, writer io.Writer, opts *Options) (*Telemeter, error) {
20+
func NewTelemeter(
21+
ctx context.Context, l log.Logger, appName, appVersion string, writer io.Writer, opts *Options,
22+
) (*Telemeter, error) {
2123
tracer, err := NewTracer(ctx, l, appName, appVersion, writer, opts)
2224
if err != nil {
2325
return nil, errors.New(err)
@@ -61,7 +63,9 @@ func (tlm *Telemeter) Shutdown(ctx context.Context) error {
6163
}
6264

6365
// Collect collects telemetry from function execution metrics and traces.
64-
func (tlm *Telemeter) Collect(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error {
66+
func (tlm *Telemeter) Collect(
67+
ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error,
68+
) error {
6569
if tlm == nil {
6670
// This should not happen in normal operation. Log a stack trace to help
6771
// diagnose if this nil guard is the one preventing a panic.

internal/telemetry/tracer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ type Tracer struct {
4545
}
4646

4747
// NewTracer creates and configures the traces collection.
48-
func NewTracer(ctx context.Context, l log.Logger, appName, appVersion string, writer io.Writer, opts *Options) (*Tracer, error) {
48+
func NewTracer(
49+
ctx context.Context, l log.Logger, appName, appVersion string, writer io.Writer, opts *Options,
50+
) (*Tracer, error) {
4951
spanExporter, err := NewTraceExporter(ctx, writer, opts)
5052
if err != nil {
5153
return nil, errors.New(err)
@@ -116,7 +118,9 @@ func NewTracer(ctx context.Context, l log.Logger, appName, appVersion string, wr
116118
}
117119

118120
// newTraceProvider creates a new trace tracer with terragrunt version.
119-
func newTraceProvider(exp sdktrace.SpanExporter, appName, appVersion string, opts *Options) (*sdktrace.TracerProvider, error) {
121+
func newTraceProvider(
122+
exp sdktrace.SpanExporter, appName, appVersion string, opts *Options,
123+
) (*sdktrace.TracerProvider, error) {
120124
r, err := resource.Merge(
121125
resource.Default(),
122126
resource.NewWithAttributes(
@@ -190,7 +194,9 @@ func NewTraceExporter(ctx context.Context, writer io.Writer, opts *Options) (sdk
190194
}
191195

192196
// Trace collects traces for method execution.
193-
func (tracer *Tracer) Trace(ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error) error {
197+
func (tracer *Tracer) Trace(
198+
ctx context.Context, name string, attrs map[string]any, fn func(childCtx context.Context) error,
199+
) error {
194200
if tracer == nil || tracer.spanExporter == nil || tracer.provider == nil { // invoke function without tracing
195201
return fn(ctx)
196202
}
@@ -199,7 +205,10 @@ func (tracer *Tracer) Trace(ctx context.Context, name string, attrs map[string]a
199205

200206
if span == nil {
201207
if tracer.l != nil {
202-
tracer.l.Debugf("openSpan returned nil span for %q (provider may have been shut down), bypassing tracing. Stack:\n%s", name, debug.Stack())
208+
tracer.l.Debugf(
209+
"openSpan returned nil span for %q (provider may have been shut down), bypassing tracing. Stack:\n%s",
210+
name, debug.Stack(),
211+
)
203212
}
204213

205214
return fn(ctx)

0 commit comments

Comments
 (0)