Skip to content

feat: setup code attributes in Elixir macros #808

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

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

Conversation

btkostner
Copy link
Contributor

This replaces #550. It adds code attributes to all Elixir macro calls. This information is gathered at compile time, and then merged with the start opt attributes at runtime. I created a new public function to format these attributes in case down the line we want to format them differently (like removing the "Elixir" prefix from namespace) and in case other libraries need them while not using the macros.

The end result is you get these attributes for the Elixir Tracer macros: code.filepath, code.function, code.lineno, code.namespace.

@doc false
@spec merge_start_opts(OpenTelemetry.Span.start_opts(), OpenTelemetry.attributes_map()) ::
OpenTelemetry.Span.start_opts()
def merge_start_opts(start_opts, builtin_attributes) do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this public but undocumented. Not sure if we want to document and make it part of the public API

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.

Project coverage is 18.45%. Comparing base (9f7affe) to head (543b8c0).

Files with missing lines Patch % Lines
...pps/opentelemetry_api/lib/open_telemetry/tracer.ex 60.00% 2 Missing ⚠️
...opentelemetry_api/lib/open_telemetry/attributes.ex 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #808      +/-   ##
==========================================
+ Coverage   17.32%   18.45%   +1.13%     
==========================================
  Files          24       25       +1     
  Lines         710      726      +16     
==========================================
+ Hits          123      134      +11     
- Misses        587      592       +5     
Flag Coverage Δ
api 18.45% <78.57%> (+1.13%) ⬆️
elixir 18.45% <78.57%> (+1.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsloughter
Copy link
Member

Sorry, I missed that there was a new PR. I'll get this reviewed soon.

@@ -0,0 +1,74 @@
defmodule OpenTelemetry.Attributes do
Copy link
Member

Choose a reason for hiding this comment

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

There is an otel_attributes module that something named OpenTelemetry.Attributes should be the Elixir equivalent of. While that isn't needed I think this should be named different anyway. Maybe CodeAttributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I can update that.

@tsloughter
Copy link
Member

I'm still torn on if this needs a configuration option. @bryannaegele thoughts?

I don't like the idea of having to check an option everytime a span is made, but not sure people wouldn't prefer to be able to turn this off for some reason. Nothing else adds attributes to your spans automatically right now, right?

I suppose we could make it optional later if anyone actually cares.

@btkostner
Copy link
Contributor Author

Let me see if I can pull some examples from other ecosystems and see what they do 👀

@tsloughter
Copy link
Member

@btkostner thanks!

@tsloughter
Copy link
Member

Oh and last I checked, I think months ago, no one else implemented these attributes at all :)

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.

2 participants