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

upgrade otelfiber to fiber v3 #1163

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

heisGarvit
Copy link

@heisGarvit heisGarvit commented Aug 11, 2024

PR contains upgrade of otelfiber to v3 for compatibility with fiber v3

Summary by CodeRabbit

  • New Features

    • Upgraded the Fiber middleware from version 2 to version 3, enhancing compatibility with the latest framework.
    • Updated example implementations to reflect new import paths and function signatures.
  • Bug Fixes

    • Adjusted function signatures to improve context management and performance, including changes from pointer to value receivers for fiber.Ctx.
  • Documentation

    • Revised the README to provide updated installation instructions and compatibility notes for the new Fiber version and Go version requirements.

@heisGarvit heisGarvit requested a review from a team as a code owner August 11, 2024 07:04
@heisGarvit heisGarvit requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team August 11, 2024 07:04
Copy link
Contributor

coderabbitai bot commented Aug 11, 2024

Walkthrough

The otelfiber package has been updated to support Fiber v3, requiring changes to function signatures and import paths. Notably, context handling has shifted from pointer receivers to value receivers, affecting middleware implementations. Compatibility with Go has also been updated from version 1.19 to 1.21. Overall, these changes enhance functionality and align with the latest versions of both the Fiber framework and OpenTelemetry conventions.

Changes

Files Change Summary
otelfiber/README.md Updated usage and compatibility notes; changed function signatures from pointer to value type.
otelfiber/config.go Modified function signatures to accept fiber.Ctx instead of *fiber.Ctx; updated options.
otelfiber/doc.go Changed import path to otelfiber/v3.
otelfiber/example/server.go Updated import paths; changed context parameter types; updated service name for tracing.
otelfiber/fiber.go Revised import paths; adjusted context handling in middleware functions.
otelfiber/otelfiber_test/fiber_test.go Updated import paths; changed context parameter types in tests; increased test timeout.
otelfiber/semconv.go Updated functions to use fiber.Ctx; modified method calls for HTTP scheme retrieval.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant Middleware

    Client->>Server: Request
    Server->>Middleware: Pass context
    Middleware-->>Server: Process context
    Server-->>Client: Response
Loading

🐰 In fields of green where changes bloom,
A hop of joy, dispelling gloom.
With Fiber's strength, we leap and play,
New paths to run, a brighter day!
Let's celebrate with hops and cheer,
For updates bring us ever near! 🌼


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.

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 (4)
otelfiber/example/server.go (1)

37-37: Update middleware span name formatter usage.

The commented-out code shows an example of customizing span names with the new fiber.Ctx type. Ensure any custom middleware logic aligns with Fiber v3.

- //app.Use(otelfiber.Middleware(otelfiber.WithSpanNameFormatter(func(ctx fiber.Ctx) string {
- //	return fmt.Sprintf("%s - %s", ctx.Method(), ctx.Route().Path)
- //})))
+ // Example: Customize span name with Fiber v3
+ // app.Use(otelfiber.Middleware(otelfiber.WithSpanNameFormatter(func(ctx fiber.Ctx) string {
+ //   return fmt.Sprintf("%s - %s", ctx.Method(), ctx.Route().Path)
+ // })))
otelfiber/README.md (3)

17-17: Use a heading instead of emphasis for the note.

The note about the Go version requirement should use a heading for better visibility and structure.

- **Note: Requires Go 1.21 and above**
+ ### Note
+ Requires Go 1.21 and above
Tools
Markdownlint

17-17: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


23-23: Specify the language for the code block.

The installation command should specify the language for syntax highlighting.

- ```
+ ```shell
Tools
Markdownlint

23-23: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


39-39: Clarify the description for WithNext.

The description for the WithNext function should clarify the context of "returned true."

- 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)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c62abb2 and 4b050c7.

Files ignored due to path filters (4)
  • otelfiber/example/go.mod is excluded by !**/*.mod
  • otelfiber/example/go.sum is excluded by !**/*.sum, !**/*.sum
  • otelfiber/go.mod is excluded by !**/*.mod
  • otelfiber/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (7)
  • otelfiber/README.md (4 hunks)
  • otelfiber/config.go (5 hunks)
  • otelfiber/doc.go (1 hunks)
  • otelfiber/example/server.go (3 hunks)
  • otelfiber/fiber.go (4 hunks)
  • otelfiber/otelfiber_test/fiber_test.go (18 hunks)
  • otelfiber/semconv.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • otelfiber/doc.go
Additional context used
Markdownlint
otelfiber/README.md

17-17: null
Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


23-23: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


66-66: Column: 1
Hard tabs

(MD010, no-hard-tabs)


68-68: Column: 1
Hard tabs

(MD010, no-hard-tabs)


69-69: Column: 1
Hard tabs

(MD010, no-hard-tabs)


70-70: Column: 1
Hard tabs

(MD010, no-hard-tabs)


71-71: Column: 1
Hard tabs

(MD010, no-hard-tabs)


73-73: Column: 1
Hard tabs

(MD010, no-hard-tabs)


74-74: Column: 1
Hard tabs

(MD010, no-hard-tabs)


75-75: Column: 1
Hard tabs

(MD010, no-hard-tabs)


76-76: Column: 1
Hard tabs

(MD010, no-hard-tabs)


94-94: Column: 1
Hard tabs

