Skip to content

Conversation

@vpranckaitis
Copy link

This commit adds a middleware option that supplies StartSpanOptions for StartSpan() call.

Concrete use case where this is useful: adding additional tags to the span through opentracing.Tag{} option, so that those tags could be used for deciding whether to sample this span.

@vpranckaitis
Copy link
Author

@lucacome drawing your attention to this since you made most of the recent contributions. Does this change make sense?

@lucacome lucacome requested a review from Copilot April 1, 2025 18:27
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 PR adds a middleware option to supply custom StartSpanOptions for tracing, enabling users to append additional tags (e.g. via opentracing.Tag) to spans for dynamic sampling decisions.

  • Introduces the MWStartSpanOptions middleware option and its corresponding helper function.
  • Adds a new test (TestStartSpanOptionsOption) to verify that the custom StartSpanOptions are correctly applied.
  • Updates the MiddlewareFunc and supporting collectStartSpanOptions function in server.go to integrate the new option.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
nethttp/server_test.go New test case added to validate the behavior of the StartSpanOptions.
nethttp/server.go New MWStartSpanOptions option added and integrated into the middleware.
Comments suppressed due to low confidence (2)

nethttp/server_test.go:250

  • [nitpick] Using the string literal "" to represent a missing tag in the test may lead to confusion. Consider using an empty string or a different sentinel value to clearly indicate the absence of the tag.
if !ok {

nethttp/server.go:183

  • [nitpick] The default RPCServerOption is prepended before user-supplied options, which may limit users' ability to override its behavior. Consider documenting the ordering or allowing user options to take precedence if intended.
startSpanOptions = append(startSpanOptions, mwStartSpanOptions...)

@vpranckaitis
Copy link
Author

@lucacome any comments? This one from copilot seem like a false-positive:

[nitpick] Using the string literal "" to represent a missing tag in the test may lead to confusion. Consider using an empty string or a different sentinel value to clearly indicate the absence of the tag.

The test already uses "<nil>" sentinel value.

@vpranckaitis
Copy link
Author

@lucacome in case you do not have time, maybe there's someone else who could do the review of this PR?

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