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

Optional Tracing Feature #207

Merged
merged 22 commits into from
Apr 22, 2021
Merged

Optional Tracing Feature #207

merged 22 commits into from
Apr 22, 2021

Conversation

joe94
Copy link
Member

@joe94 joe94 commented Apr 9, 2021

This PR introduces:

  • An option to disable tracing through OpenTelemetry's NoopTracerProvider. Note that when no configuration is provided, tracing is disabled.
  • Server-side tracing instrumentation on the gorilla/mux router. Note that traces would only be captured on matched routes.
  • Client-side tracing instrumentation.

@joe94 joe94 changed the title Feature/optional tracing Optional Tracing Feature Apr 13, 2021
@joe94 joe94 requested a review from johnabass April 13, 2021 23:10
main.go Outdated
Propagator: propagation.TraceContext{},
TracerProvider: trace.NewNoopTracerProvider(),
}
if v.IsSet(tracingConfigKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just Unmarshal the candlelight.Tracing key instead of checking first?

main.go Outdated
Dial: (&net.Dialer{
Timeout: t.dTimeout,
}).Dial},
r, err := time.ParseDuration(v.GetString(reqTimeoutKey))
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if properties like this were part of a struct. Why not just use a TimeoutConfig struct that's part of the candlelight config?

@joe94 joe94 marked this pull request as ready for review April 21, 2021 17:09
@joe94
Copy link
Member Author

joe94 commented Apr 21, 2021

@Sachin4403, just posting an update here that @johnabass is helping review this PR as well as xmidt-org/candlelight#25.

common/utils.go Outdated


transactionInfoLogger, transactionLoggerOk := ctx.Value(ContextKeyTransactionInfoLogger).(kitlog.Logger)
traceId, spanId, traceOk := candlelight.ExtractTraceInformation(r.Context())
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be less noisy if candlelight.ExtractTraceInformation actually did the appending. More like:

traceLogKVs := candlelight.AppendTraceInformation(r.Context(), nil)

Then, all the logic based around traceOk can just go inside the candlelight function.

This reduces all the extra code a client has to do. If a client needs to know if tracing was appended, then returning a []interface{}, bool can address that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should point out that the signature would be something like:

func AppendTraceInformation(ctx context.Context, kvs []interface{}) []interface{} /* maybe add a bool */ {
    kvs = append( /* stuff */ )
    return kvs
}


if !ok {
errorLogger.Log(logging.MessageKey(), "transaction logger not found in context", "tid", tid,candlelight.SpanIDLogKeyName, spanId,candlelight.TraceIdLogKeyName,traceId)
if !transactionLoggerOk {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a general theme, try to move this kind of conditional logic into the candlight package (see above)

Copy link
Contributor

@johnabass johnabass 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!

@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #207 (42eb9d9) into main (d66e18a) will decrease coverage by 0.89%.
The diff coverage is 27.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #207      +/-   ##
==========================================
- Coverage   76.92%   76.03%   -0.90%     
==========================================
  Files          11       11              
  Lines         390      388       -2     
==========================================
- Hits          300      295       -5     
- Misses         84       87       +3     
  Partials        6        6              
Impacted Files Coverage Δ
stat/service.go 84.61% <ø> (-1.10%) ⬇️
translation/service.go 80.00% <ø> (-0.96%) ⬇️
common/utils.go 55.55% <27.27%> (-4.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d66e18a...42eb9d9. Read the comment docs.

@sonarcloud
Copy link

sonarcloud bot commented Apr 22, 2021

@joe94 joe94 merged commit 8ab7921 into main Apr 22, 2021
@joe94 joe94 deleted the feature/optionalTracing branch April 22, 2021 19:55
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.

Make tracing optional OpenTelemetry Server Instrumentation OpenTelemetry Client Instrumentation
2 participants