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

Fix RuntimeError: Working outside of request context. #734

Merged
merged 4 commits into from
Oct 14, 2021

Conversation

benjaminsky
Copy link
Contributor

Description

Check for flask.request to avoid RuntimeError: Working outside of request context. error.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Validated locally.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated

@benjaminsky benjaminsky requested a review from a team as a code owner October 12, 2021 23:55
@srikanthccv
Copy link
Member

When does this happen? I would expect it to be present.

@owais
Copy link
Contributor

owais commented Oct 13, 2021

Same question as @lonewolf3739. Is this happening because you are using the instrumentation outside a real request-response cycle (some mock/test env) or are we missing something here as instrumentation authors?

@benjaminsky
Copy link
Contributor Author

benjaminsky commented Oct 13, 2021 via email

@srikanthccv
Copy link
Member

OpenTelemetry flask instrumentation requires >= 1.0. Why are trying to instrument with both otel and new relic? I think you should dig in further and find the the actual issue.

@owais
Copy link
Contributor

owais commented Oct 13, 2021

  • OpenTelemetry supports flask 1.0 and newer as @lonewolf3739 pointed out.
  • We do not support double instrumenting with multiple agents. Behavior under such conditions is undefined at best.

That said, this change itself seems harmless even if unnecessary for supported versions of Flask. I'm inclined to accept this especially if we can specifically describe a situation where this fails.

@benjaminsky
Copy link
Contributor Author

benjaminsky commented Oct 13, 2021

After digging in, this is caused by the New Relic instrumentation in my case. That said, I'm getting an uncaught exception and given the desire for instrumentation never to throw errors, this feels like a pretty reasonable bulletproofing change. We do wish to retain both New Relic and otel when we go live. I know this isn't supported but with this change it works.

@owais
Copy link
Contributor

owais commented Oct 13, 2021

It sounds like another 3rd party library (NR) is changing a Flask in way that break it's public API or expected behavior. I'm inclined to not merge PRs like this in general but this specific patch seems harmless and I think I can live with it if it unblocks you. That said, I'd like to give @open-telemetry/python-approvers a chance to share their opinion on this as well.

@lzchen
Copy link
Contributor

lzchen commented Oct 14, 2021

@owais @benjaminsky @lonewolf3739

The change itself seems harmless enough so approving, but we don't want to set the precedence for the future to change instrumentations based off of undefined/unsupported behaviour. We can deal with this on a case by case basis however since it doesn't seem like it occurs that often.

@lzchen lzchen enabled auto-merge (squash) October 14, 2021 17:59
@lzchen lzchen merged commit 3f3de86 into open-telemetry:main Oct 14, 2021
nicholasgribanov pushed a commit to nicholasgribanov/opentelemetry-python-contrib that referenced this pull request Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants