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

airbyte-metrics/server: add tags to root span from OAuth handler #20468

Merged
merged 4 commits into from
Dec 15, 2022

Conversation

alafanechere
Copy link
Contributor

What

For better error tracking, I want to tag the root span with workspace id and definition id when OAuth handler public methods are called.

How

  • Create a ApmTraceUtils.addTagsToRootSpan function to add tags to the root span
  • Tag the root span from OAuthHandler

@octavia-squidington-iv octavia-squidington-iv added area/platform issues related to the platform area/server labels Dec 14, 2022
@alafanechere alafanechere marked this pull request as ready for review December 14, 2022 08:01
@alafanechere alafanechere requested review from jdpgrailsdev and a team December 14, 2022 08:01
@alafanechere
Copy link
Contributor Author

I confirm that this changed propagates tags to the root span:
Screen Shot 2022-12-14 at 10 14 38

@alafanechere alafanechere changed the title airbyte-metrics/server: add tags root span from OAuth handler airbyte-metrics/server: add tags to root span from OAuth handler Dec 14, 2022
Copy link
Contributor

@jdpgrailsdev jdpgrailsdev left a comment

Choose a reason for hiding this comment

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

:shipit: @alafanechere Would you mind adding tests for this new method (and the one that adds an error to the root span) to the ApmTraceUtilsTest class?

*/
public static void addTagsToRootSpan(final Map<String, Object> tags) {
final Span activeSpan = GlobalTracer.get().activeSpan();
if (activeSpan instanceof MutableSpan) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[question] If the framework is wrapping all requests in a span, how would we not have a span? Perhaps if Data dog is disabled?

Copy link
Contributor

Choose a reason for hiding this comment

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

@evantahler Good catch. This method should check if activeSpan is not null. It will be null when the DataDog Java agent is not present. cc: @alafanechere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Isn't if activeSpan instanceof MutableSpan already checking a not null by itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@evantahler MutableSpan is a datadog interface. And Span and GlobalTracer.get().activeSpan() are from opentelemetry. So when datadog is disabled we might not received Span object implementing the MutableSpan interface, hence the importance of this check. Am I right @jdpgrailsdev ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@alafanechere Correct on both accounts. The instanceof check does protect us from null, as it will resolve to false. MutableSpan is a DataDog only class, so if a customer uses a different APM product that supports OpenTracing, that check protects us from calling methods that don't exist on the object.

final Map<String, Object> traceTags = Map.of(WORKSPACE_ID_KEY, sourceOauthConsentRequest.getWorkspaceId(), SOURCE_DEFINITION_ID_KEY,
sourceOauthConsentRequest.getSourceDefinitionId());
ApmTraceUtils.addTagsToTrace(traceTags);
ApmTraceUtils.addTagsToRootSpan(traceTags);
Copy link
Contributor

Choose a reason for hiding this comment

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

[non-blocking nit] when I've done instrumentation like this in the past, the strategy was to append as much information to the trace / root-span at the top level before getting into any individual controller. This looks like a global rootSpanHelper which intercepts /every/ request (e.g. "request middleware") and:

  • if there's a user, addd the user_id
  • if there's a workspace, add the workspace_id
  • if there are any LaunchDarkly feature flags, add them to the span

Then, in the controller itself, you only have to add new information (the source_id in this case).

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 like this idea of helper/request middleware. This abstraction could also help us switch tracking backend (sentry/datadog) with a single interface. @evantahler could it fit a bigger project we'd have in Q1?

@alafanechere alafanechere temporarily deployed to more-secrets December 15, 2022 09:18 — with GitHub Actions Inactive
@alafanechere alafanechere temporarily deployed to more-secrets December 15, 2022 09:18 — with GitHub Actions Inactive
@alafanechere
Copy link
Contributor Author

:shipit: @alafanechere Would you mind adding tests for this new method (and the one that adds an error to the root span) to the ApmTraceUtilsTest class?

Test added 👌

@alafanechere alafanechere temporarily deployed to more-secrets December 15, 2022 09:41 — with GitHub Actions Inactive
@alafanechere alafanechere temporarily deployed to more-secrets December 15, 2022 09:42 — with GitHub Actions Inactive
@alafanechere alafanechere merged commit 71d71a4 into master Dec 15, 2022
@alafanechere alafanechere deleted the augustin/airbyte-metrics/tag-root-span branch December 15, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/platform issues related to the platform area/server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants