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 context param in interceptor #443

Open
godchen0212 opened this issue Jan 18, 2021 · 1 comment · May be fixed by #1157
Open

Add context param in interceptor #443

godchen0212 opened this issue Jan 18, 2021 · 1 comment · May be fixed by #1157

Comments

@godchen0212
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I want to add opentracing tracking for message delivery. Executing opentracing related code in the interceptor is an elegant way which won't cause a bad influence on my logic code. However, the interceptor has no context parameter, which makes it difficult to pass in the relevant context.

Describe the solution you'd like
I want to add context param in ProducerInterceptor's BeforeSend method.
BeforeSend(producer Producer, message *ProducerMessage)

BeforeSend(ctx context.Context, producer Producer, message *ProducerMessage)

@davendu
Copy link

davendu commented Nov 30, 2023

+1 for Golang client supporting context in conceptor. Besides tracing purpose, we internally use context to trace process of a message, and change properties based on some value. Currently we have to wrap the producer to modify Send & SendAsync. It can be better implemented if interceptor supports context.

#505 is closed since tracing is already supported in #518, but I think adding context is still necessary for Golang client. In other languages like Java and C++, execution context is implicitly shared (for example, using TLS variable). However, Golang requires explicit share of state, thus having context.Context type. For now, there is no way to share state (other than some hack) between caller and interceptor.

treuherz added a commit to arenko-group/pulsar-client-go that referenced this issue Dec 20, 2023
This change adds a context.Context argument to the ProducerInterceptor
interface, and passes it between the pre- and post-Send interceptor
methods. Having this makes it much easier to write useful
interceptors that can integrate with common tracing SDKs like
OpenTelemetry, as the context is the conventional method for propagating
metadata vertically through a call stack.

For an example of another library using a similar convention, see:
https://github.com/jackc/pgx/blob/9ab9e3c40bbb33c6f37359c87508cbc6a9830ed6/tracer.go#L10

Fixes apache#443
treuherz added a commit to arenko-group/pulsar-client-go that referenced this issue Jan 10, 2024
This change adds a context.Context argument to the ProducerInterceptor
interface, and passes it between the pre- and post-Send interceptor
methods. Having this makes it much easier to write useful
interceptors that can integrate with common tracing SDKs like
OpenTelemetry, as the context is the conventional method for propagating
metadata vertically through a call stack.

For an example of another library using a similar convention, see:
https://github.com/jackc/pgx/blob/9ab9e3c40bbb33c6f37359c87508cbc6a9830ed6/tracer.go#L10

Fixes apache#443
treuherz added a commit to arenko-group/pulsar-client-go that referenced this issue Jan 17, 2024
This change adds a context.Context argument to the ProducerInterceptor
interface, and passes it between the pre- and post-Send interceptor
methods. Having this makes it much easier to write useful
interceptors that can integrate with common tracing SDKs like
OpenTelemetry, as the context is the conventional method for propagating
metadata vertically through a call stack.

For an example of another library using a similar convention, see:
https://github.com/jackc/pgx/blob/9ab9e3c40bbb33c6f37359c87508cbc6a9830ed6/tracer.go#L10

Fixes apache#443
@treuherz treuherz linked a pull request Jan 17, 2024 that will close this issue
1 task
treuherz added a commit to arenko-group/pulsar-client-go that referenced this issue Jan 17, 2024
This change adds a context.Context argument to the ProducerInterceptor
interface, and passes it between the pre- and post-Send interceptor
methods. Having this makes it much easier to write useful
interceptors that can integrate with common tracing SDKs like
OpenTelemetry, as the context is the conventional method for propagating
metadata vertically through a call stack.

For an example of another library using a similar convention, see:
https://github.com/jackc/pgx/blob/9ab9e3c40bbb33c6f37359c87508cbc6a9830ed6/tracer.go#L10

Fixes apache#443
treuherz added a commit to arenko-group/pulsar-client-go that referenced this issue Feb 2, 2024
This change adds a context.Context argument to the ProducerInterceptor
interface, and passes it between the pre- and post-Send interceptor
methods. Having this makes it much easier to write useful
interceptors that can integrate with common tracing SDKs like
OpenTelemetry, as the context is the conventional method for propagating
metadata vertically through a call stack.

For an example of another library using a similar convention, see:
https://github.com/jackc/pgx/blob/9ab9e3c40bbb33c6f37359c87508cbc6a9830ed6/tracer.go#L10

Fixes apache#443
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 a pull request may close this issue.

2 participants