Skip to content

feat: [#726][Trace] Add OpenTelemetry Tracing Support for Distributed Tracing#1283

Merged
krishankumar01 merged 29 commits intomasterfrom
kkumar-gcc/#726
Dec 9, 2025
Merged

feat: [#726][Trace] Add OpenTelemetry Tracing Support for Distributed Tracing#1283
krishankumar01 merged 29 commits intomasterfrom
kkumar-gcc/#726

Conversation

@krishankumar01
Copy link
Member

@krishankumar01 krishankumar01 commented Dec 4, 2025

📑 Description

RelatedTo goravel/goravel#726

Summary

Introduces a new Telemetry module providing OpenTelemetry-based distributed tracing for Goravel applications.

Features:

  • Multiple exporters: OTLP, Zipkin, Console
  • Configurable samplers: always_on, always_off, traceidratio
  • Context propagation: W3C TraceContext, Baggage, B3

Note

Currently It doesn't support custom exporter, I will add this feature in next couple of PR


Usage

Configuration (.env)

OTEL_SERVICE_NAME=my-service
OTEL_TRACES_EXPORTER=otlp
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

Creating Traces

tracer := facades.Telemetry().Tracer("my-service")

ctx, span := tracer.Start(ctx, "operation-name")
defer span.End()

span.SetAttributes(attribute.String("user.id", "123"))

Context Propagation

// Inject trace context into outgoing HTTP requests
facades.Telemetry().Propagator().Inject(ctx, telemetry.PropagationHeaderCarrier(req.Header))

// Extract trace context from incoming HTTP requests
ctx = facades.Telemetry().Propagator().Extract(ctx, telemetry.PropagationHeaderCarrier(req.Header))

Shutdown

defer facades.Telemetry().Shutdown(context.Background())

Configuration Reference

Option Env Variable Default Description
Exporter OTEL_TRACES_EXPORTER otlp otlp, zipkin, console, none
Sampler OTEL_TRACES_SAMPLER_TYPE always_on always_on, always_off, traceidratio
Propagators OTEL_PROPAGATORS tracecontext,baggage tracecontext, baggage, b3, b3multi

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings December 4, 2025 13:56
@krishankumar01 krishankumar01 requested a review from a team as a code owner December 4, 2025 13:56
@krishankumar01 krishankumar01 marked this pull request as draft December 4, 2025 13:56
@krishankumar01 krishankumar01 changed the title feat: [#726] Add OpenTelemetry Tracing Support for Distributed Tracing feat: [#726] Add OpenTelemetry Tracing Support for Distributed Tracing [Trace] Dec 4, 2025
@krishankumar01 krishankumar01 changed the title feat: [#726] Add OpenTelemetry Tracing Support for Distributed Tracing [Trace] feat: [#726][Trace] Add OpenTelemetry Tracing Support for Distributed Tracing Dec 4, 2025
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 59.05797% with 113 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.97%. Comparing base (52c3e24) to head (2f14cdb).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
telemetry/setup/stubs.go 0.00% 55 Missing ⚠️
telemetry/setup/setup.go 0.00% 19 Missing ⚠️
telemetry/service_provider.go 0.00% 17 Missing ⚠️
foundation/container.go 0.00% 6 Missing ⚠️
telemetry/alias.go 0.00% 4 Missing ⚠️
telemetry/application.go 92.30% 3 Missing and 1 partial ⚠️
telemetry/exporter.go 93.93% 2 Missing and 2 partials ⚠️
telemetry/propagator.go 90.47% 1 Missing and 1 partial ⚠️
telemetry/resource.go 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1283      +/-   ##
==========================================
- Coverage   69.14%   68.97%   -0.18%     
==========================================
  Files         265      275      +10     
  Lines       15671    15947     +276     
==========================================
+ Hits        10836    10999     +163     
- Misses       4368     4476     +108     
- Partials      467      472       +5     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR claims to add OpenTelemetry tracing support for distributed tracing (issue #726), but the implementation is incomplete. The PR only creates a placeholder file with no actual functionality, no OpenTelemetry dependencies, and no tests.

Key observations:

  • Only a single file is added: contracts/telemetry/telemetry.go containing only a package declaration and a placeholder comment
  • No OpenTelemetry dependencies are added to go.mod
  • No actual tracing interfaces, types, or implementation code exists
  • No test coverage is provided

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 27 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Exporters Configuration
//
// Configure exporters for sending telemetry data.
// Supported drivers: "otlp", "zipkin", "console"
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

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

The comment says "Supported drivers" but should say "Supported exporters" for consistency with the rest of the configuration comments and the actual setting name ("exporter").

Suggested change
// Supported drivers: "otlp", "zipkin", "console"
// Supported exporters: "otlp", "zipkin", "console"

Copilot uses AI. Check for mistakes.
@krishankumar01 krishankumar01 marked this pull request as ready for review December 7, 2025 10:51
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: ed119d1 Previous: 9a4a7b4 Ratio
Benchmark_DecryptString 6361 ns/op 2032 B/op 16 allocs/op 2082 ns/op 2032 B/op 16 allocs/op 3.06
Benchmark_DecryptString - ns/op 6361 ns/op 2082 ns/op 3.06

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/sdk/resource"
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

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

The import semconv "go.opentelemetry.io/otel/semconv/v1.37.0" is used but this dependency is not declared in go.mod or go.sum. This will cause compilation failures. The semconv package needs to be added as a direct dependency in go.mod.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

@krishankumar01 krishankumar01 Dec 7, 2025

Choose a reason for hiding this comment

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

Because this is not direct dependency but a subpart of otel#v1.138.0 package

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Awesome 👍 Two middleware (http/grpc) should be needed, correct? Normally, users don't need to use facades.Telemetry() directly.

propagator propagation.TextMapPropagator
}

func NewApplication(cfg config.Config) (*Application, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When writing test cases, we have to mock every configuration. Sometimes it's very complicated. Ideally, every module should have its own config interface to fetch configuration, and have a Config struct to be initiated in NewApplication, then the config can be mocked. We can optimized it later if you agree.

Copy link
Member Author

@krishankumar01 krishankumar01 Dec 8, 2025

Choose a reason for hiding this comment

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

Yeah, that’s why I experimented a bit with the propagator and exporter, you can check that they both expect a config struct. We can follow the same approach, and our service provider should resolve this config struct. If you agree, I can start moving at least this module to that philosophy. Or we can expose a method UnmarshalKey to map a key to a go struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

@hwbrzzl I have added a config.go we can follow a similar way to resolve all config

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, use the module's own config instead of facades.Config directly. It's easier to mock.

@krishankumar01
Copy link
Member Author

Awesome 👍 Two middleware (http/grpc) should be needed, correct? Normally, users don't need to use facades.Telemetry() directly.

Yeah, I’ll implement auto-instrumentation in later PRs.

telemetryServiceProvider := "&telemetry.ServiceProvider{}"
modulePath := packages.GetModulePath()

packages.Setup(os.Args).
Copy link
Contributor

Choose a reason for hiding this comment

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

I optimized the setup process. Currently, packages.Setup(os.Args) should be called first to initiate Paths from os.Args. Otherwise, path.Config("telemetry.go") will be incorrect if user customizes the config path.

Image

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to rethink the paths feature. In the code you pass a configPackage, for example:

WithPaths(func(paths configuration.Paths) {
    paths.Config("hello")
    paths.Facades("new")
})

If a user customises paths like this, when they install the cache package it should create the config in the hello directory and the facades in the new directory. But your current stubs only customise moduleName in the path. I’m not sure that’s the right approach, it looks like we need to optimise this before adopting it.

Screenshot 2025-12-09 at 5 44 50 PM Screenshot 2025-12-09 at 5 44 33 PM

Copy link
Member Author

Choose a reason for hiding this comment

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

Let’s optimise this in a later PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'm optimizing it.

Comment on lines +66 to +67
"timeout": config.Env("OTEL_EXPORTER_OTLP_TIMEOUT", 10000),
"traces_timeout": config.Env("OTEL_EXPORTER_OTLP_TRACES_TIMEOUT", ""),
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Do we have a plan to add metrics and logs later?

Copy link
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM.

@krishankumar01 krishankumar01 merged commit 18d63ba into master Dec 9, 2025
12 of 14 checks passed
@krishankumar01 krishankumar01 deleted the kkumar-gcc/#726 branch December 9, 2025 12:43
hwbrzzl pushed a commit that referenced this pull request Dec 12, 2025
… Tracing (#1283)

* init telemetry contracts package

* add propagators and telemetry interface

* add trace sampler

* add test cases

* implement telemetry resource

* implement exporters

* implement application

* add telemetry module and binding

* add service_provider

* add telemetry facade

* add telemetry setup

* change setup package to main

* update go mod

* expose propagator method

* add alias for common methods

* ...

* add insecure in grpc

* remove unnecessary nil check

* make propagator mandatory

* optimise telemetry setup

* optimise telemetry application

* optimise telemetry application

* use config struct instead of using config facade

* remove support/config

* optimise setup.go

* optimise telemetry/setup

* optimise telemetry/setup
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.

3 participants