-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fixes and refactors trace v2 #288
Conversation
The trace v2 package was not working properly. It didn't support naming the system and the integration with another packages were broken, e.g., not being injected on the logs. I tried to solve all the issues without breaking too much compatibility but some breaking changes on trace v2 were made. The tracking middleware were coupling request and trace packages. I split the middleware into two (the old one still exists but now is deprecated), so request and trace has each one its own middleware. The request middleware should be used after the trace middleware so it can inject the request-id into the trace. The previous middleware supports both versions of trace so it can be used during the phasing out of v1. The span object in trace v2 was dropped in favor of the otel span directly. The otel span is already an interface and it is very powerful. If we would wrap this interface we would need to write too much code and still would lose some of its power. Because otel is a good market standard I felt confident in exposing it's span and use the trace v2 package only as an orquestrator. The example was also redone and it's now complete dockerized and using jaeger to collect and serve the traces. A new gokit endpoint middleware was created that starts a trace for the endpoint but also handle errors and allows for custom attributes to be inserted on the span.
request/http.go
Outdated
// HTTPMiddleware returns an http middleware that adds a request id | ||
// to the context of the request and the same id in the header of the | ||
// http response. If there is an active trace span, the request id is | ||
// also registred as an attribute 'request.id'. It's importante that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "importante" -> "important"
trace/v2/config.go
Outdated
} | ||
|
||
if err != nil { | ||
log.Fatal().Str("exporter", exporterName).Err(err).Msg("Failed to create trace exporter") | ||
return nil, fmt.Errorf("creating trace exporter: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: here it could use errors.Errorf
in order to avoid importing fmt
, as errors
is already imported
trace/v2/config.go
Outdated
func newResource(serviceName, serviceVersion string) (*resource.Resource, error) { | ||
return resource.Merge(resource.Default(), | ||
resource.NewWithAttributes(semconv.SchemaURL, | ||
semconv.ServiceName(serviceName), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are serviceName
and serviceVersion
required? If they are, does resource
return a good error message? If not, a custom error message would make it quick to someone who is using fkit without deep knowledge of this source code to know which configurations are missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving. I added some nit's and a question. I'm not deep into the tracev2 and opentelemetry, so I can't vouch for correctness. The commit message implied a deprecated middleware, so I think a deprecated
comment is missing.
The Dockerfile was dropped and the docker-compose was enhanced due to security issues raised by sonar. Custom configuration was dropped in favor of the official environment variables. README as converted into a proper godoc. Added some sanity checks for checking for missing environment variables when the default OpenTelemetry values are not ideal.
OTEL_TRACES_SAMPLER: "parentbased_traceidratio" | ||
OTEL_TRACES_SAMPLER_ARG: "0.5" | ||
|
||
# TraceV1 is only used for compatibility demontration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: demontration
-> demonstration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving. A typo pointed out
The cache was supposed to be committed commented out.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
The trace v2 package was not working properly. It didn't support naming the system and the integration with another packages were broken, e.g., not being injected on the logs.
I tried to solve all the issues without breaking too much compatibility but some breaking changes on trace v2 were made.
The tracking middleware were coupling request and trace packages. I split the middleware into two (the old one still exists but now is deprecated), so request and trace has each one its own middleware. The request middleware should be used after the trace middleware so it can inject the request-id into the trace.
The previous middleware supports both versions of trace so it can be used during the phasing out of v1.
The span object in trace v2 was dropped in favor of the otel span directly. The otel span is already an interface and it is very powerful. If we would wrap this interface we would need to write too much code and still would lose some of its power. Because otel is a good market standard I felt confident in exposing it's span and use the trace v2 package only as an orquestrator.
The example was also redone and it's now complete dockerized and using jaeger to collect and serve the traces.
A new gokit endpoint middleware was created that starts a trace for the endpoint but also handle errors and allows for custom attributes to be inserted on the span.