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

contrib/segmentio/kafka-go: add implementation add tracing for kafka writer and kafka reader #1152

Merged
merged 26 commits into from Feb 28, 2022

Conversation

ajgajg1134
Copy link
Contributor

Fixes #899

This is a continuation of #897 with some of the comments addressed.

I attempted to pull out some of the duplication across the two, but since both pieces of code work with distinct kafka objects it led to a large layer of abstraction that seemed to be worse than the duplication included before. Namely: the startSpan methods would need to interact using interface{} and it grew quite unreadable it seemed. I'm happy to consider other ideas / approaches to de-duplicating some of this with the confluentinc kafka package.

@ajgajg1134 ajgajg1134 requested a review from a team as a code owner January 28, 2022 20:53
@ajgajg1134 ajgajg1134 requested a review from a team January 28, 2022 20:53
@ajgajg1134 ajgajg1134 added this to the 1.37.0 milestone Jan 28, 2022
@ajgajg1134 ajgajg1134 self-assigned this Jan 28, 2022
Copy link
Contributor

@knusbaum knusbaum left a comment

Choose a reason for hiding this comment

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

Looking good.

I have some comments.

.circleci/config.yml Outdated Show resolved Hide resolved
contrib/segmentio/kafka.go.v0/kafka.go Outdated Show resolved Hide resolved
return writer
}

// Writer wraps a kafka.Writer.
Copy link
Contributor

Choose a reason for hiding this comment

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

// Writer wraps a kafka.Writer.

Why? What does wrapping kafka.Writer accomplish? We should add a little more to this documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about something like?

Writer wraps a kafka.Writer with config data used for tracing

Copy link
Contributor

Choose a reason for hiding this comment

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

That works.

return wrapped
}

// A Reader wraps a kafka.Reader.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we should add just a bit more info for the documentation.

contrib/segmentio/kafka.go.v0/headers.go Outdated Show resolved Hide resolved
contrib/segmentio/kafka.go.v0/kafka.go Show resolved Hide resolved
Comment on lines 31 to 53
/*
to run the integration test locally, update the broker name to localhost:29092:

docker network create segementio

docker run --rm \
--name zookeeper \
--network segementio \
-p 2181:2181 \
wurstmeister/zookeeper:3.4.6

docker run --rm \
--name kafka \
--network segementio \
-p 29092:29092 \
-e KAFKA_CREATE_TOPICS=gotest:1:1 \
-e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \
-e KAFKA_LISTENERS=INSIDE://kafka:9092,OUTSIDE://kafka:29092 \
-e KAFKA_ADVERTISED_LISTENERS=INSIDE://kafka:9092,OUTSIDE://localhost:29092 \
-e KAFKA_LISTENER_SECURITY_PROTOCOL_MAP=INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT \
-e KAFKA_INTER_BROKER_LISTENER_NAME=INSIDE \
wurstmeister/kafka:2.13-2.7.0
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not able to get these instructions to work, and anyway we don't want users to have to edit the tests in order to run them locally.

Let's either fix these instructions to bring up a kafka such that tests pass without modification (should be possible since 9092 is not a protected port) or remove these instructions.

return nil
}

// Set sets a header.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not useful. We should point out that this implements the ddtrace.TextMapWriter interface.
Same for ForEachKey (only for the TextMapReader interface)

We do this with TextMapCarrier. See:

// Set implements TextMapWriter.
func (c TextMapCarrier) Set(key, val string) {
c[key] = val
}
// ForeachKey conforms to the TextMapReader interface.
func (c TextMapCarrier) ForeachKey(handler func(key, val string) error) error {
for k, v := range c {
if err := handler(k, v); err != nil {
return err
}
}
return nil
}

contrib/segmentio/kafka.go.v0/headers.go Outdated Show resolved Hide resolved
)

// A MessageCarrier injects and extracts traces from a kafka.Message.
type MessageCarrier struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this type need to be exported? I don't think users need to interact directly with this and an unexported type can still conform to an interface.

Let's keep this unexported if possible.

Copy link
Contributor

@knusbaum knusbaum left a comment

Choose a reason for hiding this comment

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

Looks good.

System tests look misconfigured. We can fix them elsewhere.

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.

proposal: add support for github.com/segmentio/kafka-go
2 participants