Skip to content

refactor(otel): reduce NewTelemetry cyclomatic complexity from 20 to ≤16#378

Merged
jeffersonrodrigues92 merged 1 commit intodevelopfrom
refactor/reduce-newtelemetry-complexity
Mar 21, 2026
Merged

refactor(otel): reduce NewTelemetry cyclomatic complexity from 20 to ≤16#378
jeffersonrodrigues92 merged 1 commit intodevelopfrom
refactor/reduce-newtelemetry-complexity

Conversation

@jeffersonrodrigues92
Copy link
Contributor

Summary

Reduces NewTelemetry cyclomatic complexity from 20 to ≤16 by extracting three helper functions. No behavior change.

Extracted Helpers

  • normalizeEndpoint(cfg *TelemetryConfig) — endpoint scheme stripping and insecure-mode inference
  • handleEmptyEndpoint(cfg TelemetryConfig) — "enabled but no endpoint" noop fallback path
  • initExporters(ctx, cfg) — OTLP exporter creation, provider setup, and rollback-on-failure

Test plan

  • go build ./... passes
  • golangci-lint run ./commons/opentelemetry/... — 0 issues

Extracts normalizeEndpoint, handleEmptyEndpoint, and initExporters helpers. No behavior change.

X-Lerian-Ref: 0x1
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6320d194-fc11-412d-9bf1-5fdd0a1765a7

📥 Commits

Reviewing files that changed from the base of the PR and between 240bf53 and d408e57.

📒 Files selected for processing (1)
  • commons/opentelemetry/otel.go

Walkthrough

The NewTelemetry function in commons/opentelemetry/otel.go was refactored by extracting logic into three new helper functions: normalizeEndpoint handles endpoint scheme trimming and whitespace normalization; handleEmptyEndpoint manages cases where telemetry is enabled but the collector endpoint is empty, logging warnings and returning noop telemetry; and initExporters encapsulates OTLP exporter, provider, and metrics factory initialization. The main function flow was simplified by delegating to these helpers while preserving all original behavior. Net change of 48 added and 34 removed lines.


Comment @coderabbitai help to get the list of available commands and usage tips.

@jeffersonrodrigues92 jeffersonrodrigues92 merged commit f7e2fd1 into develop Mar 21, 2026
2 of 3 checks passed
@jeffersonrodrigues92 jeffersonrodrigues92 deleted the refactor/reduce-newtelemetry-complexity branch March 21, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant