Skip to content

Conversation

@askpt
Copy link
Member

@askpt askpt commented Oct 13, 2025

Signed-off-by: André Silva [email protected]

This PR

This pull request updates the OpenTelemetry integration in the core module to use the new autoexport package, simplifying configuration and improving compatibility with environment variables. It removes custom gRPC transport credential handling and centralizes exporter setup, making telemetry easier to configure and maintain. Several dependencies are updated to their latest versions, and tests are adjusted to reflect the new configuration logic.

OpenTelemetry Integration Refactor:

  • Replaced manual OTLP exporter and gRPC credential setup with the new autoexport package, removing custom TLS handling and simplifying trace and metric exporter initialization in core/pkg/telemetry/builder.go. Now, environment variables are used for configuration, and Prometheus is used as a fallback for metrics. [1] [2] [3] [4]
  • Updated test cases in core/pkg/telemetry/builder_test.go to reflect the new autoexport logic, removing tests for unsupported configurations and ensuring the interceptor is always added. [1] [2]

Dependency Updates:

  • Updated core dependencies in core/go.mod, including prometheus/client_golang, stretchr/testify, go.opentelemetry.io/otel, and related packages to their latest versions. Added new dependencies for autoexport and related exporters.
  • Updated various indirect dependencies to newer versions, such as github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp, github.com/cenkalti/backoff/v5, github.com/go-jose/go-jose/v4, and others. [1] [2] [3] [4] [5]

These changes make telemetry setup more robust and future-proof, reducing custom code and leveraging upstream improvements.

Related Issues

Fixes #1141

Notes

  • In case the "old" variables are set, I override the "auto-export" variables. Then the library do its magic as suggested by @erka

@netlify
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 0c23f00
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/691f48fc318b4f00084ef415

@erka
Copy link
Member

erka commented Oct 14, 2025

@askpt I would suggest using https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport and not re-implement the entire otel sdk.

@askpt
Copy link
Member Author

askpt commented Oct 14, 2025

@askpt I would suggest using https://pkg.go.dev/go.opentelemetry.io/contrib/exporters/autoexport and not re-implement the entire otel sdk.

Thank you so much for the suggestion @erka! I was not aware of this library, and I will take a look. I am concerned that it may not be easily switched, as we need to maintain backwards compatibility with the previous settings.

@erka
Copy link
Member

erka commented Oct 14, 2025

You can likely configure the OTEL environment variables within the code - using the flagd configuration - prior to initializing autoexport to maintain backwards compatibility.

@askpt askpt force-pushed the askpt/1141-add-otel-variables branch from 94a88af to 6d015b6 Compare October 23, 2025 13:38
@askpt askpt marked this pull request as ready for review October 31, 2025 16:16
@askpt askpt requested review from a team as code owners October 31, 2025 16:16
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 31, 2025
@beeme1mr
Copy link
Member

@askpt I've resolved the FOSSA issues.

@askpt
Copy link
Member Author

askpt commented Nov 18, 2025

@askpt I've resolved the FOSSA issues.

@beeme1mr Is there any library i shouldn't be using? I think they are all related to OTEL.

@sonarqubecloud
Copy link

@toddbaert
Copy link
Member

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant improvement, refactoring the OpenTelemetry integration to use the autoexport package. This change greatly simplifies the codebase by removing custom logic for OTLP exporter setup and transport credentials, instead relying on standard environment variable-based configuration. The addition of backward compatibility for existing flag-based configurations by setting the corresponding environment variables is a well-thought-out approach. The overall result is a cleaner, more maintainable, and more standard-compliant telemetry setup. The dependency updates and test adjustments are also appropriate and align with the refactoring. Great work!


// buildDefaultMetricReader provides the default metric reader
func buildDefaultMetricReader() (metric.Reader, error) {
func buildDefaultMetricReader(ctx context.Context) (metric.Reader, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The ctx parameter in buildDefaultMetricReader is not used. It's good practice to name unused parameters with an underscore (_) to make it explicit to readers of the code that it is intentionally unused.

Suggested change
func buildDefaultMetricReader(ctx context.Context) (metric.Reader, error) {
func buildDefaultMetricReader(_ context.Context) (metric.Reader, error) {

// Set OTEL environment variables from configuration if not already set
setEnvIfNotSet("OTEL_METRICS_EXPORTER", "otlp")
setEnvIfNotSet("OTEL_EXPORTER_OTLP_ENDPOINT", cfg.CollectorConfig.Target)
setEnvIfNotSet("OTEL_EXPORTER_OTLP_PROTOCOL", "grpc")
Copy link
Member

Choose a reason for hiding this comment

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

Is gRPC the right default here? Or should we add other options. I have NO idea myself, so I will defer to you on this one.

cc @beeme1mr

https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_protocol

Copy link
Member

Choose a reason for hiding this comment

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

Ya... based on my research, I think "http/protobuf" might be a safer default.

Copy link
Member

Choose a reason for hiding this comment

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

It was used by flagd before. I believe it's a fallback value for backward compatibility.

@toddbaert toddbaert requested a review from beeme1mr November 21, 2025 18:56
@toddbaert
Copy link
Member

toddbaert commented Nov 21, 2025

It seems right to me, but I'm far from being an OTel expert, especially WRT to the autoexport stuff... maybe @beeme1mr can confrim.

@toddbaert toddbaert self-requested a review November 21, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] flagd should use standard OTel SDK env vars

4 participants