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

migrate go version from 1.19 -> 1.20, upgrade semiconv package version and fix deprecated usages... #1226

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

Conversation

alioktar
Copy link

@alioktar alioktar commented Feb 9, 2025

This pr represents version upgrades and deprecated usages fix for otelfiber package
Changes Includes :

  • go version upgrade
  • opentelemetry semi convention package version upgrade
  • usages fix in otelfiber package
  • removed WithServerName configuration because http.server_name don't using anymore on opentelemetry semi conventions

Summary by CodeRabbit

  • Refactor
    • Removed the server name configuration option, streamlining HTTP metrics and span status handling.
    • Updated attribute assignments for telemetry tracing and metrics to align with new conventions.
  • Chores
    • Upgraded OpenTelemetry dependencies to the latest semantic conventions.
  • Tests
    • Enhanced unit tests for HTTP status code handling and updated assertions to validate the new telemetry attribute names and values.

@alioktar alioktar requested a review from a team as a code owner February 9, 2025 17:47
@alioktar alioktar requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team February 9, 2025 17:47
Copy link
Contributor

coderabbitai bot commented Feb 9, 2025

Walkthrough

This pull request removes the WithServerName configuration option from the otelfiber middleware by eliminating the ServerName field and its setter function from the configuration. The documentation has been updated to reflect these changes. Additionally, the OpenTelemetry semantic conventions dependency has been upgraded (e.g., semconv from v1.12.0/v1.4.0 to v1.21.0), prompting updates to HTTP attribute keys and telemetry processing logic across the codebase. A new internal helper has been introduced to compute span statuses from HTTP status codes and span kinds.

Changes

File(s) Change Summary
otelfiber/README.md, otelfiber/config.go Removed the WithServerName configuration option and the ServerName field; updated WithPort documentation in config.
otelfiber/fiber.go, otelfiber/otelfiber_test/fiber_test.go, otelfiber/semconv.go Upgraded OpenTelemetry semconv dependency to v1.21.0; updated HTTP attribute keys and telemetry processing logic (e.g., response attributes, span status, renaming of httpFlavorAttribute).
otelfiber/internal/http.go Added new internal helper functions: SpanStatusFromHTTPStatusCodeAndSpanKind and isCode4xx for computing span statuses based on HTTP status codes and span kinds.
otelfiber/internal/http_test.go Introduced unit tests for isCode4xx and SpanStatusFromHTTPStatusCodeAndSpanKind functions to validate HTTP status code handling.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant M as Fiber Middleware
    participant I as Internal Helper
    participant OT as OpenTelemetry
    C->>+M: HTTP Request
    M->>+I: Compute Span Status (using HTTP status & span kind)
    I-->>-M: Span Status Result
    M->>OT: Record Telemetry Attributes (HTTP status, response size, etc.)
    M-->>C: HTTP Response
Loading

Suggested labels

✏️ Feature

Suggested reviewers

  • sixcolors
  • gaby
  • ReneWerner87
  • efectn

Poem

I'm a hopping coder, a little bunny on the run,
Skipping old configs beneath the rising sun.
Server names bid farewell, out of sight,
New telemetry dances in the code's soft light.
Fiber flows gracefully with updated tune,
Hexed by semconv's new, bright boon.
Hoppy changes make my circuits swoon! 🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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 ☢️ Bug Something isn't working 🧹 Updates labels Feb 9, 2025
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

🧹 Nitpick comments (2)
otelfiber/internal/http.go (1)

26-28: Consider adding a test for the helper function.

While the implementation is correct, adding unit tests would help ensure the 4xx status code range check remains accurate.

Would you like me to generate unit tests for the isCode4xx function?

otelfiber/semconv.go (1)

73-79: Consider caching protocol attributes.

Since protocol attributes are used in both metric and trace collection, consider caching them to avoid redundant computation.