(MD010, no-hard-tabs)


95-95: Column: 1
Hard tabs

(MD010, no-hard-tabs)


96-96: Column: 1
Hard tabs

(MD010, no-hard-tabs)


98-98: Column: 1
Hard tabs

(MD010, no-hard-tabs)

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)

Additional comments not posted (24)
otelfiber/example/server.go (5)

10-12: Update import paths for Fiber v3.

The import paths have been updated to use Fiber v3 and its associated otelfiber middleware. Ensure that all references in the code align with these new import paths.


20-20: Update OpenTelemetry semantic conventions.

The semantic version of OpenTelemetry conventions has been updated to v1.12.0. Ensure compatibility with this version throughout the codebase.


43-43: Update handler function signature.

The handler function now uses fiber.Ctx as a value receiver. Ensure all handler functions are updated accordingly.


47-47: Update handler function signature and JSON response.

The handler function now uses fiber.Ctx as a value receiver. Also, ensure that the JSON response correctly maps keys to values.


68-68: Update service name in tracer provider.

The service name in the tracer provider has been updated to "my-service-fiber-v3". Ensure this change is consistent with the application's service naming conventions.

otelfiber/semconv.go (6)

7-7: Update import path for Fiber v3.

The import path for Fiber has been updated to version 3. Ensure all references in the code align with this new import path.


13-13: Transition to value receiver for fiber.Ctx.

The function httpServerMetricAttributesFromRequest now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.


17-17: Update method call to c.Scheme().

The method call has been updated from c.Protocol() to c.Scheme(). Ensure this change aligns with the desired functionality and the new Fiber v3 API.


36-36: Transition to value receiver for fiber.Ctx.

The function httpServerTraceAttributesFromRequest now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.


44-44: Update method call to c.Scheme().

The method call has been updated from c.Protocol() to c.Scheme(). Ensure this change aligns with the desired functionality and the new Fiber v3 API.


77-77: Transition to value receiver for fiber.Ctx.

The function httpFlavorAttribute now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.

otelfiber/config.go (6)

4-4: Update import path for Fiber v3.

The import path for Fiber has been updated to version 3. Ensure all references in the code align with this new import path.


13-21: Transition to value receivers for fiber.Ctx in config struct.

The config struct now uses fiber.Ctx as a value receiver for several functions. Verify that these changes do not affect the intended behavior of the middleware.


38-38: Transition to value receiver for fiber.Ctx.

The function WithNext now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.


71-71: Transition to value receiver for fiber.Ctx.

The function WithSpanNameFormatter now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.


96-96: Transition to value receiver for fiber.Ctx.

The function WithCustomAttributes now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.


104-104: Transition to value receiver for fiber.Ctx.

The function WithCustomMetricAttributes now uses fiber.Ctx as a value receiver. Verify that this change does not affect the intended behavior of the function.

otelfiber/fiber.go (4)

8-9: Update import paths for Fiber v3 and utils.

The import paths have been correctly updated to reflect the new versions of Fiber and utils. Ensure that all usages of these packages are compatible with the new versions.


21-21: Update instrumentation name constant.

The instrumentationName constant has been updated to include the version. This change is correct and aligns with the new versioning scheme.


179-179: Update default span name formatter function signature.

The defaultSpanNameFormatter function now uses fiber.Ctx instead of *fiber.Ctx. This change aligns with the updated middleware signature.


83-83: Shift from pointer to value receiver for fiber.Ctx.

The middleware function signature now uses fiber.Ctx instead of *fiber.Ctx. This change is significant and may impact performance or memory usage. Ensure that all middleware logic is compatible with this change.

otelfiber/otelfiber_test/fiber_test.go (3)

11-12: Update import paths for Fiber v3 and otelfiber.

The import paths have been correctly updated to reflect the new versions of Fiber and otelfiber. Ensure that all test cases are compatible with the new versions.


31-31: Update instrumentation name constant.

The instrumentationName constant has been updated to include the version. This change is correct and aligns with the new versioning scheme.


40-40: Shift from pointer to value receiver for fiber.Ctx in test cases.

The test cases now use fiber.Ctx instead of *fiber.Ctx. This change is significant and may impact how context is handled in tests. Ensure that all test logic is compatible with this change.

Also applies to: 57-57, 73-73, 77-77, 100-100, 135-135, 157-157, 163-163, 175-175, 201-201, 230-230, 295-295, 416-416, 424-424, 429-429, 464-464, 472-472, 513-513, 517-517, 537-537, 547-547, 571-571

@gaby
Copy link
Member

gaby commented Aug 11, 2024

@heisGarvit v3 is still in beta, middlewares will be upgraded once we are closer to release.

@heisGarvit
Copy link
Author

@gaby is there any plan for beta release of v3 middleware? So that users of fiber v3 can use opentelemetry to track performance of upcoming release?

"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/utils"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/utils/v2"
"go.opentelemetry.io/otel/attribute"
semconv "go.opentelemetry.io/otel/semconv/v1.12.0"
Copy link

Choose a reason for hiding this comment

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

Do you plan to ugprade semconv version? One notable change from 1.21 is that http.server.request.duration now has unit of seconds.

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/metrics/semantic_conventions/http-metrics.md

vs

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/metrics/semantic_conventions/http-metrics.md

(I also wonder if this upgrade should be done for fiber 2)

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