question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin integration with NRE fails to return values

See original GitHub issue

While extending Nile with plugins works well with CLI, one issue I’ve stumbled upon is returning values in the NRE. For simplicity, consider this plugin example:

# plugins/do_something.py

@click.command()
def do_something():
    click.echo("AHHHHHHHH")
    return 5

And let’s say we have this script:

# scripts/do_something.py

def run(nre):
    x = nre.do_something()
    print(x)

Running the script will print AHHHHHHHH but the expected return value 5 is returned as None; therefore, the logic is being executed, but the values are not being returned.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
franalgabacommented, May 2, 2022

Yes, definitely. It is possible to inject the parameter in the command call that happens underneath I think. It should be very straightforward. I will open a PR to handle this 😃

2reactions
franalgabacommented, May 2, 2022

Hi @andrew-fleming !

Glad to see you are using plugins. I reproduced the error you are having and diving into the NRE and how the plugins work there does not seem to be anything wrong.

Then, I looked at how click works internally for handling commands and… that’s where the issue is. If you check the click documentation about Command Return Values you will see something like this:

When a Click script is invoked as command line application (through BaseCommand.main()) the return value is ignored unless the standalone_mode is disabled in which case it’s bubbled through.

So, how to solve the issue? When you are using the plugin in a programmatic way with the NRE you have to pass the standalone_mode argument like this in order to retrieve the return value from the click command:

# scripts/do_something.py

def run(nre):
    x = nre.do_something(standalone_mode=False)
    print(x)

Just tried it and it works as expected. Hope it helps 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Integration plugin installed but no metrics come through and ...
I have configured NR on one of my environments. K8s metrics come through fine. Have configured elastic search and rabbitmq using the nri- ......
Read more >
maven-failsafe-plugin Errors and BUILD SUCCESS?
The Failsafe Plugin will not fail the build during the integration-test phase, thus enabling the post-integration-test phase to execute. I was able to...
Read more >
New Relic Infrastructure Database Integration - GitHub
For Kubernetes deployments, a Helm chart is provided to install a deployment and the supporting Kubernetes resources required to run nri-db in a...
Read more >
Unit and integration testing for Node.js apps - LogRocket Blog
This post teaches you how to perform unit and integration testing for ... function() { it('should return -1 when the value is not...
Read more >
nri-bundle 5.0.2 · helm/newrelic - Artifact Hub
This chart does not deploy anything by itself but has many charts as ... helm upgrade --reuse-values -f values.yaml [RELEASE] newrelic/nri-bundle.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found