feat: [#726] Add HTTP server and client telemetry instrumentation [5]
π Description
RelatedTo https://github.com/goravel/goravel/issues/726
β Checks
- [ ] Added test cases for my code
Codecov Report
:x: Patch coverage is 71.17117% with 64 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 68.81%. Comparing base (dec0882) to head (0d36c61).
:warning: Report is 1 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #1326 +/- ##
========================================
Coverage 68.80% 68.81%
========================================
Files 283 286 +3
Lines 17884 18043 +159
========================================
+ Hits 12305 12416 +111
- Misses 5065 5101 +36
- Partials 514 526 +12
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
The report is sent by default currently, it should be unexpected. Could you optimize it in this PR?
The report is sent by default currently, it should be unexpected. Could you optimize it in this PR?
![]()
Is it for grpc?
@krishankumar01 No, just using the default configuration and run the project.
Okay, Iβll check. Iβm thinking of using a kill switch for all instrumentation in config/telemetry.go to disable telemetry globally. This switch would override all other configuration and help enable or disable telemetry across different environments without changing multiple files.
Instrumentation:
HttpServer:
Enabled: true
HttpClient:
Enabled: false
Log:
Enabled: false
In this case, regardless of whether the log driver or HTTP middleware is registered, telemetry will not be published when it is disabled.
The report is sent by default currently, it should be unexpected. Could you optimize it in this PR?
@hwbrzzl I think the issue is in telemetry.metrics.exporter. We are setting it to otelmetric, which by default enables metrics publishing. Since OpenTelemetry is push-based, it tries to push metrics automatically. To disable metrics, we need to set this value to an empty string.
@coderabbitai review
β Actions performed
Review triggered.
Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.
[!NOTE]
Other AI code review bot(s) detected
CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.
π Walkthrough
Walkthrough
This PR introduces comprehensive telemetry instrumentation support across HTTP clients, HTTP servers, logging, and gRPC services. It adds a telemetry resolver abstraction, configuration-driven feature flags for each instrumentation domain, lazy telemetry initialization, and conditional transport/handler wrapping to enable observability without breaking existing functionality.
Changes
| Cohort / File(s) | Summary |
|---|---|
Core Telemetry Infrastructure contracts/telemetry/telemetry.go, go.mod |
Added Resolver type alias for factory-style telemetry resolution and new otelhttp instrumentation dependency. |
HTTP Client Instrumentation http/client/config.go, http/client/factory.go, http/client/factory_test.go, http/service_provider.go, telemetry/instrumentation/http/transport.go, telemetry/instrumentation/http/transport_test.go |
Introduced EnableTelemetry config field; refactored factory to accept telemetry resolver and conditionally wrap HTTP transports with OTEL instrumentation; updated service provider to wire telemetry into factory initialization. |
HTTP Server Instrumentation telemetry/instrumentation/http/config.go, telemetry/instrumentation/http/middleware.go, telemetry/instrumentation/http/middleware_test.go |
Added HTTP server telemetry middleware with configurable filters, span naming, and metric collection; includes functional option pattern for ServerConfig composition. |
Logging Instrumentation log/application.go, log/application_test.go, log/service_provider.go, log/writer_test.go, telemetry/instrumentation/log/channel.go, telemetry/instrumentation/log/channel_test.go, telemetry/instrumentation/log/handler.go, telemetry/instrumentation/log/handler_test.go |
Threaded telemetry resolver through log application initialization; implemented lazy telemetry channel and handler resolution with runtime enable/disable via config flags. |
gRPC Instrumentation telemetry/instrumentation/grpc/handler.go, telemetry/instrumentation/grpc/handler_test.go |
Refactored gRPC handlers from stateless to config/telemetry-aware; added nil-checks and conditional instrumentation based on feature flags. |
Configuration & Service Provider Cleanup telemetry/setup/stubs.go, telemetry/service_provider.go |
Added new instrumentation configuration block with per-domain feature flags (http_server, http_client, grpc_server, grpc_client, log); removed global telemetry/config facades and enabled local resolution via dependency injection. |
Sequence Diagram(s)
sequenceDiagram
actor App as Application
participant Config as Config Service
participant Factory as Component Factory
participant TelemetryResolver as Telemetry Resolver
participant Telemetry as Telemetry Instance
participant Component as Instrumented Component
App->>Config: Load instrumentation config
App->>Factory: Initialize with TelemetryResolver
Factory->>Config: Check if instrumentation enabled
alt Instrumentation Disabled
Factory->>Component: Create base component (no wrapping)
else Instrumentation Enabled
Factory->>TelemetryResolver: Resolve telemetry
TelemetryResolver->>Telemetry: Return Telemetry instance
Factory->>Component: Create and wrap with OTEL instrumentation
Component->>Telemetry: Use TracerProvider, MeterProvider, Propagator
end
App->>Component: Use instrumented component
Component->>Telemetry: Emit traces/metrics
Estimated code review effort
π― 4 (Complex) | β±οΈ ~50 minutes
Suggested labels
π Review Ready
Suggested reviewers
- hwbrzzl
Poem
π° Telemetry traces now flow,
HTTP, logs, and gRPC glow,
With config flags and resolvers bright,
Observability takes flight!
No facades, just injection clean,
The best instrumented scene! β¨
π₯ Pre-merge checks | β 2 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 12.82% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title clearly indicates the PR adds HTTP server and client telemetry instrumentation, which is the main focus of the changeset across multiple files. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing touches
- [ ] π Generate docstrings
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
