framework icon indicating copy to clipboard operation
framework copied to clipboard

feat: [#726] Add HTTP server and client telemetry instrumentation [5]

Open krishankumar01 opened this issue 2 months ago β€’ 1 comments

πŸ“‘ Description

RelatedTo https://github.com/goravel/goravel/issues/726

βœ… Checks

  • [ ] Added test cases for my code

krishankumar01 avatar Dec 29 '25 20:12 krishankumar01

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.

Files with missing lines Patch % Lines
telemetry/setup/stubs.go 0.00% 22 Missing :warning:
telemetry/instrumentation/http/middleware.go 80.00% 11 Missing and 8 partials :warning:
telemetry/instrumentation/http/config.go 45.45% 6 Missing :warning:
http/service_provider.go 0.00% 4 Missing :warning:
log/service_provider.go 0.00% 4 Missing :warning:
telemetry/service_provider.go 0.00% 4 Missing :warning:
telemetry/instrumentation/http/transport.go 84.61% 1 Missing and 1 partial :warning:
telemetry/instrumentation/log/handler.go 87.50% 1 Missing and 1 partial :warning:
telemetry/instrumentation/grpc/handler.go 90.90% 0 Missing and 1 partial :warning:
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.

codecov[bot] avatar Dec 29 '25 20:12 codecov[bot]

The report is sent by default currently, it should be unexpected. Could you optimize it in this PR?

image

hwbrzzl avatar Jan 03 '26 07:01 hwbrzzl

The report is sent by default currently, it should be unexpected. Could you optimize it in this PR?

image

Is it for grpc?

krishankumar01 avatar Jan 03 '26 07:01 krishankumar01

@krishankumar01 No, just using the default configuration and run the project.

hwbrzzl avatar Jan 03 '26 08:01 hwbrzzl

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.

krishankumar01 avatar Jan 03 '26 08:01 krishankumar01

The report is sent by default currently, it should be unexpected. Could you optimize it in this PR? image

@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.

krishankumar01 avatar Jan 04 '26 09:01 krishankumar01

@coderabbitai review

krishankumar01 avatar Jan 21 '26 18:01 krishankumar01

βœ… 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.

coderabbitai[bot] avatar Jan 21 '26 18:01 coderabbitai[bot]

[!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.

❀️ Share

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

coderabbitai[bot] avatar Jan 21 '26 19:01 coderabbitai[bot]