+var (
+    httpProtocolNameAttr = semconv.NetworkProtocolName("http")
+    http11VersionAttr    = semconv.NetworkProtocolVersion("1.1")
+    http10VersionAttr    = semconv.NetworkProtocolVersion("1.0")
+)
+
 func httpNetworkProtocolAttributes(c *fiber.Ctx) []attribute.KeyValue {
-    httpProtocolAttributes := []attribute.KeyValue{semconv.NetworkProtocolName("http")}
+    httpProtocolAttributes := []attribute.KeyValue{httpProtocolNameAttr}
     if c.Request().Header.IsHTTP11() {
-        return append(httpProtocolAttributes, semconv.NetworkProtocolVersion("1.1"))
+        return append(httpProtocolAttributes, http11VersionAttr)
     }
-    return append(httpProtocolAttributes, semconv.NetworkProtocolVersion("1.0"))
+    return append(httpProtocolAttributes, http10VersionAttr)
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f60be7 and e07464b.

⛔ 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 (6)
  • otelfiber/README.md (0 hunks)
  • otelfiber/config.go (1 hunks)
  • otelfiber/fiber.go (5 hunks)
  • otelfiber/internal/http.go (1 hunks)
  • otelfiber/otelfiber_test/fiber_test.go (9 hunks)
  • otelfiber/semconv.go (3 hunks)
💤 Files with no reviewable changes (1)
  • otelfiber/README.md
🔇 Additional comments (11)
otelfiber/internal/http.go (1)

13-24: LGTM! The span status implementation follows OpenTelemetry specification.

The function correctly handles:

  • Invalid HTTP status codes
  • Success codes (1xx-3xx)
  • Special case for 4xx codes in server spans
otelfiber/semconv.go (2)

13-31: LGTM! Updated metric attributes align with latest OpenTelemetry conventions.

The changes correctly update the attribute keys and add protocol attributes.


33-71: LGTM! Trace attributes collection is comprehensive.

The implementation now includes additional attributes like request body size, URL components, and user agent.

otelfiber/config.go (1)

76-79: LGTM! Documentation update reflects semantic convention changes.

The comment correctly updates the attribute name from net.host.port to server.port to align with the latest OpenTelemetry conventions.

otelfiber/fiber.go (2)

132-135: LGTM! Response attributes follow latest OpenTelemetry conventions.

The implementation correctly uses the updated attribute keys.


155-155: LGTM! Span updates use new internal package.

The implementation correctly:

  • Uses the new response body size attribute key
  • Delegates span status computation to the internal package

Also applies to: 158-159

otelfiber/otelfiber_test/fiber_test.go (5)

27-27: LGTM! Semantic conventions package upgrade.

The upgrade to go.opentelemetry.io/otel/semconv/v1.21.0 aligns with the PR objectives to upgrade the OpenTelemetry semi-convention package.


303-309: LGTM! Updated metric attributes follow semantic conventions.

The metric attributes have been correctly updated to use the latest OpenTelemetry semantic convention functions:

  • Network protocol attributes using semconv.NetworkProtocolName and semconv.NetworkProtocolVersion
  • URL scheme using semconv.URLScheme
  • HTTP method using semconv.HTTPRequestMethodKey
  • Server details using semconv.ServerAddress and semconv.ServerPort
  • Response status using semconv.HTTPResponseStatusCode

Also applies to: 310-313


458-458: LGTM! Custom metric attributes updated to use semantic conventions.

The custom metric attributes have been correctly updated to use the semantic convention functions:

  • URL query parameters using semconv.URLQuery
  • Network and server attributes using appropriate semantic convention functions

Also applies to: 479-490


575-577: LGTM! Client IP attribute key updated.

The client IP attribute key has been updated to use client.address in accordance with the latest semantic conventions.


116-119: Verify the updated attribute keys align with OpenTelemetry specifications.

The attribute keys have been updated to follow the latest OpenTelemetry semantic conventions:

  • server.address for server identification
  • http.response.status_code for response status
  • http.request.method for HTTP method
  • url.path for request path
✅ Verification successful

🌐 Web query:

What are the latest OpenTelemetry semantic conventions for HTTP attributes?

💡 Result:

The latest OpenTelemetry HTTP semantic conventions (as of 2025) introduce stabilized attribute names and structures following a merger with Elastic Common Schema (ECS). Here's what developers need to know:

## Key Changes in HTTP Semantic Conventions
- **Stable Release**: HTTP conventions reached stability in November 2023 through alignment with ECS[1][3]
- **Attribute Renaming**:
  - `http.method` → `http.request.method`
  - `http.url` → `url.full`
  - `http.client_id` → `client.address`
  - `http.flavor` → `network.protocol.name`[1][9]
- **New Namespace Structure**: Attributes now follow clearer hierarchical naming (e.g., `http.request.header.content-type`)[3][6]

## Transition Requirements
Use environment variables to control convention versions:
```bash
OTEL_SEMCONV_STABILITY_OPT_IN=http       # Stable only
OTEL_SEMCONV_STABILITY_OPT_IN=http/dup   # Dual emission[5][6]
```

## Impacted Components
| Legacy Attribute | New Attribute | Stability |
|------------------|---------------|-----------|
| `http.host`      | `server.address` | Deprecated[9] |
| `http.target`    | `url.path` + `url.query` | Split[9] |
| `http.user_agent` | `user_agent.original` | Replaced[9] |

## Migration Considerations
1. Update Collector configurations using legacy attributes[1]
2. Modify transform/filter processors referencing old names[1]
3. Adapt dashboards and queries using HTTP attributes in visualization tools[1]
4. Check instrumentation libraries for stable releases (most now support v1.0)[7]

Official documentation recommends using the `@opentelemetry/semantic-conventions` npm package's stable entry point, which includes only finalized conventions[7][8]. For gradual migration, use the `http/dup` mode to emit both old and new attributes during transition periods[6].

The changes aim to improve cross-platform compatibility while maintaining backward compatibility through careful deprecation policies[3][10]. Monitoring OpenTelemetry release notes and provider-specific guidance (like Honeycomb's transition updates[1]) is recommended during migration.

Citations:

- 1: https://www.honeycomb.io/blog/opentelemetry-http-attributes
- 2: https://github.com/open-telemetry/semantic-conventions/releases
- 3: https://betterstack.com/community/guides/observability/opentelemetry-semantic-conventions/
- 4: https://docs.datadoghq.com/opentelemetry/schema_semantics/semantic_mapping/
- 5: https://opentelemetry.io/docs/specs/semconv/http/
- 6: https://opentelemetry.io/docs/specs/semconv/http/http-spans/
- 7: https://www.npmjs.com/package/@opentelemetry/semantic-conventions
- 8: https://opentelemetry.io/docs/specs/semconv/
- 9: https://opentelemetry.io/docs/specs/semconv/attributes-registry/http/
- 10: https://opentelemetry.io/docs/concepts/semantic-conventions/

Attribute Keys Are Consistent with the Latest Conventions

The updated keys in the test are in line with the current OpenTelemetry HTTP semantic conventions. Specifically:

  • "server.address" replaces the legacy "http.host".
  • "http.request.method" reflects the new nomenclature for HTTP methods.
  • "url.path" is used appropriately as part of the split of "http.target".
  • The use of "http.response.status_code" aligns with the updated request/response naming pattern.

All four attribute keys match the updated conventions as described in the latest documentation.

…ackage version and fix deprecated usages...
@alioktar alioktar force-pushed the otelfiber/version-upgrades-and-fixes branch from e07464b to 0de3bae Compare February 9, 2025 18:18
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

🧹 Nitpick comments (1)
otelfiber/internal/http_test.go (1)

44-56: Consider adding test cases for edge cases.

While the current test coverage is good, consider adding test cases for:

  • Status code 399 (edge of 3xx)
  • Status code 400 (start of 4xx)
  • Status code 499 (end of 4xx)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e07464b and 0de3bae.

⛔ 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 (0 hunks)
  • otelfiber/config.go (1 hunks)
  • otelfiber/fiber.go (5 hunks)
  • otelfiber/internal/http.go (1 hunks)
  • otelfiber/internal/http_test.go (1 hunks)
  • otelfiber/otelfiber_test/fiber_test.go (9 hunks)
  • otelfiber/semconv.go (3 hunks)
💤 Files with no reviewable changes (1)
  • otelfiber/README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • otelfiber/config.go
  • otelfiber/internal/http.go
🔇 Additional comments (11)
otelfiber/internal/http_test.go (2)

11-21: LGTM! Good test coverage for 4xx status codes.

The tests effectively validate both positive and negative cases for 4xx status code detection.


23-56: LGTM! Comprehensive error handling test cases.

The tests thoroughly cover various error scenarios:

  • Invalid HTTP status codes (600)
  • Ignored HTTP status codes (306)
  • Server errors (500)
otelfiber/semconv.go (4)

13-17: LGTM! Good initialization of protocol attributes.

The protocol attributes are correctly defined using the latest semantic conventions.


19-37: LGTM! Clean implementation of metric attributes collection.

The function correctly collects and combines protocol attributes with other server metrics.


39-77: LGTM! Comprehensive trace attributes collection.

The function effectively collects all required trace attributes including URL components and user agent.


79-85: LGTM! Improved protocol attributes handling.

The refactored function now returns a slice of attributes, making it more flexible and maintainable.

otelfiber/fiber.go (2)

132-136: LGTM! Clean response attributes construction.

The response attributes are correctly constructed using the latest semantic conventions.


155-159: LGTM! Improved span status handling.

The code now uses the internal package for span status determination, which provides better encapsulation.

otelfiber/otelfiber_test/fiber_test.go (3)

302-309: LGTM! Comprehensive request attributes testing.

The test correctly validates all required request attributes using the latest semantic conventions.


310-314: LGTM! Updated response attributes testing.

The test properly validates response attributes with the new semantic conventions.


478-486: LGTM! Complete metric attributes testing.

The test thoroughly validates all metric attributes including protocol, URL, and server information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
☢️ Bug Something isn't working 🧹 Updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant