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: update go.opentelemetry.io/otel/semconv to v1.26.0 #1175

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

Conversation

RyabovNick
Copy link

@RyabovNick RyabovNick commented Sep 11, 2024

PR updates the otelfiber package to use the actual OpenTelemetry semantic conventions by upgrading to go.opentelemetry.io/otel/semconv/v1.26.0. As part of this update, several attributes that were previously in use have been deprecated and replaced.

This leads to many changes because several current attribute names have been deprecated.

http.server_name and net.host.name were both replaced by server.address. I believe that service.name is the most suitable replacement for what was meant by the ServerName field.

The minimum Go version will be bumped as well.

Fixes #1174

P.S. If everything looks fine, I'll update the workflow and README accordingly.

Summary by CodeRabbit

  • New Features

    • Introduced a Status function for enhanced tracing capabilities based on HTTP status codes.
    • Added new attributes for tracking HTTP request and response metrics in line with OpenTelemetry standards.
  • Improvements

    • Renamed ServerName to ServiceName for better alignment with service-oriented terminology.
    • Updated metric names and descriptions to adhere to the latest OpenTelemetry conventions.
    • Enhanced clarity and consistency in the handling of telemetry data attributes.
  • Bug Fixes

    • Corrected attribute names in tests to reflect updated OpenTelemetry standards, ensuring accurate metrics collection.

@RyabovNick RyabovNick requested a review from a team as a code owner September 11, 2024 18:34
@RyabovNick RyabovNick requested review from gaby, sixcolors, ReneWerner87 and efectn and removed request for a team September 11, 2024 18:34
Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The pull request introduces significant updates to the otelfiber package, focusing on aligning with the latest OpenTelemetry semantic conventions. Key changes include renaming fields and functions for clarity, updating metric names and types, and enhancing tracing capabilities. The modifications aim to improve the consistency and accuracy of telemetry data collection, ensuring better compliance with OpenTelemetry standards.

Changes

Files Change Summary
otelfiber/config.go, otelfiber/fiber.go, otelfiber/semconv.go Renamed ServerName to ServiceName, updated metric names and descriptions, introduced new constants, and enhanced metric handling.
otelfiber/otelfiber_test/fiber_test.go Updated tests to reflect renaming from serverName to serviceName and adjusted assertions for new attribute names.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Middleware
    participant Metrics
    participant Tracing

    Client->>Middleware: Send HTTP Request
    Middleware->>Metrics: Record Request Duration
    Middleware->>Tracing: Start Span
    Tracing->>Metrics: Log Attributes
    Middleware->>Client: Send HTTP Response
    Metrics->>Tracing: End Span
Loading

Assessment against linked issues

