Skip to content

test: add unit tests for telemetry#3033

Closed
omer-topal wants to merge 1 commit into
masterfrom
test/telemetry-coverage
Closed

test: add unit tests for telemetry#3033
omer-topal wants to merge 1 commit into
masterfrom
test/telemetry-coverage

Conversation

@omer-topal

@omer-topal omer-topal commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Tests
    • Added broader test coverage for telemetry setup, including exporter selection, protocol handling, and OTLP configuration.
    • Verified that supported exporter options create valid instances and unsupported options return clear errors.
    • Added checks for service naming, logging/tracing setup, and metric helpers to improve confidence in telemetry behavior.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

πŸ“ Walkthrough

Walkthrough

This PR adds unit test files for the telemetry package, covering exporter factories for log, meter, and tracer exporters (OTLP, zipkin, jaeger, signoz), as well as core telemetry helpers like resource naming, handler factory, log/tracer providers, and metric instruments.

Changes

Telemetry exporter and core test coverage

Layer / File(s) Summary
Log exporter factory tests
pkg/telemetry/logexporters/factory_test.go
Table-driven tests verify ExporterFactory alias acceptance and error handling, and NewOTLP succeeds/fails across http/grpc configurations.
Meter exporter factory tests
pkg/telemetry/meterexporters/factory_test.go
Table-driven tests verify ExporterFactory alias acceptance and error handling, and NewOTLP succeeds/fails across http/grpc configurations.
Tracer exporter factory tests
pkg/telemetry/tracerexporters/factory_test.go
Table-driven and smoke tests cover ExporterFactory, NewOTLP, NewZipkin, NewJaegar, and NewSigNoz for success and error cases.
Core telemetry helper tests
pkg/telemetry/telemetry_test.go
Tests validate newResource naming fallback, HandlerFactory success/error paths, NewOTLPHandler, NewGCPHandler errors, NewLog/NewTracer shutdown behavior, and noop meter/counter/histogram instrument creation.

Estimated code review effort: 2 (Simple) | ~12 minutes

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately summarizes the main change: added unit tests for the telemetry package.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/telemetry-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
pkg/telemetry/meterexporters/factory_test.go (2)

57-57: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | ⚑ Quick win

Verify the exact error message for the unsupported protocol case.

TestExporterFactory asserts the precise error string for error cases, but TestNewOTLP only checks that an error occurred for the "unsupported protocol" case. Asserting the message ("unsupported protocol: udp") would make the test consistent and guard against accidental error-format changes.

♻️ Proposed fix
 		{name: "unsupported protocol", protocol: "udp", wantErr: true},
 func TestNewOTLP(t *testing.T) {
 	tests := []struct {
 		name       string
 		insecure   bool
 		urlpath    string
 		headers    map[string]string
 		protocol   string
 		wantErr    bool
+		errMessage string
 	}{
 		{name: "http insecure with options", insecure: true, urlpath: "/v1/metrics", headers: map[string]string{"key": "value"}, protocol: "http"},
 		{name: "http secure", insecure: false, protocol: "http"},
 		{name: "grpc insecure", insecure: true, headers: map[string]string{"key": "value"}, protocol: "grpc"},
 		{name: "grpc secure", insecure: false, headers: map[string]string{"key": "value"}, protocol: "grpc"},
-		{name: "unsupported protocol", protocol: "udp", wantErr: true},
+		{name: "unsupported protocol", protocol: "udp", wantErr: true, errMessage: "unsupported protocol: udp"},
 	}
 			exp, err := NewOTLP("localhost:4317", tt.insecure, tt.urlpath, tt.headers, tt.protocol)
 			if tt.wantErr {
 				if err == nil {
 					t.Fatalf("expected error, got nil")
 				}
+				if tt.errMessage != "" && err.Error() != tt.errMessage {
+					t.Fatalf("expected error %q, got %q", tt.errMessage, err.Error())
+				}
 				return
 			}
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/telemetry/meterexporters/factory_test.go` at line 57, The unsupported
protocol case in TestNewOTLP only checks for an error, but it should assert the
exact message to stay consistent with TestExporterFactory. Update the
"unsupported protocol" table-driven case in factory_test.go to verify the error
string from NewOTLP matches the precise unsupported protocol message for "udp",
using the existing TestNewOTLP and unsupported protocol symbols to locate the
assertion.

60-75: 🩺 Stability & Availability | πŸ”΅ Trivial | ⚑ Quick win

Shut down exporters in success cases to avoid resource leaks.

otlpmetrichttp.New and otlpmetricgrpc.New can start background goroutines/connections. The success cases create exporters but never call Shutdown, which may leak resources or cause flakiness when the suite runs in CI.

♻️ Proposed fix
 			if exp == nil {
 				t.Fatalf("expected exporter, got nil")
 			}
+			if err := exp.Shutdown(context.Background()); err != nil {
+				t.Fatalf("failed to shutdown exporter: %v", err)
+			}
 		})

You'll also need to add "context" to the import block.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/telemetry/meterexporters/factory_test.go` around lines 60 - 75, The
successful NewOTLP test cases create exporters but never clean them up, which
can leave background goroutines or connections running. Update the table-driven
test in factory_test.go so that when NewOTLP returns a non-nil exporter in the
non-error path, it calls Shutdown with a context before the subtest exits. Add
the context import needed for that cleanup, and keep the existing error
assertions intact in the t.Run cases around NewOTLP.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/telemetry/meterexporters/factory_test.go`:
- Line 57: The unsupported protocol case in TestNewOTLP only checks for an
error, but it should assert the exact message to stay consistent with
TestExporterFactory. Update the "unsupported protocol" table-driven case in
factory_test.go to verify the error string from NewOTLP matches the precise
unsupported protocol message for "udp", using the existing TestNewOTLP and
unsupported protocol symbols to locate the assertion.
- Around line 60-75: The successful NewOTLP test cases create exporters but
never clean them up, which can leave background goroutines or connections
running. Update the table-driven test in factory_test.go so that when NewOTLP
returns a non-nil exporter in the non-error path, it calls Shutdown with a
context before the subtest exits. Add the context import needed for that
cleanup, and keep the existing error assertions intact in the t.Run cases around
NewOTLP.

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8706542-67e3-4b6e-b182-e72c06e96857

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e62cb3e and 35edd31.

πŸ“’ Files selected for processing (4)
  • pkg/telemetry/logexporters/factory_test.go
  • pkg/telemetry/meterexporters/factory_test.go
  • pkg/telemetry/telemetry_test.go
  • pkg/telemetry/tracerexporters/factory_test.go

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 74.24%. Comparing base (e62cb3e) to head (35edd31).

❌ Your project check has failed because the head coverage (74.24%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3033      +/-   ##
==========================================
- Coverage   74.67%   74.24%   -0.42%     
==========================================
  Files          83       99      +16     
  Lines        9212     9541     +329     
==========================================
+ Hits         6878     7083     +205     
- Misses       1798     1910     +112     
- Partials      536      548      +12     

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@omer-topal omer-topal closed this Jul 8, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 8, 2026
@omer-topal
omer-topal deleted the test/telemetry-coverage branch July 8, 2026 12:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant