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

Adds a Producer Interceptor example #1775

Merged
merged 2 commits into from Aug 12, 2020
Merged

Conversation

d1egoaz
Copy link
Contributor

@d1egoaz d1egoaz commented Aug 11, 2020

add some examples for the usage of the new interceptors feature added in #1730

@d1egoaz d1egoaz requested a review from bai as a code owner August 11, 2020 19:11
@d1egoaz d1egoaz requested a review from dnwe August 11, 2020 19:11
a consumer interceptor should be similar
Copy link
Contributor

@varun06 varun06 left a comment

Choose a reason for hiding this comment

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

one nit about documentation. Look great.
Do we need to push binary as part of these examples?

examples/README.md Show resolved Hide resolved
and also adds a linkg to OpenTelemetry Go
@d1egoaz
Copy link
Contributor Author

d1egoaz commented Aug 12, 2020

@varun06 I don't think we need to push binaries none of the examples are doing that 🤷
binaries can also be easily crated as a go.mod is provided

@d1egoaz d1egoaz merged commit 9e4e58d into master Aug 12, 2020
@d1egoaz d1egoaz deleted the diego_interceptor-example branch August 12, 2020 17:36
@danielhookx
Copy link

The situation I met is that I want to put the parent span in the context, then the Kafka Producer interceptor to create the child span from this context. But It seems not supported by getting the context from the OnSend method.

The code looks like:

func Caller() {
        ...
        span := tracer.StartSpan(info.FullMethod)
	defer span.Finish()
	ctx = opentracing.ContextWithSpan(ctx, span)
        ....
        Publish(ctx)
        ....
}

func Publish(ctx context.Context) {
      var kafkaPub sarama.SyncProducer
       ...
       m := &sarama.ProducerMessage{
		Key:   sarama.StringEncoder(fromId),
		Topic: appTopic,
		Value: sarama.ByteEncoder(b),
	}
	_, _, _ = kafkaPub.SendMessage(ctx, m)
}

type ProducerInterceptor struct {
}

func (oi *ProducerInterceptor) OnSend(ctx context.Context, msg *sarama.ProducerMessage) {
	span, ctx := opentracing.StartSpanFromContext(ctx, method)
	defer span.Finish()
        ...
}

So please add some more information about it or is there any place I could find the right example to solve it?

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

3 participants