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

Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon #1000

Merged
merged 9 commits into from
Apr 15, 2022

Conversation

rjduffner
Copy link
Contributor

@rjduffner rjduffner commented Mar 15, 2022

Description

The largest change between falcon 1.x and 2.x was the changing the placement of some exception args. This PR adds some logic to place those args in the correct places for all versions of falcon.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Made sure tests pass
  • Forked and ran against falcon instance internally.

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@rjduffner rjduffner requested a review from a team as a code owner March 15, 2022 15:45
@rjduffner rjduffner changed the title [WIP] Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon Mar 16, 2022
@rjduffner
Copy link
Contributor Author

rjduffner commented Mar 16, 2022

In falcon 3, not setting remote_addr leads to an error where net.peer.ip is not set in the span.

Between falcon 2 and falcon 3, there was a slightly less than documented change (falconry/falcon#1573) where REMOTE_ADDR is not always set and is therefore not always readable.

Removing the optional remote_addr arg from the simulate_request call (to support falcon 1.4.1) then borked the behavior in falcon 3 (where it used to be totally optional in falcon 2)

https://github.com/falconry/falcon/blob/2.0.0/falcon/testing/helpers.py#L176
vs
https://github.com/falconry/falcon/blob/3.0.1/falcon/testing/helpers.py#L1168-L1172

Function that sets the net.peer.ip var

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/util/opentelemetry-util-http/src/opentelemetry/util/http/httplib.py#L70-L109

@rjduffner rjduffner changed the title Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon [WIP] Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon Mar 16, 2022
@rjduffner
Copy link
Contributor Author

rjduffner commented Mar 16, 2022

Given how this is handled in the wsgi instrumentation, I am going to update the tests to make the NET_PEER_IP optional.

remote_addr = environ.get("REMOTE_ADDR")
if remote_addr:
result[SpanAttributes.NET_PEER_IP] = remote_addr

@rjduffner rjduffner changed the title [WIP] Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon Add falcon version 1.4.1 support to opentelemetry-instrumentation-falcon Mar 16, 2022
@rjduffner
Copy link
Contributor Author

Tested locally and working for all three versions, ready for review and approval to run the test suite here.

SpanAttributes.NET_PEER_PORT: "65133",
SpanAttributes.HTTP_FLAVOR: "1.1",
"falcon.resource": "HelloWorldResource",
SpanAttributes.HTTP_STATUS_CODE: 201,
},
)
if SpanAttributes.NET_PEER_IP in span.attributes:
self.assertEqual(
span.attributes[SpanAttributes.NET_PEER_IP], "127.0.0.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, if remote_addr="127.0.0.1" was removed from the call to simulate_request then why should it appear here? Is this a default value? If so, it would be good to test also a non-default value.

Copy link
Contributor Author

@rjduffner rjduffner Mar 18, 2022

Choose a reason for hiding this comment

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

@ocelotl,

In falcon 1.4.1 (the new version added in this PR), the remote_addr param doesn't exist. This to me wasn't a huge deal as in the tests, it was being tested with the default value anyways, '127.0.0.1'. So I removed the remote_addr param from the tests.

However in falcon 3.x, there was an update to the code that was made which doesn't set the remote_addr if the default value is used. (See my comment above) or

https://github.com/falconry/falcon/blob/2.0.0/falcon/testing/helpers.py#L176
vs
https://github.com/falconry/falcon/blob/3.0.1/falcon/testing/helpers.py#L1168-L1172

This is different to how it was done in falcon 2.x where the remote_addr was always set, just with the default value.

The if statement in the test here was a compromise to show that there is something strange going on between the different versions.

If you have any thoughts on this, please let me know. I am open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that's fine, can you please add this explanation to the test as a comment? ✌️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. Thank you

@lzchen
Copy link
Contributor

lzchen commented Mar 21, 2022

@owais
PTAL

@rjduffner rjduffner force-pushed the falcon141 branch 2 times, most recently from ed0e0e1 to fd03868 Compare March 23, 2022 22:28
@rjduffner rjduffner force-pushed the falcon141 branch 5 times, most recently from 7e2d6c9 to 0f3111c Compare April 6, 2022 18:22
@rjduffner
Copy link
Contributor Author

@owais and @lzchen, got everything passing, let me know if there is anything else you would like updated.

@srikanthccv srikanthccv requested a review from ocelotl April 7, 2022 15:56
Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

Some comments, LGTM.

@rjduffner
Copy link
Contributor Author

@srikanthccv Not sure what to do here. Lint locally seems to be failing due to this commit, 40c1805

Specifically this

instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py:25:0: E0611: No name 'InMemoryMetricReader' in module 'opentelemetry.sdk._metrics.export' (no-name-in-module)```


And lint on the runner seems to have a different issue

``` TypeError: __init__() got an unexpected keyword argument 'styles'```

is there a re-run command for lint?

@srikanthccv
Copy link
Member

If it's not related to your changes please ignore. We will get that fixed in separate PR.

@rjduffner
Copy link
Contributor Author

Thanks @srikanthccv

Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

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

Blocking till we resolve the transitive dep comment

@srikanthccv
Copy link
Member

@rjduffner Please add packaging dependency and we are good to merge.

@rjduffner
Copy link
Contributor Author

@srikanthccv packaging dependency has been added to the setup.cfg.

@srikanthccv srikanthccv merged commit abdd25f into open-telemetry:main Apr 15, 2022
@rjduffner rjduffner deleted the falcon141 branch April 15, 2022 20:38
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