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

Instrumentation: Improve automatic instrumentation by the SDK to include handler/request logs, metrics and traces #1028

Merged
merged 9 commits into from
Jul 12, 2024

Conversation

marefr
Copy link
Member

@marefr marefr commented Jul 10, 2024

Makes the adapters share some common functionality (middlewares).

  • Adds request/handler logs, traces and metrics.
  • Adds basic support for capturing error source (status source in grafana) given QueryDataResponse to make it in pair with how Grafana works. In theory backend.DownstreamError(...) or backend.WithDownstreamErrorSource(...) could be returned/used from CheckHealthandCallResource`, but should be considered experimental.
  • Copies RequestStatus from grafana into backend package for convenience (could be used by Grafana later)

Note 1) There's #1019 which I had in mind for this. However, I think we can pick that up later and rather focusing on getting this logic in place.

Reminder: https://grafana.com/developers/plugin-tools/how-to-guides/data-source-plugins/add-logs-metrics-traces-for-backend-plugins should be updated later in regards to automatic instrumentation by the SDK.

@marefr marefr self-assigned this Jul 10, 2024
@marefr marefr requested a review from a team as a code owner July 10, 2024 13:16
@marefr marefr requested review from wbrowne, andresmgot, oshirohugo and xnyo and removed request for a team July 10, 2024 13:16
@marefr marefr changed the title Improve o11y Instrumentation: Improve automatic instrumentation by the SDK to include handler/request logs, metrics and traces Jul 10, 2024
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

I don't see anything outstanding here, LGTM

}

// TODO status source
// logParams = append(logParams, "statusSource", pluginrequestmeta.StatusSourceFromContext(ctx))
Copy link
Contributor

Choose a reason for hiding this comment

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

do you want to keep this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Related to description

Note 2) logs, metrics and traces currently lacks error source (status source in grafana) denoting whether an error originates from the plugin itself or from downstream service. There's some additional work needed to support this for all endpoints and would need some additional thinking to simplify for plugin authors.

I guess can target that in a follow up though. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I just wanted to make sure you want to keep this commented code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added support for error source (status source) to make it in pair with how it works in Grafana, however if a plugin returns a backend.DownstreamError(...) from CheckHealth or CallResource it will be recorded as a downstream error source. This should be enough for now and support the very most basic stuff.

Realized that having the ErrorSource in the backend package is not optimal. Tried to move the context support for error source to experimental/errorsource, but that creates a circular dependency 😢 So the current state of error status seems a bit broken to be used both internally in the SDK and in plugins. We can hopefully revisit in the future and introduce some breaking changes and clear up the problems.

@marefr marefr requested a review from ivanahuckova July 11, 2024 17:58
Copy link
Member

@ivanahuckova ivanahuckova left a comment

Choose a reason for hiding this comment

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

Thank you for working on this! Did a quick review and LGTM.

@marefr
Copy link
Member Author

marefr commented Jul 12, 2024

Opened https://github.com/grafana/test-datasource/pull/39 seems to work as expected. Only the duration in logs seems off

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

Successfully merging this pull request may close these issues.

3 participants