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

NH-90184: add doc for add_tracer api call #174

Merged
merged 11 commits into from
Jan 8, 2025
Merged

NH-90184: add doc for add_tracer api call #174

merged 11 commits into from
Jan 8, 2025

Conversation

xuan-cao-swi
Copy link
Contributor

Description

Test (if applicable)

@xuan-cao-swi xuan-cao-swi marked this pull request as ready for review January 6, 2025 15:28
@xuan-cao-swi xuan-cao-swi requested a review from a team as a code owner January 6, 2025 15:28
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

I reran one of the failed 3.1.0 tests and it still failed, could you take a look?

Regarding the README, i think add_tracer belongs in the convenience category, so how about updating that section to talk both about our in_span and our add_tracer methods.

And replace the introduction part To instrument a custom function outside the default scope... (which i think is a given, that if a customer bothers using the API, it's because they'd like to instrument something not covered by autoinsrumentation) with how add_tracer should be used, e.g. does it:

And we need the docstring in the source code so things show up in RubyDoc.

@xuan-cao-swi
Copy link
Contributor Author

And replace the introduction part To instrument a custom function outside the default scope... (which i think is a given, that if a customer bothers using the API

Updated.

failed 3.1.0 tests

It's caused by old activerecord gem inside the marginalia test case. It's removed so I just remove the gemfile as well (it's done in pg dbo pr).

@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 7, 2025 17:23
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

Getting close! Made a few wording changes and one larger change/question on the instance vs class example.

Also, how about the docstring (or are you waiting for this README content to finish revising before adding)?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 100 to 109
# instrument class function create_session
def create_session(user)
end
add_tracer :create_session, 'custom_name', { attributes: { 'foo' => 'bar' }, kind: :consumer }

# instrument instance function self.create_session
def self.create_session(user)
end

class << self
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# instrument class function create_session
def create_session(user)
end
add_tracer :create_session, 'custom_name', { attributes: { 'foo' => 'bar' }, kind: :consumer }
# instrument instance function self.create_session
def self.create_session(user)
end
class << self
def create_session(user)
end
def self.create_session(user)
end
# instrument instance method create_session
add_tracer :create_session, 'custom_name', { attributes: { 'foo' => 'bar' }, kind: :consumer }
# instrument class method create_session
class << self

Copy link
Contributor

Choose a reason for hiding this comment

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

I think create_session is the instance method, while self.create_session is the class method. And is the include SolarWindsAPM::API::Tracer on line 93 needed by the "instrument instance method" usage? It might be clearer if we just show the instrument instance vs class method as two separate snippets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean like putting them in separate code block?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, how about the docstring

Updated

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, i mean two separate code blocks, because currently it's unclear where include SolarWindsAPM::API::Tracer is needed for each scenario--the current example has it once at the start of class definition, then again via the class << self construct. If we keep a single code block example it would be good to clarify why.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

xuan-cao-swi and others added 6 commits January 7, 2025 17:38
@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 7, 2025 22:54
README.md Outdated Show resolved Hide resolved
README.md Outdated
Comment on lines 100 to 109
# instrument class function create_session
def create_session(user)
end
add_tracer :create_session, 'custom_name', { attributes: { 'foo' => 'bar' }, kind: :consumer }

# instrument instance function self.create_session
def self.create_session(user)
end

class << self
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, i mean two separate code blocks, because currently it's unclear where include SolarWindsAPM::API::Tracer is needed for each scenario--the current example has it once at the start of class definition, then again via the class << self construct. If we keep a single code block example it would be good to clarify why.

@@ -14,6 +14,37 @@ def self.included(base)
end

module ClassMethods
# Helper function to instrument custom function
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we be consistent and just use "method" instead of sometimes "function"? Please check for all instances in this docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use method

#
# * +method_name+ - (String) A non-empty string that match the function name that need to be instrumented
# * +span_name+ - (String, optional, default = method_name) A non-empty string that define the span name (default to method_name)
# * +options+ - (Hash, optional, default = {}) A hash with desired attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

and span kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

span kind is part of options hash. Updated the docstring.

# * +span_name+ - (String, optional, default = method_name) A non-empty string that define the span name (default to method_name)
# * +options+ - (Hash, optional, default = {}) A hash with desired attributes
#
# === Example:
Copy link
Contributor

Choose a reason for hiding this comment

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

in this example there is no include SolarWindsAPM::API::Tracer, should there be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated.

xuan-cao-swi and others added 2 commits January 8, 2025 10:09
@xuan-cao-swi xuan-cao-swi requested a review from cheempz January 8, 2025 17:18
Copy link
Contributor

@cheempz cheempz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @xuan-cao-swi!

@xuan-cao-swi xuan-cao-swi merged commit fbfbffb into main Jan 8, 2025
14 checks passed
@xuan-cao-swi xuan-cao-swi deleted the NH-90184 branch January 8, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants