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

chore(rq): integrated core api to rq integration #10607

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

Conversation

jessicagamio
Copy link
Contributor

@jessicagamio jessicagamio commented Sep 10, 2024

Implementing the Core API into the existing rq integration.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@jessicagamio jessicagamio added the changelog/no-changelog A changelog entry is not required for this PR. label Sep 10, 2024
@jessicagamio jessicagamio requested review from a team as code owners September 10, 2024 17:26
Copy link
Contributor

CODEOWNERS have been resolved as:

ddtrace/_trace/trace_handlers.py                                        @DataDog/apm-sdk-api-python
ddtrace/contrib/rq/__init__.py                                          @DataDog/apm-core-python @DataDog/apm-idm-python

@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Sep 10, 2024

Datadog Report

Branch report: jgamio_integrate_with_coreapi
Commit report: 50e34a6
Test service: dd-trace-py

✅ 0 Failed, 592 Passed, 694 Skipped, 39m 15.39s Total duration (34m 54.2s time saved)

@pr-commenter
Copy link

pr-commenter bot commented Sep 10, 2024

Benchmarks

Benchmark execution time: 2024-09-23 19:06:06

Comparing candidate commit 50e34a6 in PR branch jgamio_integrate_with_coreapi with baseline commit 7a2e802 in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 353 metrics, 47 unstable metrics.

Copy link
Collaborator

@emmettbutler emmettbutler left a comment

Choose a reason for hiding this comment

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

Aside from the one note I left, this looks great. Nice work so far. Please also add a brief description to the pull request.

ddtrace/contrib/rq/__init__.py Outdated Show resolved Hide resolved
ddtrace/contrib/rq/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mabdinur mabdinur left a comment

Choose a reason for hiding this comment

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

Let some nits but overall this looks really good. Great job!

ddtrace/_trace/trace_handlers.py Outdated Show resolved Hide resolved
ddtrace/_trace/trace_handlers.py Outdated Show resolved Hide resolved
ddtrace/_trace/trace_handlers.py Outdated Show resolved Hide resolved
ddtrace/contrib/rq/__init__.py Outdated Show resolved Hide resolved
ddtrace/contrib/rq/__init__.py Outdated Show resolved Hide resolved
ddtrace/contrib/rq/__init__.py Outdated Show resolved Hide resolved
ddtrace/_trace/trace_handlers.py Outdated Show resolved Hide resolved
Copy link
Contributor

@mabdinur mabdinur left a comment

Choose a reason for hiding this comment

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

Tests are passing: https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-py/-/jobs/642791801.

This change looks good to me. Thanks for sticking with it

Copy link
Collaborator

@emmettbutler emmettbutler left a comment

Choose a reason for hiding this comment

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

This looks great. Seems like you've got your head around how the Core API works. There are a few bits that should be changed, but the main body of this change is ready to go.

Comment on lines +695 to +696
config = ctx.get_item("integration_config")
distributed_tracing_enabled = config.distributed_tracing_enabled
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this code is written with the (acceptable) assumption that integration_config will always exist, making that assumption more explicit would clarify the code. Example:

Suggested change
config = ctx.get_item("integration_config")
distributed_tracing_enabled = config.distributed_tracing_enabled
distributed_tracing_enabled = ctx["integration_config"].distributed_tracing_enabled

This code throws a KeyError if that key isn't present, as opposed to the less-clear NoneType has no attribute... error that the current version would throw.

span.error = 1
if span_tags:
for k in span_tags.keys():
span.set_tag_str(k, span_tags[k])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code fails if span is None


def _on_end_of_traced_method_in_fork(ctx):
"""Force flush to agent since the process `os.exit()`s
immediately after this method returnsf
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
immediately after this method returnsf
immediately after this method returns

span.set_tag_str("job.id", job_id)
call_key="traced_queue_fetch_job",
tags={COMPONENT: config.rq.integration_name, JOB_ID: job_id},
) as ctx, ctx[ctx["call_key"]] as _:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) as ctx, ctx[ctx["call_key"]] as _:
) as ctx, ctx[ctx["call_key"]]:

This does the same thing

distributed_headers_config=config.rq_worker,
distributed_headers=job.meta,
tags={COMPONENT: config.rq.integration_name, SPAN_KIND: SpanKind.CONSUMER, JOB_ID: job.get_id()},
) as ctx, ctx[ctx["call_key"]] as _:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) as ctx, ctx[ctx["call_key"]] as _:
) as ctx, ctx[ctx["call_key"]]:

finally:
# Force flush to agent since the process `os.exit()`s
# immediately after this method returns
pin.tracer.flush()
core.context_with_data("rq.worker.after.perform.job")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why's this included? The dispatch on the next line seems like it does the job.

call_key="job.perform",
pin=pin,
tags={COMPONENT: config.rq.integration_name, JOB_ID: job.get_id()},
) as ctx, ctx[ctx["call_key"]] as _:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) as ctx, ctx[ctx["call_key"]] as _:
) as ctx, ctx[ctx["call_key"]]:

call_key="job.fetch_many",
pin=pin,
tags={COMPONENT: config.rq.integration_name, JOB_ID: job_ids},
) as ctx, ctx[ctx["call_key"]] as _:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
) as ctx, ctx[ctx["call_key"]] as _:
) as ctx, ctx[ctx["call_key"]]:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog A changelog entry is not required for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants