Code Monkey home page Code Monkey logo

Comments (5)

ferd avatar ferd commented on July 19, 2024

right, because the case expression is fully local, the branch is unique to each call-site.

I'm noticing that we already do some dynamic dispatch on otel_counter:add/4:

-spec add(
otel_ctx:t(), otel_meter:t() | otel_instrument:t(),
otel_instrument:name() | pos_integer() | float(),
pos_integer() | float() | opentelemetry:attributes_map()) -> ok.
add(Ctx, Instrument=#instrument{module=Module}, Number, Attributes) ->
Module:record(Ctx, Instrument, Number, Attributes);
add(Ctx, Meter, Name, Number) ->
otel_meter:record(Ctx, Meter, Name, Number).

I don't think adding a similar match in add/5 would be a problem, if anything it may increase consistency?

from opentelemetry-erlang.

tsloughter avatar tsloughter commented on July 19, 2024

The problem is the use of ?MODULE. We'd have to always pass the module for the meter to maybe be looked up in the counter module.

from opentelemetry-erlang.

ferd avatar ferd commented on July 19, 2024

An alternative is to make it a sort of "private API" function that the macro uses to create a layer of indirection but passes the union of all required context to.

like

-define(counter_add(NameOrInstrument, Number, Attributes),
        otel_counter:'_macro_helper_add'(otel_ctx:get_current(), ?current_meter, NameOrInstrument, Number, Attributes)).
        
% [...] within otel_counter, maybe?
'_macro_helper_add'(Ctx, Meter, NameOrInstrument, Number, Attributes) ->
        case is_atom(NameOrInstrument) of 
            true -> 
               add(Ctx, Meter, NameOrInstrument, Number, Attributes); 
            false -> 
               add(Ctx, NameOrInstrument, Number, Attributes) 
        end).

This looks like hot garbage internally but keeps macro usage unchanged.

I would however say that the arity confusion likely transfers to users of the app who aren't quite sure when to pass in the right data types?

from opentelemetry-erlang.

tsloughter avatar tsloughter commented on July 19, 2024

Hm, interesting idea.

Yea, arity confusion. Have messed that up a few places. Maybe a reason to make it separate calls. ?instrument_counter_add(...).

from opentelemetry-erlang.

ferd avatar ferd commented on July 19, 2024

Yeah separate calls would have a clear demarcation of type signatures and split docs automatically. Sounds like it's a bit wordier but clearer for usage.

from opentelemetry-erlang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.