Objective Addressed Explanation
Update otelfiber to use actual OpenTelemetry semantic conventions (#1174)
Rename ServerName to ServiceName in configuration (#1159)
Update metric units from milliseconds to seconds (#1174)

Possibly related PRs

Suggested labels

✏️ Feature

Poem

🐇 In the meadow where data flows,
Changes bloom like springtime's prose.
Metrics dance with names anew,
Tracing paths both bright and true.
With each hop, we celebrate,
OpenTelemetry, oh how great! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db22edc and f35208f.

Files ignored due to path filters (2)
  • otelfiber/go.mod is excluded by !**/*.mod
  • otelfiber/go.sum is excluded by !**/*.sum, !**/*.sum
Files selected for processing (4)
  • otelfiber/config.go (2 hunks)
  • otelfiber/fiber.go (7 hunks)
  • otelfiber/otelfiber_test/fiber_test.go (13 hunks)
  • otelfiber/semconv.go (4 hunks)
Additional comments not posted (35)
otelfiber/semconv.go (6)

11-11: LGTM!

The import statement has been updated to use the latest version of the go.opentelemetry.io/otel/semconv package (v1.26.0), which aligns with the PR objective.


16-27: LGTM!

The changes in the httpServerMetricAttributesFromRequest function align with the PR objective of updating the attribute keys to the latest OpenTelemetry semantic conventions. The changes are consistent with the AI-generated summary.


Line range hint 39-68: LGTM!

The changes in the httpServerTraceAttributesFromRequest function align with the PR objective of updating the attribute keys to the latest OpenTelemetry semantic conventions. The changes are consistent with the AI-generated summary.


79-84: LGTM!

The networkProtocolVersion function has been updated to align with the latest OpenTelemetry semantic conventions. The changes are consistent with the AI-generated summary.


Line range hint 86-114: Skipping the review of the HasBasicAuth function.

The HasBasicAuth function has not been changed and is not relevant to the PR objective.


Line range hint 1-114: Verify the impact of the changes on the codebase.

The changes involve updating the attribute keys to the latest OpenTelemetry semantic conventions and are localized to the otelfiber package. However, it's important to ensure that all the references to the updated functions and attributes are updated accordingly.

Run the following script to verify the impact of the changes on the codebase:

Verification successful

Verification Successful: Changes to OpenTelemetry Semantic Conventions Integrated

The new OpenTelemetry semantic convention keys are consistently used across the codebase, including in example and test files. This confirms that the changes have been successfully integrated.

  • Files with updated keys:
    • otelfiber/semconv.go
    • otelfiber/example/server.go
    • otelfiber/otelfiber_test/fiber_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the changes on the codebase.

# Test: Search for references to the updated functions and attributes.
# Expect: All references should be updated to use the new names.
rg --type go -A 5 $'httpFlavorAttribute|semconv.HTTPMethodKey|semconv.NetHostNameKey|semconv.HTTPServerNameKey|semconv.HTTPURLKey|semconv.HTTPUserAgentKey|semconv.HTTPClientIPKey'

Length of output: 180


Script:

#!/bin/bash
# Description: Verify the usage of the new semantic convention keys in the codebase.

# Test: Search for references to the new semantic convention keys used in the provided code snippet.
rg --type go -A 5 $'semconv.HTTPRequestMethodKey|semconv.URLScheme|semconv.ServerAddress|semconv.ServerPort|semconv.ServiceName|semconv.URLOriginal|semconv.URLPath|semconv.URLQuery|semconv.UserAgentOriginal|semconv.NetworkTransportTCP|semconv.EnduserIDKey|semconv.ClientAddress'

Length of output: 4775

otelfiber/config.go (3)

18-18: LGTM: Field renaming aligns with OpenTelemetry semantic conventions.

The renaming of the ServerName field to ServiceName in the config struct improves clarity and consistency with the latest OpenTelemetry standards, as indicated in the PR summary.


77-81: LGTM: Function changes align with the ServiceName field update.

The following changes to the WithServerName function are approved:

  • Renaming the function to WithServiceName to match the ServiceName field in the config struct.
  • Updating the function comment to clarify that the service.name attribute is being set.
  • Renaming the serverName parameter to serviceName.
  • Updating the field assignment to match the new ServiceName field.

These changes improve clarity and consistency with the ServiceName field update in the config struct.


85-88: LGTM: Comment update aligns with OpenTelemetry semantic conventions.

The update to the WithPort function comment, mentioning the server.port attribute instead of net.host.port, aligns with the latest OpenTelemetry semantic conventions, as indicated in the PR summary.

otelfiber/fiber.go (12)

14-14: LGTM!

The changes to the import statements are approved.

Also applies to: 17-17


28-30: LGTM!

The changes to declare the ExplicitBucketBoundaries variable with the recommended bucket boundaries for the http.server.request.duration metric are approved.


56-56: LGTM!

The changes to update the httpServerDuration metric to use the constants from the semconv package and the ExplicitBucketBoundaries variable are approved.


60-60: LGTM!

The changes to update the httpServerRequestSize metric to use the constants from the semconv package are approved.


64-64: LGTM!

The changes to update the httpServerResponseSize metric to use the constants from the semconv package are approved.


68-68: LGTM!

The changes to update the httpServerActiveRequests metric to use the constants from the semconv package are approved.


128-131: LGTM!

The changes to update the responseAttrs slice to use the functions and constants from the semconv package are approved.


147-147: LGTM!

The change to record the httpServerDuration metric in seconds instead of milliseconds is approved.


156-156: LGTM!

The change to update the span attributes to use the semconv.HTTPResponseBodySize function is approved.


160-160: LGTM!

The change to update the span status to use the Status function is approved.


179-190: LGTM!

The addition of the Status function is approved. The function is well-structured and follows the OpenTelemetry specification for span status codes.


25-25: Verify the usage of the new constant.

A new constant AttributeNameHTTPRequestHeaderContentLength is introduced. Please ensure that this constant is being used correctly in the code to track the content length of HTTP request headers.

Run the following script to verify the constant usage:

Verification successful

Constant usage verified successfully.

The constant AttributeNameHTTPRequestHeaderContentLength is used appropriately in otelfiber/semconv.go to track the content length of HTTP request headers. This confirms its intended purpose and correct usage in the codebase.

  • File: otelfiber/semconv.go
  • Usage: Within a call to attribute.StringSlice.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the constant `AttributeNameHTTPRequestHeaderContentLength`.

# Test: Search for the constant usage. Expect: At least one occurrence.
rg --type go -A 5 $'AttributeNameHTTPRequestHeaderContentLength'

Length of output: 1149

otelfiber/otelfiber_test/fiber_test.go (14)

Line range hint 33-50: LGTM!

The code changes are approved.


Line range hint 52-69: LGTM!

The code changes are approved.


Line range hint 71-89: LGTM!

The code changes are approved.


Line range hint 91-126: LGTM!

The code changes are approved. The test correctly uses the updated otelfiber.WithServiceName and verifies the updated trace attributes.


Line range hint 128-154: LGTM!

The code changes are approved.


Line range hint 156-173: LGTM!

The code changes are approved.


Line range hint 175-190: LGTM!

The code changes are approved.


Line range hint 192-224: LGTM!

The code changes are approved.


Line range hint 226-255: LGTM!

The code changes are approved.


Line range hint 257-283: LGTM!

The code changes are approved.


Line range hint 285-322: LGTM!

The code changes are approved. The test correctly uses the updated otelfiber.WithServiceName and verifies the updated metric attributes.


Line range hint 409-451: LGTM!

The code changes are approved.


Line range hint 453-504: LGTM!

The code changes are approved. The test correctly uses the updated otelfiber.WithServiceName.


Line range hint 569-592: LGTM!

The code changes are approved.


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 [Feature]: Update otelfiber to use actual OpenTelemetry semantic conventions
1 participant