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

Add Dataloader instrumentation library #137

Merged
merged 3 commits into from
Apr 5, 2023

Conversation

maartenvanvliet
Copy link
Contributor

What does this PR do?

The Dataloader package is a library often used in conjunction with the Absinthe GraphQL library to perform batch loading of data. This can be useful for efficiently querying databases using Ecto or other custom data sources. It is important to add instrumentation to Dataloader to be able to track and analyze the performance of data loads and identify potential issues such as slow data loads or N+1 queries.

I've looked at the conventions for naming the events but could not find any applicable but open to suggestions.

end

def handle_event(@run_stop, _measurements, metadata, config) do
parent_ctx = OpentelemetryProcessPropagator.fetch_parent_ctx(4, :"$callers")

Choose a reason for hiding this comment

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

I found this unexpected. Why is this and the attach needed when immediately following the current span is set from metadata and ended?

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 call. It was my first time working with OpentelemetryTelemetry and I was fiddling with it to get the right results. The current way showed me the correct spans in honeycomb but these should me moved to the @run_start event right and yield the same results right?

Copy link
Member

Choose a reason for hiding this comment

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

Right. In your fiddling were you starting a span that is active when Dataloader is called, as in, does the first dataloader span have a parent? I'd expect it not to in the current setup.

@olivermt
Copy link

Whats the status on this PR? Anything someone can assist with?

end

def handle_event(@run_stop, _measurements, metadata, config) do
OpentelemetryTelemetry.set_current_telemetry_span(config.tracer_id, metadata)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need to do this.

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 got that from here:

ctx = OpentelemetryTelemetry.set_current_telemetry_span(config.tracer_id, metadata)
but I'l remove it.

Should it also be removed in the @batch_stop handle_event?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

@tsloughter it's possible another span is open, especially with Phoenix due to when controller functions return, so it was a safeguard to ensure the Phoenix span was closed properly to not lose the trace. I don't know that this is as much of a concern in other libraries, so probably not needed, but also isn't harmful if someone used it.

The other use case would be if some process was creating many spans that are getting closed asynchronously and you therefore have more than one in progress. An example would be a genserver.

I can't speak to the dataloader library, but those are the cases when I'd employ that function.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, yea, I'm guessing I thought OpentelemetryTelemetry worked differently when I originally commented.

@tsloughter
Copy link
Member

@olivermt it is moving along. I just had another comment, it may be mergable soon.

@tsloughter tsloughter merged commit 1de26cc into open-telemetry:main Apr 5, 2023
@yordis yordis mentioned this pull request Dec 12, 2023
1 task
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.

6 participants