-
Notifications
You must be signed in to change notification settings - Fork 8
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
move default attributes to separate macro #5
move default attributes to separate macro #5
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5 +/- ##
=======================================
+ Coverage 0% 100% +100%
=======================================
Files 1 1
Lines 5 5
=======================================
+ Hits 0 5 +5
+ Misses 5 0 -5
Continue to review full report at Codecov.
|
lib/opencensus/trace.ex
Outdated
Wraps the given block in a tracing child span with the given label/name, optional attributes and | ||
includes default attributes of line, module, file and function name in the span data. | ||
""" | ||
defmacro with_child_span_defaults(label, attributes \\ quote(do: %{}), do: block) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about distinction. I would rather allow setting attributes
to %{file: nil}
to prevent it from sending to the reporter. Alternatively we could make default attributes default and with_child_span_naked/2-3
macro for handling it without defaults.
I'm all for explicitness in cases like this. I feel like with more macrology we achieve the same without having two macros. Having two macros is a compile-time dispatch anyway. So maybe we could have an optional parameter, like include_default_attributes: nil. Or allowing attributes argument to be also a tuple/list like {(:line, :module}, } or [:line, :module] or [:line, :module, map]. with_child_span("my-important-span", [:line, :module]) do
end
## or
with_child_span("my-important-span", [:line, :module, %map]) do
end |
Hm, I think I like that idea of a list of attributes you can tell it to include, and maybe in addition to individual ones like |
yep, like I have :default as a shortcut for all built in prometheus collectors |
@deadtrickster I'm not sure how to do it besides a naive way. Got any pointers on what this should look like to be a macro that the code it generates only builds a map of the requested values, instead of building the whole map and filtering or always iterating over all possibilities and matching on the ones requested? Figure as a macro it should be able to just output code that only does anything with the requested attributes. |
If I understand you correctly, I would do it like this:
Highlights - iterate at compile time, Map.put only requested stuff. should be a var not map itself. We initialize it with provided attributes map, if any. |
a6caf0d
to
1feef28
Compare
1feef28
to
03c00ca
Compare
I gave up on getting the list idea to work. So I've tried something different that is simply an additional macro ( If no one is happy with this one either then I'll revert to the old way of defaulting to having all the attributes and publish as is. This version makes me think it should be offered to the Erlang version as well. have: -define(ATTRS(Attributes), Attributes#{module => ?MODULE, function => ...}). |
@tsloughter I was thinking more about macro in form of: -define(WITH_CHILD_SPAN(Name, Body), ocp:with_child_span(Name, #{
module => ?MODULE,
line => ?LINE,
file => ?FILE,
function => lists:concat([?FUNCTION_NAME, "/", integer_to_list(?FUNCTION_ARITY)]},
fun() -> Body end)). |
test "verify attributes", _state do | ||
:application.load(:opencensus) | ||
:application.set_env(:opencensus, :send_interval_ms, 1) | ||
:application.set_env(:opencensus, :reporter, {PidAttributesReporter, self()}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Elixir's Application
module to be more idiomatic.
@deadtrickster @hauleth thoughts on this latest PR? @deadtrickster were you able to try your idea? |
No, mad week, tomorrow. |
Default attributes, see also #5
I am not fan of this approach, I would much better like the "Elixir logger" approach, where we can pass |
I don't really like this, but it is the only thing I've been able to come up with so far.
Because traces should have a near zero cost I am hesitant to have anything included by default that is not absolutely necessary to fulfill the spec.
In a perfect world there would be a way for at run time the user to define what attributes from these defaults are to be included in each span, but I don't know of one that doesn't involve looking up application env data or some other ets table (maybe
persistent_term
would work in the future).Open to alternatives.