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

[cowboy instrumenter] Allow users to set custom attributes on span start #128

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

albertored
Copy link
Contributor

@albertored albertored commented Nov 19, 2022

Maybe better to get this configuration parameter from the setup function instead of application env but for now this PR it's a draft waiting for comments.

The use case is to be able to filter spans with a sampler based on user attributes that, if added after span creation, are not present when the sampling decision is taken.

See also discussion on slack

@tsloughter
Copy link
Member

I think this makes sense, just needs to, as you mention, not be read from the environment on every request but once in setup.

@albertored albertored force-pushed the cowboy-user-attrs-on-span-start branch from cab4938 to 87668ed Compare November 19, 2022 21:48
@albertored
Copy link
Contributor Author

@tsloughter done. Not sure about the options type, I'm using a keyword at the moment (as I would have done in Elixir to have a better typespec), not sure how it is usually done in Erlang

@tsloughter
Copy link
Member

Keyword list v map is one of the more annoying interop issues we've run in to in OpenTelemetry -- other main one being nil v undefined. A keyword list is still not out of the ordinary in Erlang but maps have started to take their place.

I guess I'd say do what is done in Cowboy for options. Is it a map in 2.0 mostly?

@albertored
Copy link
Contributor Author

Yes, they are maps in cowboy, I'll change

@tsloughter
Copy link
Member

So talking with a user it came up the need to do this and they mentioned Javascript instrumentation libraries take a startSpanHook that can then call set_attributes.

Made me realize we should probably not limit this to attributes but instead take a fun like, start_span_callback or _fun that runs with the Span active so they can just call Traceer.set_attribute.

@tsloughter
Copy link
Member

Oops. @bryannaegele corrected me that for sampling the attributes need to be available at the call of start.

So maybe this is ready to merge?

@tsloughter
Copy link
Member

We'll need a follow up that allows for this: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-request-and-response-headers

This fun is more generic and takes the whole req so is fine that it doesn't follow the semconv which only applies to headers.

@tsloughter
Copy link
Member

Damn, tests fail.

@albertored
Copy link
Contributor Author

@tsloughter upgraded deps and a failing test, let's if it works now.

@albertored
Copy link
Contributor Author

Before merging we should choose a good name for the option, in principle it can be added also to other HTTP client/server instrumenters. In js for instance they call it requestHook and responseHook, I like it because we can use the same name and the same functionality also for every isntrumenter that has a request/response concept, not only HTTP.

@tsloughter
Copy link
Member

Yea, I think request/response_hook is good.

@albertored
Copy link
Contributor Author

@tsloughter ready

@albertored albertored requested a review from tsloughter July 15, 2023 13:04
@albertored
Copy link
Contributor Author

Is there something missing to this to be merged?

@bryannaegele
Copy link
Collaborator

Hey @albertored. I have to review it still and just got home from 2 weeks of holiday. I'll be working through my backlog over the next couple weeks

@albertored
Copy link
Contributor Author

@bryannaegele perfect thanks! I was just wondering if there was something missing from my side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants