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

bugfix(opentelemetry-instrumentation-grpc): Add code() and details() to ServicerContext #1578

Merged
merged 5 commits into from
Jan 20, 2023

Conversation

CoLa5
Copy link
Contributor

@CoLa5 CoLa5 commented Jan 13, 2023

Description

_OpenTelemetryServicerContext aims to implement the abstract interface of grpc.ServicerContext.
grpc.ServicerContext supports since grpcio v1.38.0 (s. here) a code() and details()-method to retrieve the currently set code/details in the servicer method.
In contrast, _OpenTelemetryServicerContext implements code and details as public attributes, which are not callable.
Consequently, calling code() and details() in a servicer method will fail, when using OpenTelemetry, e.g.:

class Greeter(helloworld_pb2_grpc.GreeterServicer):

    def SayHello(self, request, context):
        print("code before: %r" % context.code())  # ERROR
        context.set_code(grpc.StatusCode.OK)
        print("code after: %r" % context.code())  # ERROR

        print("details before: %r" % context.details())  # ERROR
        context.set_details("test")
        print("details after: %r" % context.details())  # ERROR

        return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)

will raise an error.

Obviously, the abc-module of python allows this bug, since the @abstractmethods code() and details() of grpc.ServicerContext have been overwritten by _OpenTelemetryServicerContext, although the abstract interface has not been implemented correctly.

Fixes (#855)

Please delete options that are not relevant.

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

How Has This Been Tested?

Not tested.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • 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

@CoLa5 CoLa5 requested a review from a team January 13, 2023 13:07
@srikanthccv
Copy link
Member

Was there ever a publicly accessible code and details attributes?

@CoLa5
Copy link
Contributor Author

CoLa5 commented Jan 14, 2023

As said in the PR, grpc.ServicerContext supports since grpcio v1.38.0 (s. here) a code() and details()-method to retrieve the currently-set code/details in the servicer method. Before, both methods did not exist in the public interface.

And starting from the first non-beta version v0.15 of grpc in python, the internal implementation of the grpc.ServicerContext uses an internal/private _RpcState-object to manage the set code/details.

Consequently, code- or details-attributes have never been publicly accessible.

@srikanthccv srikanthccv changed the title Bugfix of (#855) bugfix(opentelemetry-instrumentation-grpc): Add code() and details() to ServicerContext Jan 18, 2023
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.

2 participants