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

Expose opentracing start span options to allow tag customization #110

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

gruane-sq
Copy link
Collaborator

@gruane-sq gruane-sq commented Feb 17, 2024

Exposes the opentracing.StartSpanOption to allow callers to pass custom span tags. One use case is to allow control over Datadog's Unified Span Tagging. This is commonly done with database clients so that queries show as a different "service" in the Datadog interface, with their own Service Page that is tailored specifically to database interactions.

db.go Outdated
// SetStartSpanOption will apply the span option function to every opentracing span created by squalor
func SetStartSpanOption(spanOption opentracing.StartSpanOption) DBOption {
return func(db *DB) error {
if db.SpanOptions == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need the if since append will create the slice if needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could also make this function take varargs ...opentracing.StartSpanOption and append them all

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea - fixed

db.go Outdated
models map[reflect.Type]*Model
mappings map[reflect.Type]fieldMap
// Span option functions are applied to every span started by squalor, when OpentracingEnabled is true.
SpanOptions []opentracing.StartSpanOption
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be visible (capitalized)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope - made private

db.go Outdated
@@ -513,6 +526,7 @@ func NewDB(db *sql.DB, options ...DBOption) (*DB, error) {
IgnoreMissingCols: false,
Logger: nil,
OpentracingEnabled: false,
SpanOptions: make([]opentracing.StartSpanOption, 0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could probably initialize to nil just fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

@gruane-sq gruane-sq merged commit 462ac07 into square:master Feb 20, 2024
1 check passed
@gruane-sq gruane-sq deleted the start-span-option branch February 21, 2024 00:57
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.

4 participants