这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@hgiasac
Copy link
Collaborator

@hgiasac hgiasac commented Nov 16, 2025

This pull request refactors the tracing middleware to improve OpenTelemetry semantic conventions usage and header handling. The main changes include replacing manual attribute construction with OpenTelemetry semantic attribute helpers, introducing a robust host/port parsing utility, and enhancing header attribute filtering to exclude tracing-related headers from span attributes.

OpenTelemetry semantic conventions and attribute handling:

  • Replaced manual construction of metric and span attributes with OpenTelemetry semantic conventions (semconv), including for HTTP methods, URLs, addresses, ports, request/response body sizes, protocol versions, user agent, and status codes. This standardizes telemetry data and improves compatibility. [1] [2] [3] [4] [5] [6] [7]

  • Exception and error attributes on spans now use semantic keys (exception.error, exception.stacktrace) for better error reporting and trace analysis. [1] [2]

Header attribute filtering:

  • Added excludedSpanHeaderAttributes to filter out tracing-related headers (e.g., traceparent, baggage, x-b3-*) from span attributes, reducing noise and potential data leaks in telemetry. [1] [2]

Host/port parsing utility:

  • Introduced SplitHostPort in utils.go for robust parsing of network addresses, supporting various formats and handling errors gracefully. This replaces previous manual parsing and improves reliability in extracting host and port information for telemetry. [1] [2] [3]

Other improvements:

  • Minor update to the MaskString function to mask sensitive data more consistently, and adjusted related test expectations. [1] [2]

These changes collectively improve the accuracy, consistency, and security of telemetry data collected by the middleware.

@hgiasac hgiasac requested a review from Copilot November 16, 2025 05:54
Copilot finished reviewing on behalf of hgiasac November 16, 2025 05:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the tracing middleware to adopt OpenTelemetry semantic conventions and introduces robust header filtering capabilities. The changes standardize telemetry data collection, improve host/port parsing reliability, and reduce noise in span attributes by filtering tracing-related headers.

Key changes:

  • Replaced manual attribute construction with OpenTelemetry semantic convention helpers (semconv) for HTTP methods, URLs, addresses, ports, body sizes, protocol versions, and status codes
  • Introduced excludedSpanHeaderAttributes map and updated SetSpanHeaderAttributes to filter out tracing headers (e.g., traceparent, baggage, x-b3-*) from span attributes
  • Added SplitHostPort utility function for robust parsing of network addresses in various formats (IPv4, IPv6, with/without ports)
  • Modified MaskString function to change masking pattern from 3+7 chars to 2+8 chars for strings >= 12 characters

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
utils.go Adds header exclusion map, updates SetSpanHeaderAttributes to filter tracing headers with improved attribute naming format, modifies MaskString pattern, and introduces SplitHostPort utility for parsing network addresses
utils_test.go Updates test expectation for masked authorization header to reflect new MaskString pattern (2+8 instead of 3+7)
middleware.go Refactors to use OpenTelemetry semantic conventions throughout, replaces manual host/port parsing with SplitHostPort, and updates exception attribute keys to use semantic convention helpers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hgiasac hgiasac merged commit a061784 into main Nov 16, 2025
1 check passed
@hgiasac hgiasac deleted the fix-header-attributes branch November 16, 2025 06:03
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