Skip to content

refactor: extract OTLP exporter building logic into reusable macro#16

Merged
iamnivekx merged 3 commits intomainfrom
refactor/extract-exporter-macro
Jan 7, 2026
Merged

refactor: extract OTLP exporter building logic into reusable macro#16
iamnivekx merged 3 commits intomainfrom
refactor/extract-exporter-macro

Conversation

@iamnivekx
Copy link
Owner

@iamnivekx iamnivekx commented Jan 7, 2026

Summary

This PR refactors the OTLP exporter building logic by extracting common patterns into a reusable build_exporter! macro. This reduces code duplication and improves maintainability.

Changes

  • ✨ Add new macros module with build_exporter! macro for building OTLP exporters
  • 🔧 Refactor build_span_exporter(), build_metric_exporter(), and build_log_exporter() to use the new macro
  • 📝 Add protocol parsing utilities and tests
  • 🧹 Remove duplicate protocol resolution logic from otel.rs

Benefits

  • Consistency: Ensures all exporters use the same protocol resolution logic
  • Maintainability: Future changes to exporter building only need to be made in one place
  • Testability: Protocol parsing logic is now testable in isolation

Technical Details

The build_exporter! macro:

  • Supports both gRPC (tonic) and HTTP (protobuf/json) protocols
  • Respects signal-specific environment variables with global fallback
  • Allows optional builder configuration via closure parameter
  • Provides clear error messages for build failures

Testing

  • ✅ Added unit tests for protocol parsing
  • ✅ Existing integration tests should continue to pass

@gemini-code-assist
Copy link

Summary of Changes

Hello @iamnivekx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the OpenTelemetry Protocol (OTLP) exporter initialization logic by consolidating common patterns into a new, reusable macro. This change aims to reduce code duplication, enhance maintainability, and provide a consistent mechanism for configuring OTLP exporters for various signals (traces, metrics, logs) based on environment variables, streamlining the setup process for OpenTelemetry integration.

Highlights

  • New macros module: A new module crates/tracing-opentelemetry/src/macros.rs has been introduced to house reusable macro definitions and helper functions for OTLP exporter building.
  • Reusable build_exporter! macro: The core logic for building OTLP exporters (for traces, metrics, and logs) has been extracted into a build_exporter! macro, which handles protocol detection (gRPC vs. HTTP) based on environment variables.
  • Centralized Protocol Resolution: Helper functions parse_protocol, protocol_from_env, and protocol_for_signal were moved to the new macros module, centralizing the logic for determining the OTLP export protocol from environment variables.
  • Simplified Exporter Builders: The build_span_exporter, build_metric_exporter, and build_log_exporter functions in crates/tracing-opentelemetry/src/otel.rs have been refactored to utilize the new build_exporter! macro, significantly reducing code duplication and improving readability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@iamnivekx
Copy link
Owner Author

/gemini review

Copy link

@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 great refactoring that extracts the OTLP exporter building logic into a reusable macro, significantly reducing code duplication in otel.rs. The new build_exporter! macro is well-designed and makes the code cleaner and more maintainable.

I have a couple of suggestions to improve the changes. One is about the visibility of the new macros module, and the other is to enhance the documentation for a new public function to make it more explicit for users of the crate.

Overall, this is a solid improvement.

Copy link

@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 effectively refactors the OTLP exporter building logic into a reusable macro, which significantly reduces code duplication and improves maintainability. The new build_exporter! macro is well-designed and handles different protocols and configurations cleanly. My review includes a few suggestions to further improve the code: restoring important documentation that was removed during the refactoring, organizing use statements for better readability, and making the new macro even more concise by reducing code repetition within it. Overall, this is a solid improvement.

@iamnivekx iamnivekx merged commit 6638a64 into main Jan 7, 2026
5 checks passed
@iamnivekx iamnivekx deleted the refactor/extract-exporter-macro branch January 7, 2026 15:14
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.

1 participant