Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

otelfiber: add WithCustomMetricAttrbutes option #1159

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

hwo411
Copy link

@hwo411 hwo411 commented Jul 22, 2024

Add WithCustomMetricAttributes which is analogous to WithCustomAttributes for span.

Alternatively, we can apply WithCustmAttributes to metrics, but it doesn't give enough control over attributes

Fixes #1156

(If the solution is good, I'll update the README then)

Summary by CodeRabbit

  • New Features

    • Introduced custom metric attributes functionality for enhanced observability in the Fiber middleware.
    • Added configuration options to define custom attributes for metrics in the middleware.
  • Bug Fixes

    • Improved readability of the middleware code without altering its logic.
  • Tests

    • Implemented a test function to ensure correct behavior of custom metric attributes within the Fiber framework.

@hwo411 hwo411 requested a review from a team as a code owner July 22, 2024 10:44
@hwo411 hwo411 requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team July 22, 2024 10:44
Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

The recent modifications to the otelfiber library introduce a feature for custom metric attributes, significantly enhancing observability in Fiber middleware. Users can now specify a function that returns custom attributes for metrics collected during requests, improving flexibility while maintaining existing functionalities. Additionally, minor readability improvements were made, along with the introduction of a test case to validate the new feature.

Changes

Files Change Summary
otelfiber/config.go, otelfiber/semconv.go Added CustomMetricAttributes field and WithCustomMetricAttributes function; modified metric attribute collection to utilize custom attributes.
otelfiber/fiber.go Minor adjustments made to improve code readability in the Middleware function without functional changes.
otelfiber/otelfiber_test/fiber_test.go Introduced a new test function TestCustomMetricAttributes to validate the new custom metric attributes feature.
otelfiber/README.md Updated to include WithCustomMetricAttributes, enhancing middleware configuration options.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Fiber
    participant MetricCollector
    participant Config

    User->>Fiber: Sends request
    Fiber->>Config: Retrieves CustomMetricAttributes
    Config->>Fiber: Returns custom attributes function
    Fiber->>MetricCollector: Collects metrics with custom attributes
    MetricCollector-->>Fiber: Metrics recorded
Loading

Assessment against linked issues

Objective Addressed Explanation
Custom metric attributes for otelfiber (#1156)
Ability to set custom parameters based on request

Poem

🐰 In the garden of code, new features take flight,
Custom metrics now dance, a joyous delight!
With attributes tailored, each request sings,
Observability blooms, oh the joy that it brings!
Hoppy and bright, our middleware's new song,
In the world of otelfiber, we all belong! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the ✏️ Feature New feature or request label Jul 22, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1eedcd5 and c1d9e50.

Files selected for processing (4)
  • otelfiber/config.go (2 hunks)
  • otelfiber/fiber.go (1 hunks)
  • otelfiber/otelfiber_test/fiber_test.go (1 hunks)
  • otelfiber/semconv.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • otelfiber/fiber.go
Additional comments not posted (4)
otelfiber/semconv.go (1)

29-31: LGTM! The new conditional block correctly integrates custom metric attributes.

The changes are correct and logically sound.

otelfiber/config.go (2)

21-21: LGTM! The new field CustomMetricAttributes is correctly added to the config struct.

The changes are correct and logically sound.


102-108: LGTM! The new function WithCustomMetricAttributes is correctly added and integrated.

The changes are correct and logically sound.

otelfiber/otelfiber_test/fiber_test.go (1)

450-502: LGTM! The new test function TestCustomMetricAttributes is correctly added and provides adequate coverage.

The changes are correct and logically sound.

Copy link
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

LGTM

@hwo411
Copy link
Author

hwo411 commented Jul 22, 2024

Great! Let me push the README then

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (2)
otelfiber/README.md (2)

39-39: Correct the verb tense.

The verb "returned" should be in the present tense "returns" to fit the context better.

- Define a function to skip this middleware when returned true.
+ Define a function to skip this middleware when it returns true.
Tools
LanguageTool

[uncategorized] ~39-~39: This verb may not be in the correct tense. Consider changing the tense to fit the context better.
Context: ...a function to skip this middleware when returned true .| nil ...

(AI_EN_LECTOR_REPLACEMENT_VERB_TENSE)


45-45: Add missing comma.

A comma is missing before "and" in the description.

- Takes a function that will be called on every request and the returned string will become the span Name.
+ Takes a function that will be called on every request, and the returned string will become the span Name.
Tools
LanguageTool

[uncategorized] ~45-~45: Possible missing comma found.
Context: ...a function that will be called on every request and the returned string will become the...

(AI_HYDRA_LEO_MISSING_COMMA)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c1d9e50 and 8f3bc05.

Files selected for processing (1)
  • otelfiber/README.md (1 hunks)
Additional context used
LanguageTool
otelfiber/README.md

[uncategorized] ~39-~39: This verb may not be in the correct tense. Consider changing the tense to fit the context better.
Context: ...a function to skip this middleware when returned true .| nil ...

(AI_EN_LECTOR_REPLACEMENT_VERB_TENSE)


[uncategorized] ~45-~45: Possible missing comma found.
Context: ...a function that will be called on every request and the returned string will become the...

(AI_HYDRA_LEO_MISSING_COMMA)

Additional comments not posted (1)
otelfiber/README.md (1)

47-47: LGTM! Verify usage examples.

The addition of the WithCustomMetricAttributes parameter is consistent and well-documented.

Ensure that the usage examples in the documentation are updated to reflect this new parameter.

@ReneWerner87 ReneWerner87 merged commit 32c12f3 into gofiber:main Jul 23, 2024
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 [Feature]: Custom metric attributes for otelfiber
3 participants